Skip to content

Commit bfc19a4

Browse files
authored
Merge pull request #3911 from Gedochao/maintenance/scala-2-cleanup
Drop Scala 2 in `runner`, `test-runner` and `tasty-lib` modules
2 parents 216bc95 + d9af5a4 commit bfc19a4

File tree

18 files changed

+161
-83
lines changed

18 files changed

+161
-83
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,7 @@ jobs:
15931593
- name: Print version
15941594
run: ./mill -i show project.publish.finalPublishVersion
15951595
- name: Publish to Sonatype Central
1596-
run: ./mill mill.scalalib.SonatypeCentralPublishModule/ --publishArtifacts '{__[],_,test-runner[2.13.17],test-runner[2.12.20],runner[2.13.17],runner[2.12.20]}.publishArtifacts'
1596+
run: ./mill mill.scalalib.SonatypeCentralPublishModule/ --publishArtifacts '{__[],_}.publishArtifacts'
15971597
if: env.SHOULD_PUBLISH == 'true'
15981598
env:
15991599
MILL_PGP_SECRET_BASE64: ${{ secrets.PGP_SECRET }}

build.mill.scala

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ object directives extends Cross[Directives](Scala.scala3MainVersions)
105105
object core extends Cross[Core](Scala.scala3MainVersions) with CrossScalaDefaultToInternal
106106
object `build-module` extends Cross[Build](Scala.scala3MainVersions)
107107
with CrossScalaDefaultToInternal
108-
object runner extends Cross[Runner](Scala.runnerScalaVersions) with CrossScalaDefaultToRunner
109-
object `test-runner` extends Cross[TestRunner](Scala.testRunnerScalaVersions)
110-
with CrossScalaDefaultToRunner
111-
object `tasty-lib` extends Cross[TastyLib](Scala.all) with CrossScalaDefaultToInternal
108+
object runner extends Runner
109+
object `test-runner` extends TestRunner
110+
object `tasty-lib` extends Cross[TastyLib](Scala.scala3MainVersions)
111+
with CrossScalaDefaultToInternal
112112
// Runtime classes used within native image on Scala 3 replacing runtime from Scala
113113
object `scala3-runtime` extends Cross[Scala3Runtime](Scala.scala3MainVersions)
114114
with CrossScalaDefaultToInternal
@@ -437,16 +437,16 @@ trait Core extends ScalaCliCrossSbtModule
437437
def constantsFile: T[PathRef] = Task(persistent = true) {
438438
val dir = Task.dest / "constants"
439439
val dest = dir / "Constants.scala"
440-
val testRunnerMainClass = `test-runner`(Scala.runnerScala3)
440+
val testRunnerMainClass = `test-runner`
441441
.mainClass()
442442
.getOrElse(sys.error("No main class defined for test-runner"))
443-
val runnerMainClass = build.runner(Scala.runnerScala3)
443+
val runnerMainClass = build.runner
444444
.mainClass()
445445
.getOrElse(sys.error("No main class defined for runner"))
446446
val detailedVersionValue =
447447
if (`local-repo`.developingOnStubModules) s"""Some("${vcsState()}")"""
448448
else "None"
449-
val testRunnerOrganization = `test-runner`(Scala.runnerScala3)
449+
val testRunnerOrganization = `test-runner`
450450
.pomSettings()
451451
.organization
452452
val code =
@@ -466,14 +466,15 @@ trait Core extends ScalaCliCrossSbtModule
466466
| def scalaNativeVersion = "${Deps.Versions.scalaNative}"
467467
|
468468
| def testRunnerOrganization = "$testRunnerOrganization"
469-
| def testRunnerModuleName = "${`test-runner`(Scala.runnerScala3).artifactName()}"
470-
| def testRunnerVersion = "${`test-runner`(Scala.runnerScala3).publishVersion()}"
469+
| def testRunnerModuleName = "${`test-runner`.artifactName()}"
470+
| def testRunnerVersion = "${`test-runner`.publishVersion()}"
471471
| def testRunnerMainClass = "$testRunnerMainClass"
472472
|
473-
| def runnerOrganization = "${build.runner(Scala.runnerScala3).pomSettings().organization}"
474-
| def runnerModuleName = "${build.runner(Scala.runnerScala3).artifactName()}"
475-
| def runnerVersion = "${build.runner(Scala.runnerScala3).publishVersion()}"
476-
| def runnerLegacyVersion = "${Cli.runnerLegacyVersion}"
473+
| def runnerOrganization = "${build.runner.pomSettings().organization}"
474+
| def runnerModuleName = "${build.runner.artifactName()}"
475+
| def runnerVersion = "${build.runner.publishVersion()}"
476+
| def runnerScala30LegacyVersion = "${Cli.runnerScala30LegacyVersion}"
477+
| def runnerScala2LegacyVersion = "${Cli.runnerScala2LegacyVersion}"
477478
| def runnerMainClass = "$runnerMainClass"
478479
|
479480
| def semanticDbPluginOrganization = "${Deps.semanticDbScalac.dep.module.organization
@@ -744,7 +745,7 @@ trait Build extends ScalaCliCrossSbtModule
744745
options(crossScalaVersion),
745746
directives(crossScalaVersion),
746747
`scala-cli-bsp`,
747-
`test-runner`(crossScalaVersion),
748+
`test-runner`,
748749
`tasty-lib`(crossScalaVersion)
749750
)
750751
override def scalacOptions: T[Seq[String]] = Task {
@@ -1095,7 +1096,8 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
10951096
| def ammoniteVersion = "${Deps.ammonite.dep.versionConstraint.asString}"
10961097
| def defaultGraalVMJavaVersion = "${deps.graalVmJavaVersion}"
10971098
| def defaultGraalVMVersion = "${deps.graalVmVersion}"
1098-
| def runnerLegacyVersion = "${Cli.runnerLegacyVersion}"
1099+
| def runnerScala30LegacyVersion = "${Cli.runnerScala30LegacyVersion}"
1100+
| def runnerScala2LegacyVersion = "${Cli.runnerScala2LegacyVersion}"
10991101
| def scalaPyVersion = "${Deps.scalaPy.dep.versionConstraint.asString}"
11001102
| def scalaPyMaxScalaNative = "${Deps.Versions.maxScalaNativeForScalaPy}"
11011103
| def bloopVersion = "${Deps.bloopRifle.dep.versionConstraint.asString}"
@@ -1275,19 +1277,19 @@ trait CliIntegrationDocker extends SbtModule with ScalaCliPublishModule with Has
12751277
)
12761278
}
12771279

