Skip to content

Commit

Permalink
Allow resolving moduleDeps with older Scala 3 versions (#2877)
Browse files Browse the repository at this point in the history
# Motivation
Sometimes you want different modules in a build to have different Scala
3 versions, one the older and one the newer.
The current resolve implementation in `CrossModuleBase` is tailored to
Scala 2 since it assumes that the binary version is `x.y` while in Scala
3 it's just the first part.

This change adapts the algorithm to consider 1 or 2 parts depending if
it is Scala 3 or not.

Pull Request: #2877
  • Loading branch information
lolgab authored Jan 8, 2024
1 parent e57652b commit 554c84f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scalalib/src/mill/scalalib/CrossModuleBase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
21 changes: 21 additions & 0 deletions scalalib/test/src/mill/scalalib/HelloWorldTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -677,6 +688,16 @@ 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[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")
}

"runMain" - {
"runMainObject" - workspaceTest(HelloWorld) { eval =>
val runResult = eval.outPath / "core" / "runMain.dest" / "hello-mill"
Expand Down

0 comments on commit 554c84f

Please sign in to comment.