Skip to content

Commit

Permalink
Remove support for Scoverage 1.x (#3597)
Browse files Browse the repository at this point in the history
Scoverage 1.x is unmaintained and it does not support any actual Scala
version except Scala 2.11. It also block proper compilation with Java
21.

Users still dependent on Scoverage 1.x should either stay on Mill 0.11.x
or fork the Scoverage 1.x plugin as a standalone project.

Fix #3588

Pull request: #3597
  • Loading branch information
lefou authored Sep 24, 2024
1 parent 89bce51 commit 64ee6f6
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 157 deletions.
8 changes: 2 additions & 6 deletions build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ object Deps {
// When updating, run "Publish Bridges" Github Actions for the new version
// and then add to it `bridgeScalaVersions`
val scalaVersion = "2.13.14"
// Scoverage 1.x will not get releases for newer Scala versions
val scalaVersionForScoverageWorker1 = "2.13.8"
// The Scala 2.12.x version to use for some workers
val workerScalaVersion212 = "2.12.19"

Expand Down Expand Up @@ -163,13 +161,11 @@ object Deps {
val scalafmtDynamic = ivy"org.scalameta::scalafmt-dynamic:3.8.3"
def scalap(scalaVersion: String) = ivy"org.scala-lang:scalap:${scalaVersion}"
def scalaReflect(scalaVersion: String) = ivy"org.scala-lang:scala-reflect:${scalaVersion}"
val scalacScoveragePlugin = ivy"org.scoverage:::scalac-scoverage-plugin:1.4.11"
val scoverage2Version = "2.1.1"
val scalacScoverage2Plugin = ivy"org.scoverage:::scalac-scoverage-plugin:${scoverage2Version}"
val scalacScoverage2Reporter = ivy"org.scoverage::scalac-scoverage-reporter:${scoverage2Version}"
val scalacScoverage2Domain = ivy"org.scoverage::scalac-scoverage-domain:${scoverage2Version}"
val scalacScoverage2Serializer =
ivy"org.scoverage::scalac-scoverage-serializer:${scoverage2Version}"
val scalacScoverage2Serializer = ivy"org.scoverage::scalac-scoverage-serializer:${scoverage2Version}"
val scalaparse = ivy"com.lihaoyi::scalaparse:${fastparse.version}"
val scalatags = ivy"com.lihaoyi::scalatags:0.12.0"
def scalaXml = ivy"org.scala-lang.modules::scala-xml:2.3.0"
Expand Down Expand Up @@ -243,7 +239,7 @@ def millBinPlatform: T[String] = T {
def baseDir = build.millSourcePath

val essentialBridgeScalaVersions =
Seq(Deps.scalaVersion, Deps.scalaVersionForScoverageWorker1, Deps.workerScalaVersion212)
Seq(Deps.scalaVersion, Deps.workerScalaVersion212)
// published compiler bridges
val bridgeScalaVersions = Seq(
// Our version of Zinc doesn't work with Scala 2.12.0 and 2.12.4 compiler
Expand Down
18 changes: 1 addition & 17 deletions contrib/package.mill
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,12 @@ object `package` extends RootModule {
def compileModuleDeps = Seq(build.scalalib)

def testTransitiveDeps =
super.testTransitiveDeps() ++ Seq(worker.testDep(), worker2.testDep())
super.testTransitiveDeps() ++ Seq(worker2.testDep())

def testArgs = T {
super.testArgs() ++
Seq(
s"-DMILL_SCOVERAGE_VERSION=${build.Deps.scalacScoveragePlugin.dep.version}",
s"-DMILL_SCOVERAGE2_VERSION=${build.Deps.scalacScoverage2Plugin.dep.version}",
s"-DTEST_SCALA_2_13_VERSION_FOR_SCOVERAGE_1=${build.Deps.scalaVersionForScoverageWorker1}",
s"-DTEST_SCALA_2_12_VERSION=2.12.15" // last supported 2.12 version for Scoverage 1.x
)
}

Expand All @@ -127,19 +124,6 @@ object `package` extends RootModule {
super.testModuleDeps ++
Seq(build.scalalib, build.scalajslib, build.scalanativelib, build.contrib.buildinfo)

// Worker for Scoverage 1.x
object worker extends build.MillPublishScalaModule {
// scoverage is on an old Scala version which doesnt support scalafix
def fix(args: String*): Command[Unit] = T.command {}
def compileModuleDeps = Seq(build.main.api)
def moduleDeps = Seq(scoverage.api)
def testDepPaths = T { Seq(compile().classes) }

// compile-time only, need to provide the correct scoverage version at runtime
def compileIvyDeps = Agg(build.Deps.scalacScoveragePlugin)
def scalaVersion = build.Deps.scalaVersionForScoverageWorker1
}

// Worker for Scoverage 2.0
object worker2 extends build.MillPublishScalaModule {
def compileModuleDeps = Seq(build.main.api)
Expand Down
6 changes: 3 additions & 3 deletions contrib/scoverage/readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import $ivy.`com.lihaoyi::mill-contrib-scoverage:`
import mill.contrib.scoverage.ScoverageModule
object foo extends ScoverageModule {
def scalaVersion = "2.12.9"
def scoverageVersion = "1.4.0"
def scalaVersion = "2.13.15"
def scoverageVersion = "2.1.1"
object test extends ScoverageTests with TestModule.ScalaTest {
def ivyDeps = Agg(ivy"org.scalatest::scalatest:3.0.8")
def ivyDeps = Agg(ivy"org.scalatest::scalatest:3.2.19")
}
}
----
Expand Down
82 changes: 25 additions & 57 deletions contrib/scoverage/src/mill/contrib/scoverage/ScoverageModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import mill.scalalib.api.ZincWorkerUtil
import mill.scalalib.{Dep, DepSyntax, JavaModule, ScalaModule}
import mill.util.Util.millProjectModule

import scala.util.Try

/**
* Adds targets to a [[mill.scalalib.ScalaModule]] to create test coverage reports.
*
Expand All @@ -29,11 +27,11 @@ import scala.util.Try
* import mill.contrib.scoverage.ScoverageModule
*
* Object foo extends ScoverageModule {
* def scalaVersion = "2.12.9"
* def scoverageVersion = "1.4.0"
* def scalaVersion = "2.13.15"
* def scoverageVersion = "2.1.1"
*
* object test extends ScoverageTests {
* def ivyDeps = Agg(ivy"org.scalatest::scalatest:3.0.5")
* def ivyDeps = Agg(ivy"org.scalatest::scalatest:3.2.19")
* def testFrameworks = Seq("org.scalatest.tools.Framework")
* }
* }
Expand All @@ -60,8 +58,6 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule =>
*/
def scoverageVersion: T[String]

private def isScoverage2: Task[Boolean] = Task.Anon { scoverageVersion().startsWith("2.") }

private def isScala3: Task[Boolean] = Task.Anon { ZincWorkerUtil.isScala3(outer.scalaVersion()) }

def scoverageRuntimeDeps: T[Agg[Dep]] = Task {
Expand All @@ -77,31 +73,23 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule =>
if (isScala3()) {
Agg.empty
} else {
if (isScoverage2()) {
Agg(
ivy"org.scoverage:::scalac-scoverage-plugin:${sv}",
ivy"org.scoverage::scalac-scoverage-domain:${sv}",
ivy"org.scoverage::scalac-scoverage-serializer:${sv}",
ivy"org.scoverage::scalac-scoverage-reporter:${sv}"
)
} else {
Agg(ivy"org.scoverage:::scalac-scoverage-plugin:${sv}")
}
Agg(
ivy"org.scoverage:::scalac-scoverage-plugin:${sv}",
ivy"org.scoverage::scalac-scoverage-domain:${sv}",
ivy"org.scoverage::scalac-scoverage-serializer:${sv}",
ivy"org.scoverage::scalac-scoverage-reporter:${sv}"
)
}
}

private def checkVersions = Task.Anon {
val sv = scalaVersion()
val isSov2 = scoverageVersion().startsWith("2.")
(sv.split('.'), isSov2) match {
case (_, false) =>
Result.Failure("Scoverage 1.x is no longer supported. Please use Scoverage 2.x")
case (Array("3", "0" | "1", _*), _) => Result.Failure(
"Scala 3.0 and 3.1 is not supported by Scoverage. You have to update to at least Scala 3.2 and Scoverage 2.0"
)
case (Array("3", _*), false) => Result.Failure(
"Scoverage 1.x does not support Scala 3. You have to update to at least Scala 3.2 and Scoverage 2.0"
)
case (Array("2", "11", _*), true) => Result.Failure(
"Scoverage 2.x is not compatible with Scala 2.11. Consider using Scoverage 1.x or switch to a newer Scala version."
"Scala 3.0 and 3.1 is not supported by Scoverage. You have to update to at least Scala 3.2"
)
case _ =>
}
Expand All @@ -113,31 +101,14 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule =>
val sv = scoverageVersion()
val millScalaVersion = BuildInfo.scalaVersion

if (sv.startsWith("1.")) {
// In Scoverage 1.x, the reporting API is included in the plugin jar
val scalaVersion = millScalaVersion.split("[.]", 4).toList.take(3) match {
// Scoverage 1 is not released for Scala > 2.13.8, but we don't need to compiler specific code,
// only the reporter API, which does not depend on the Compiler API, so using another full Scala version
// should be safe
case "2" :: "13" :: c :: _ if Try(c.toInt).getOrElse(0) > 8 =>
val v = "2.13.8"
T.log.outputStream.println(
s"Detected an unsupported Scala version (${millScalaVersion}). Using Scala version ${v} to resolve scoverage ${sv} reporting API."
)
v
case _ => millScalaVersion
}
Agg(ivy"org.scoverage:scalac-scoverage-plugin_${scalaVersion}:${sv}")
} else {
// we need to resolve with same Scala version used for Mill, not the project Scala version
val scalaBinVersion = ZincWorkerUtil.scalaBinaryVersion(millScalaVersion)
// In Scoverage 2.x, the reporting API is no longer bundled in the plugin jar
Agg(
ivy"org.scoverage:scalac-scoverage-domain_${scalaBinVersion}:${sv}",
ivy"org.scoverage:scalac-scoverage-serializer_${scalaBinVersion}:${sv}",
ivy"org.scoverage:scalac-scoverage-reporter_${scalaBinVersion}:${sv}"
)
}
// we need to resolve with same Scala version used for Mill, not the project Scala version
val scalaBinVersion = ZincWorkerUtil.scalaBinaryVersion(millScalaVersion)
// In Scoverage 2.x, the reporting API is no longer bundled in the plugin jar
Agg(
ivy"org.scoverage:scalac-scoverage-domain_${scalaBinVersion}:${sv}",
ivy"org.scoverage:scalac-scoverage-serializer_${scalaBinVersion}:${sv}",
ivy"org.scoverage:scalac-scoverage-reporter_${scalaBinVersion}:${sv}"
)
}

def scoverageToolsClasspath: T[Agg[PathRef]] = Task {
Expand All @@ -150,11 +121,7 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule =>
}

def scoverageReportWorkerClasspath: T[Agg[PathRef]] = Task {
val isScov2 = isScoverage2()

val workerArtifact =
if (isScov2) "mill-contrib-scoverage-worker2"
else "mill-contrib-scoverage-worker"
val workerArtifact = "mill-contrib-scoverage-worker2"

millProjectModule(
workerArtifact,
Expand Down Expand Up @@ -209,9 +176,10 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule =>
if (isScala3()) {
Seq(s"-coverage-out:${data().path.toIO.getPath()}")
} else {
val base = s"-P:scoverage:dataDir:${data().path.toIO.getPath()}"
if (isScoverage2()) Seq(base, s"-P:scoverage:sourceRoot:${T.workspace}")
else Seq(base)
Seq(
s"-P:scoverage:dataDir:${data().path.toIO.getPath()}",
s"-P:scoverage:sourceRoot:${T.workspace}"
)
}

outer.scalacOptions() ++ extras
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,18 +302,6 @@ trait FailedWorldTests extends HelloWorldTests {
}
}

object Scoverage1Tests_2_12 extends HelloWorldTests {
override def testScalaVersion: String = sys.props.getOrElse("TEST_SCALA_2_12_VERSION", ???)
override def testScoverageVersion = sys.props.getOrElse("MILL_SCOVERAGE_VERSION", ???)
}

object Scoverage1Tests_2_13 extends HelloWorldTests {
// scaoverage 1.x was only released for Scala up to 2.13.8
override def testScalaVersion: String =
sys.props.getOrElse("TEST_SCALA_2_13_VERSION_FOR_SCOVERAGE_1", ???)
override def testScoverageVersion = sys.props.getOrElse("MILL_SCOVERAGE_VERSION", ???)
}

object Scoverage2Tests_2_13 extends HelloWorldTests {
override def testScalaVersion: String = sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???)
override def testScoverageVersion = sys.props.getOrElse("MILL_SCOVERAGE2_VERSION", ???)
Expand All @@ -323,10 +311,3 @@ object Scoverage2Tests_3_2 extends HelloWorldTests {
override def testScalaVersion: String = sys.props.getOrElse("TEST_SCALA_3_2_VERSION", ???)
override def testScoverageVersion = sys.props.getOrElse("MILL_SCOVERAGE2_VERSION", ???)
}

object Scoverage1Tests_3_2 extends FailedWorldTests {
override def testScalaVersion: String = sys.props.getOrElse("TEST_SCALA_3_2_VERSION", ???)
override def testScoverageVersion = sys.props.getOrElse("MILL_SCOVERAGE_VERSION", ???)
override val errorMsg =
"Scoverage 1.x does not support Scala 3. You have to update to at least Scala 3.2 and Scoverage 2.0"
}

This file was deleted.

0 comments on commit 64ee6f6

Please sign in to comment.