1278-
trait Runner extends ScalaCliCrossSbtModule
1280+
trait Runner extends SbtModule
12791281
with ScalaCliPublishModule
1280-
with ScalaCliScalafixLegacyModule {
1281-
override def crossScalaVersion: String = crossValue
1282+
with ScalaCliScalafixModule {
1283+
override def scalaVersion: T[String] = Scala.scala3Lts
12821284
override def scalacOptions: T[Seq[String]] = Task {
1283-
super.scalacOptions() ++ Seq("-release", "8")
1285+
super.scalacOptions() ++ Seq("-release", "8", "-deprecation")
12841286
}
12851287
override def mainClass: T[Option[String]] = Some("scala.cli.runner.Runner")
12861288
override def sources: T[Seq[PathRef]] = Task.Sources {
12871289
val scala3DirNames =
1288-
if (crossScalaVersion.startsWith("3.")) {
1290+
if (scalaVersion().startsWith("3.")) {
12891291
val name =
1290-
if (crossScalaVersion.contains("-RC")) "scala-3-unstable"
1292+
if (scalaVersion().contains("-RC")) "scala-3-unstable"
12911293
else "scala-3-stable"
12921294
Seq(name)
12931295
}
@@ -1298,12 +1300,12 @@ trait Runner extends ScalaCliCrossSbtModule
12981300
}
12991301
}
13001302

1301-
trait TestRunner extends ScalaCliCrossSbtModule
1303+
trait TestRunner extends SbtModule
13021304
with ScalaCliPublishModule
1303-
with ScalaCliScalafixLegacyModule {
1304-
override def crossScalaVersion: String = crossValue
1305+
with ScalaCliScalafixModule {
1306+
override def scalaVersion: T[String] = Scala.scala3Lts
13051307
override def scalacOptions: T[Seq[String]] = Task {
1306-
super.scalacOptions() ++ Seq("-release", "8")
1308+
super.scalacOptions() ++ Seq("-release", "8", "-deprecation")
13071309
}
13081310
override def ivyDeps: T[Agg[Dep]] = super.ivyDeps() ++ Agg(
13091311
Deps.asm,
@@ -1315,7 +1317,7 @@ trait TestRunner extends ScalaCliCrossSbtModule
13151317

13161318
trait TastyLib extends ScalaCliCrossSbtModule
13171319
with ScalaCliPublishModule
1318-
with ScalaCliScalafixLegacyModule {
1320+
with ScalaCliScalafixModule {
13191321
override def crossScalaVersion: String = crossValue
13201322
def constantsFile: T[PathRef] = Task(persistent = true) {
13211323
val dir = Task.dest / "constants"
@@ -1345,12 +1347,9 @@ object `local-repo` extends LocalRepo {
13451347
*/
13461348
def developingOnStubModules = false
13471349

1348-
override def stubsModules: Seq[PublishLocalNoFluff] =
1349-
for {
1350-
sv <- Scala.runnerScalaVersions
1351-
proj <- Seq(runner, `test-runner`)
1352-
} yield proj(sv)
1353-
override def version: T[String] = runner(Scala.runnerScala3).publishVersion()
1350+
override def stubsModules: Seq[PublishLocalNoFluff] = Seq(runner, `test-runner`)
1351+
1352+
override def version: T[String] = runner.publishVersion()
13541353
}
13551354

13561355
// Helper CI commands

modules/integration/src/test/scala/scala/cli/integration/CompileTests213.scala

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,23 @@ class CompileTests213 extends CompileTestDefinitions with Test213 {
4444
| }
4545
|}""".stripMargin
4646
).fromRoot { root =>
47-
val result = os.proc(TestUtil.cli, "test", ".").call(
47+
val result = os.proc(TestUtil.cli, "test", ".", extraOptions).call(
4848
cwd = root,
4949
check = false,
5050
mergeErrIntoOut = true
5151
)
52-
val separator = if (Properties.isWin) "\\" else "/"
52+
val separator = if (Properties.isWin) "\\" else "/"
53+
val graalVmVersion = Constants.defaultGraalVMJavaVersion
54+
val legacyRunnerVersion = Constants.runnerScala2LegacyVersion
55+
val ltsPrefix = Constants.scala3LtsPrefix
5356

5457
val expectedOutput =
55-
s"""|Compiling project (Scala ${Constants.scala213}, JVM (${Constants
56-
.defaultGraalVMJavaVersion}))
57-
|Compiled project (Scala ${Constants.scala213}, JVM (${Constants
58-
.defaultGraalVMJavaVersion}))
59-
|Compiling project (test, Scala ${Constants.scala213}, JVM (${Constants
60-
.defaultGraalVMJavaVersion}))
58+
s"""|Compiling project (Scala $actualScalaVersion, JVM ($graalVmVersion))
59+
|Compiled project (Scala $actualScalaVersion, JVM ($graalVmVersion))
60+
|[warn] Scala $actualScalaVersion is no longer supported by the test-runner module.
61+
|[warn] Defaulting to a legacy test-runner module version: $legacyRunnerVersion.
62+
|[warn] To use the latest test-runner, upgrade Scala to at least $ltsPrefix.
63+
|Compiling project (test, Scala $actualScalaVersion, JVM ($graalVmVersion))
6164
|[info] .${separator}Test.test.scala:6:5
6265
|[info] scala.Predef.ArrowAssoc[Int](1).->[String]("test")
6366
|[info] scala.Predef.ArrowAssoc[Int](1).->[String]("test")
@@ -71,8 +74,7 @@ class CompileTests213 extends CompileTestDefinitions with Test213 {
7174
|[error] example error message
7275
|[error] Scala2Example.macroMethod(1 -> "test")
7376
|[error] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
74-
|Error compiling project (test, Scala ${Constants.scala213}, JVM (${Constants
75-
.defaultGraalVMJavaVersion}))
77+
|Error compiling project (test, Scala $actualScalaVersion, JVM ($graalVmVersion))
7678
|Compilation failed
7779
|""".stripMargin
7880

modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2426,7 +2426,11 @@ abstract class RunTestDefinitions
24262426
val res = os.proc(TestUtil.cli, "run", ".", "--runner", extraOptions)
24272427
.call(cwd = root, stderr = os.Pipe)
24282428
expect(res.out.trim() == expectedMessage)
2429-
expect(!res.err.trim().contains(legacyRunnerWarning))
2429+
val legacyWarningCheck = {
2430+
val check = res.err.trim().contains(legacyRunnerWarning)
2431+
if (actualScalaVersion.startsWith("2")) check else !check
2432+
}
2433+
expect(legacyWarningCheck)
24302434
}
24312435
}
24322436

modules/integration/src/test/scala/scala/cli/integration/RunTestsDefault.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class RunTestsDefault extends RunTestDefinitions
192192
scalaVersion <- TestUtil.legacyScalaVersionsOnePerMinor
193193
expectedMessage = "Hello, world!"
194194
expectedWarning =
195-
s"Defaulting to a legacy runner module version: ${Constants.runnerLegacyVersion}"
195+
s"Defaulting to a legacy runner module version: ${Constants.runnerScala30LegacyVersion}"
196196
}
197197
test(
198198
s"run a simple hello world with the runner module on the classpath and Scala $scalaVersion (legacy)"
Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
11
package scala.cli.integration
22

3-
class TestTests212 extends TestTestDefinitions with Test212
3+
import com.eed3si9n.expecty.Expecty.expect
4+
5+
import scala.cli.integration.TestUtil.StringOps
6+
7+
class TestTests212 extends TestTestDefinitions with Test212 {
8+
test(s"run a simple test with Scala $actualScalaVersion (legacy)") {
9+
val expectedMessage = "Hello, world!"
10+
TestInputs(os.rel / "example.test.scala" ->
11+
s"""//> using dep com.novocode:junit-interface:0.11
12+
|import org.junit.Test
13+
|
14+
|class MyTests {
15+
| @Test
16+
| def foo(): Unit = {
17+
| assert(2 + 2 == 4)
18+
| println("$expectedMessage")
19+
| }
20+
|}
21+
|""".stripMargin).fromRoot { root =>
22+
val expectedWarning =
23+
s"Defaulting to a legacy test-runner module version: ${Constants.runnerScala2LegacyVersion}"
24+
val res =
25+
os.proc(TestUtil.cli, "test", ".", extraOptions)
26+
.call(cwd = root, stderr = os.Pipe)
27+
val out = res.out.trim()
28+
expect(out.contains(expectedMessage))
29+
val err = res.err.trim()
30+
expect(err.contains(expectedWarning))
31+
expect(err.countOccurrences(expectedWarning) == 1)
32+
}
33+
}
34+
}
Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
11
package scala.cli.integration
22

3-
class TestTests213 extends TestTestDefinitions with Test213
3+
import com.eed3si9n.expecty.Expecty.expect
4+
5+
import scala.cli.integration.TestUtil.StringOps
6+
7+
class TestTests213 extends TestTestDefinitions with Test213 {
8+
test(s"run a simple test with Scala $actualScalaVersion (legacy)") {
9+
val expectedMessage = "Hello, world!"
10+
TestInputs(os.rel / "example.test.scala" ->
11+
s"""//> using dep com.novocode:junit-interface:0.11
12+
|import org.junit.Test
13+
|
14+
|class MyTests {
15+
| @Test
16+
| def foo(): Unit = {
17+
| assert(2 + 2 == 4)
18+
| println("$expectedMessage")
19+
| }
20+
|}
21+
|""".stripMargin).fromRoot { root =>
22+
val expectedWarning =
23+
s"Defaulting to a legacy test-runner module version: ${Constants.runnerScala2LegacyVersion}"
24+
val res =
25+
os.proc(TestUtil.cli, "test", ".", extraOptions)
26+
.call(cwd = root, stderr = os.Pipe)
27+
val out = res.out.trim()
28+
expect(out.contains(expectedMessage))
29+
val err = res.err.trim()
30+
expect(err.contains(expectedWarning))
31+
expect(err.countOccurrences(expectedWarning) == 1)
32+
}
33+
}
34+
35+
}

modules/integration/src/test/scala/scala/cli/integration/TestTestsDefault.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class TestTestsDefault extends TestTestDefinitions with TestDefault {
7272
scalaVersion <- TestUtil.legacyScalaVersionsOnePerMinor
7373
expectedMessage = "Hello, world!"
7474
expectedWarning =
75-
s"Defaulting to a legacy test-runner module version: ${Constants.runnerLegacyVersion}"
75+
s"Defaulting to a legacy test-runner module version: ${Constants.runnerScala30LegacyVersion}"
7676
}
7777
test(s"run a simple test with Scala $scalaVersion (legacy)") {
7878
TestInputs(os.rel / "example.test.scala" ->

modules/options/src/main/scala/scala/build/Artifacts.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,18 @@ object Artifacts {
146146
scalaVersion = scalaParams.scalaVersion
147147
} yield scalaVersion).getOrElse(defaultScalaVersion)
148148

149-
val shouldUseLegacyRunners =
149+
val shouldUseLegacyScala3Runners =
150150
scalaVersion.startsWith("3") &&
151151
scalaVersion.coursierVersion < s"$scala3LtsPrefix.0".coursierVersion
152+
val shouldUseLegacyScala2Runners = scalaVersion.startsWith("2")
153+
val shouldUseLegacyRunners = shouldUseLegacyScala2Runners || shouldUseLegacyScala3Runners
152154

153155
val jvmTestRunnerDependencies =
154156
if addJvmTestRunner then {
157+
val runnerLegacyVersion =
158+
if scalaVersion.startsWith("3")
159+
then runnerScala30LegacyVersion
160+
else runnerScala2LegacyVersion
155161
val testRunnerVersion0 =
156162
if shouldUseLegacyRunners then {
157163
logger.message(
@@ -471,6 +477,10 @@ object Artifacts {
471477
else Nil
472478
val runnerVersion0 =
473479
if shouldUseLegacyRunners then {
480+
val runnerLegacyVersion =
481+
if shouldUseLegacyScala3Runners
482+
then runnerScala30LegacyVersion
483+
else runnerScala2LegacyVersion
474484
logger.message(
475485
s"""$warnPrefix Scala $scalaVersion is no longer supported by the runner module.
476486
|$warnPrefix Defaulting to a legacy runner module version: $runnerLegacyVersion.

modules/runner/src/main/scala/scala/cli/runner/StackTracePrinter.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,8 @@ final case class StackTracePrinter(
9797
}
9898

9999
object StackTracePrinter {
100-
101100
lazy val coloredStackTraces: Boolean =
102101
sys.props.get("scala.colored-stack-traces")
103102
.map(_.toLowerCase(Locale.ROOT))
104103
.forall(_ == "true")
105-
106104
}

0 commit comments

Comments
 (0)