From 49e2ee4c4e0c398c7174f3da013b203cba7c1a6f Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Wed, 15 Nov 2023 15:13:44 +0100 Subject: [PATCH 1/2] Allow resolving moduleDeps with older Scala 3 versions --- .../src/mill/scalalib/CrossModuleBase.scala | 2 +- .../src/mill/scalalib/HelloWorldTests.scala | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/scalalib/src/mill/scalalib/CrossModuleBase.scala b/scalalib/src/mill/scalalib/CrossModuleBase.scala index d8d9c81ffe3..87a54d5cb26 100644 --- a/scalalib/src/mill/scalalib/CrossModuleBase.scala +++ b/scalalib/src/mill/scalalib/CrossModuleBase.scala @@ -22,7 +22,7 @@ trait CrossModuleBase extends ScalaModule with Cross.Module[String] { crossScalaVersion .split('.') .inits - .takeWhile(_.length > 1) + .takeWhile(_.length > (if (ZincWorkerUtil.isScala3(crossScalaVersion)) 0 else 1)) .flatMap(prefix => c.crossModules .find(_.crossScalaVersion.split('.').startsWith(prefix)) diff --git a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala index 873536a6bd5..403464071ce 100644 --- a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala +++ b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala @@ -22,6 +22,8 @@ object HelloWorldTests extends TestSuite { val scala2123Version = "2.12.3" val scala212Version = sys.props.getOrElse("TEST_SCALA_2_12_VERSION", ???) val scala213Version = sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???) + val scala32Version = sys.props.getOrElse("TEST_SCALA_3_2_VERSION", ???) + val scala33Version = sys.props.getOrElse("TEST_SCALA_3_3_VERSION", ???) val zincVersion = sys.props.getOrElse("TEST_ZINC_VERSION", ???) trait HelloBase extends TestUtil.BaseModule { @@ -59,6 +61,15 @@ object HelloWorldTests extends TestSuite { ) trait HelloWorldCross extends CrossScalaModule } + object CrossModuleDeps extends HelloBase { + object stable extends Cross[Stable](scala212Version, scala32Version) + trait Stable extends CrossScalaModule + + object cuttingEdge extends Cross[CuttingEdge](scala213Version, scala33Version) + trait CuttingEdge extends CrossScalaModule { + def moduleDeps = Seq(stable()) + } + } object HelloWorldDefaultMain extends HelloBase { object core extends HelloWorldModule @@ -677,6 +688,14 @@ object HelloWorldTests extends TestSuite { } } + "scala-33-depend-on-scala-32-works" - { + CrossModuleDeps.cuttingEdge(scala33Version).moduleDeps + } + "scala-213-depend-on-scala-212-fails" - { + val message = intercept(CrossModuleDeps.cuttingEdge(scala213Version).moduleDeps).getMessage + assert(message == "Unable to find compatible cross version between 2.13.8 and 2.12.6,3.2.0") + } + "runMain" - { "runMainObject" - workspaceTest(HelloWorld) { eval => val runResult = eval.outPath / "core" / "runMain.dest" / "hello-mill" From 0df564a28672ab2f7254674a33bb66a7faba8487 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 8 Jan 2024 14:47:31 +0100 Subject: [PATCH 2/2] fix: Fix tests --- scalalib/test/src/mill/scalalib/HelloWorldTests.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala index 403464071ce..7bceebea13c 100644 --- a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala +++ b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala @@ -692,7 +692,9 @@ object HelloWorldTests extends TestSuite { CrossModuleDeps.cuttingEdge(scala33Version).moduleDeps } "scala-213-depend-on-scala-212-fails" - { - val message = intercept(CrossModuleDeps.cuttingEdge(scala213Version).moduleDeps).getMessage + val message = intercept[Exception]( + CrossModuleDeps.cuttingEdge(scala213Version).moduleDeps + ).getMessage assert(message == "Unable to find compatible cross version between 2.13.8 and 2.12.6,3.2.0") }