From 0b1224b034a71dfaed6e4edd6396ce0d5870ad23 Mon Sep 17 00:00:00 2001 From: Chris Kipp Date: Sat, 6 Nov 2021 12:01:26 +0100 Subject: [PATCH 1/2] Initial work for scoverage 2.0 --- build.sc | 4 +-- .../api/src/ScoverageReportWorkerApi.scala | 7 ++++- contrib/scoverage/src/ScoverageModule.scala | 31 ++++++++++++++----- contrib/scoverage/src/ScoverageReport.scala | 2 +- .../src/ScoverageReportWorkerImpl.scala | 11 ++++--- 5 files changed, 38 insertions(+), 17 deletions(-) diff --git a/build.sc b/build.sc index 84c45b879e1..dd95f67cdec 100755 --- a/build.sc +++ b/build.sc @@ -107,7 +107,7 @@ object Deps { val scalafmtDynamic = ivy"org.scalameta::scalafmt-dynamic:3.0.6" val scalametaTrees = ivy"org.scalameta::trees:4.4.29" def scalaReflect(scalaVersion: String) = ivy"org.scala-lang:scala-reflect:${scalaVersion}" - def scalacScoveragePlugin = ivy"org.scoverage:::scalac-scoverage-plugin:1.4.9" + def scalacScoverageReporter = ivy"org.scoverage::scalac-scoverage-reporter:2.0.0-M2" val sourcecode = ivy"com.lihaoyi::sourcecode:0.2.7" val upickle = ivy"com.lihaoyi::upickle:1.4.2" val utest = ivy"com.lihaoyi::utest:0.7.10" @@ -573,7 +573,7 @@ object contrib extends MillModule { override def compileIvyDeps = T{ Agg( // compile-time only, need to provide the correct scoverage version runtime - Deps.scalacScoveragePlugin, + Deps.scalacScoverageReporter, // provided by mill runtime Deps.osLib ) diff --git a/contrib/scoverage/api/src/ScoverageReportWorkerApi.scala b/contrib/scoverage/api/src/ScoverageReportWorkerApi.scala index 338ba907804..4319bd282b2 100644 --- a/contrib/scoverage/api/src/ScoverageReportWorkerApi.scala +++ b/contrib/scoverage/api/src/ScoverageReportWorkerApi.scala @@ -5,7 +5,12 @@ import mill.api.Ctx trait ScoverageReportWorkerApi { import ScoverageReportWorkerApi._ - def report(reportType: ReportType, sources: Seq[os.Path], dataDirs: Seq[os.Path])(implicit + def report( + reportType: ReportType, + sources: Seq[os.Path], + dataDirs: Seq[os.Path], + sourceRoot: os.Path + )(implicit ctx: Ctx ): Unit } diff --git a/contrib/scoverage/src/ScoverageModule.scala b/contrib/scoverage/src/ScoverageModule.scala index 3a126cab1ba..3af32ca65b8 100644 --- a/contrib/scoverage/src/ScoverageModule.scala +++ b/contrib/scoverage/src/ScoverageModule.scala @@ -59,8 +59,12 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule => def scoverageRuntimeDep: T[Dep] = T { ivy"org.scoverage::scalac-scoverage-runtime:${outer.scoverageVersion()}" } - def scoveragePluginDep: T[Dep] = T { - ivy"org.scoverage:::scalac-scoverage-plugin:${outer.scoverageVersion()}" + def scoveragePluginDep: T[Agg[Dep]] = T { + Agg( + ivy"org.scoverage:::scalac-scoverage-plugin:${outer.scoverageVersion()}", + ivy"org.scoverage::scalac-scoverage-domain:${outer.scoverageVersion()}", + ivy"org.scoverage::scalac-scoverage-serializer:${outer.scoverageVersion()}" + ) } @deprecated("Use scoverageToolsClasspath instead.", "mill after 0.10.0-M1") @@ -72,13 +76,15 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule => scoverageReportWorkerClasspath() ++ resolveDeps(T.task { Agg( - ivy"org.scoverage:scalac-scoverage-plugin_${mill.BuildInfo.scalaVersion}:${outer.scoverageVersion()}" + ivy"org.scoverage::scalac-scoverage-domain:${outer.scoverageVersion()}", + ivy"org.scoverage::scalac-scoverage-serializer:${outer.scoverageVersion()}", + ivy"org.scoverage::scalac-scoverage-reporter:${outer.scoverageVersion()}" ) })() } def scoverageClasspath: T[Agg[PathRef]] = T { - resolveDeps(T.task { Agg(scoveragePluginDep()) })() + resolveDeps(T.task { scoveragePluginDep() })() } def scoverageReportWorkerClasspath: T[Agg[PathRef]] = T { @@ -98,7 +104,7 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule => ScoverageReportWorker .scoverageReportWorker() .bridge(scoverageToolsClasspath().map(_.path)) - .report(reportType, allSources().map(_.path), Seq(data().path)) + .report(reportType, allSources().map(_.path), Seq(data().path), T.workspace) } /** @@ -126,11 +132,20 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule => /** Add the scoverage scalac plugin. */ override def scalacPluginIvyDeps: Target[Loose.Agg[Dep]] = - T { outer.scalacPluginIvyDeps() ++ Agg(outer.scoveragePluginDep()) } + T { outer.scalacPluginIvyDeps() ++ outer.scoveragePluginDep() } - /** Add the scoverage specific plugin settings (`dataDir`). */ + /** + * Add the scoverage specific plugin settings + * - `dataDir` - where the coverage data files should go + * - `sourceRoot` - used for path relativization. + */ override def scalacOptions: Target[Seq[String]] = - T { outer.scalacOptions() ++ Seq(s"-P:scoverage:dataDir:${data().path.toIO.getPath()}") } + T { + outer.scalacOptions() ++ Seq( + s"-P:scoverage:dataDir:${data().path.toIO.getPath()}", + s"-P:scoverage:sourceRoot:${T.workspace}" + ) + } def htmlReport(): Command[Unit] = T.command { doReport(ReportType.Html) } def xmlReport(): Command[Unit] = T.command { doReport(ReportType.Xml) } diff --git a/contrib/scoverage/src/ScoverageReport.scala b/contrib/scoverage/src/ScoverageReport.scala index c852c915368..18e521bdc25 100644 --- a/contrib/scoverage/src/ScoverageReport.scala +++ b/contrib/scoverage/src/ScoverageReport.scala @@ -106,7 +106,7 @@ trait ScoverageReport extends Module { scoverageReportWorkerModule .scoverageReportWorker() .bridge(workerModule.scoverageToolsClasspath().map(_.path)) - .report(reportType, sourcePaths, dataPaths) + .report(reportType, sourcePaths, dataPaths, T.workspace) PathRef(T.dest) } } diff --git a/contrib/scoverage/worker/src/ScoverageReportWorkerImpl.scala b/contrib/scoverage/worker/src/ScoverageReportWorkerImpl.scala index ac948ec9969..54d7bd088aa 100644 --- a/contrib/scoverage/worker/src/ScoverageReportWorkerImpl.scala +++ b/contrib/scoverage/worker/src/ScoverageReportWorkerImpl.scala @@ -1,7 +1,7 @@ package mill.contrib.scoverage.worker import mill.contrib.scoverage.api.ScoverageReportWorkerApi -import _root_.scoverage.report.{CoverageAggregator, ScoverageHtmlWriter, ScoverageXmlWriter} +import _root_.scoverage.reporter.{CoverageAggregator, ScoverageHtmlWriter, ScoverageXmlWriter} import mill.api.Ctx import mill.contrib.scoverage.api.ScoverageReportWorkerApi.ReportType @@ -10,11 +10,12 @@ class ScoverageReportWorkerImpl extends ScoverageReportWorkerApi { override def report( reportType: ReportType, sources: Seq[os.Path], - dataDirs: Seq[os.Path] + dataDirs: Seq[os.Path], + sourceRoot: os.Path )(implicit ctx: Ctx): Unit = try { ctx.log.info(s"Processing coverage data for ${dataDirs.size} data locations") - CoverageAggregator.aggregate(dataDirs.map(_.toIO)) match { + CoverageAggregator.aggregate(dataDirs.map(_.toIO), sourceRoot.toIO) match { case Some(coverage) => val sourceFolders = sources.map(_.toIO) val folder = ctx.dest @@ -24,7 +25,7 @@ class ScoverageReportWorkerImpl extends ScoverageReportWorkerApi { new ScoverageHtmlWriter(sourceFolders, folder.toIO, None) .write(coverage) case ReportType.Xml => - new ScoverageXmlWriter(sourceFolders, folder.toIO, false) + new ScoverageXmlWriter(sourceFolders, folder.toIO, false, None) .write(coverage) case ReportType.Console => ctx.log.info(s"Statement coverage.: ${coverage.statementCoverageFormatted}%") @@ -34,7 +35,7 @@ class ScoverageReportWorkerImpl extends ScoverageReportWorkerApi { ctx.log.error(s"No coverage data found in [${dataDirs.mkString(", ")}]") } } catch { - case e => + case e: Throwable => ctx.log.error(s"Exception while building coverage report. ${e.getMessage()}") e.printStackTrace() throw e From 2573eb6695801b9d0b0031fec0238e99252198b5 Mon Sep 17 00:00:00 2001 From: Chris Kipp Date: Sat, 6 Nov 2021 12:49:48 +0100 Subject: [PATCH 2/2] Update tests to use milestone --- .../scoverage/test/src/HelloWorldTests.scala | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/contrib/scoverage/test/src/HelloWorldTests.scala b/contrib/scoverage/test/src/HelloWorldTests.scala index e200f523b57..0c7e288bcdf 100644 --- a/contrib/scoverage/test/src/HelloWorldTests.scala +++ b/contrib/scoverage/test/src/HelloWorldTests.scala @@ -106,7 +106,11 @@ trait HelloWorldTests extends utest.TestSuite { eval.apply(HelloWorld.core.scoverage.scalacPluginIvyDeps) assert( - result == Agg(ivy"org.scoverage:::scalac-scoverage-plugin:${testScoverageVersion}"), + result == Agg( + ivy"org.scoverage:::scalac-scoverage-plugin:${testScoverageVersion}", + ivy"org.scoverage::scalac-scoverage-domain:${testScoverageVersion}", + ivy"org.scoverage::scalac-scoverage-serializer:${testScoverageVersion}" + ), evalCount > 0 ) } @@ -190,21 +194,14 @@ trait HelloWorldTests extends utest.TestSuite { object HelloWorldTests_2_12 extends HelloWorldTests { override def threadCount = Some(1) - override def testScalaVersion: String = "2.12.14" - override def testScoverageVersion = "1.4.9" + override def testScalaVersion: String = "2.12.15" + override def testScoverageVersion = "2.0.0-M4" override def testScalatestVersion = "3.0.8" } object HelloWorldTests_2_13 extends HelloWorldTests { override def threadCount = Some(1) - override def testScalaVersion: String = "2.13.6" - override def testScoverageVersion = "1.4.9" + override def testScalaVersion: String = "2.13.7" + override def testScoverageVersion = "2.0.0-M4" override def testScalatestVersion = "3.0.8" } - -//object HelloWorldParTests_2_13 extends HelloWorldTests { -// override def threadCount: Some[Int] = Some(4) -// override def testScalaVersion: String = "2.13.6" -// override def testScoverageVersion = "1.4.8" -// override def testScalatestVersion = "3.0.8" -//}