From cb30f1c42c818b2a2b1e216823ca09c8430da5f9 Mon Sep 17 00:00:00 2001 From: Nikolay Tatarinov <5min4eq.unity@gmail.com> Date: Tue, 20 Mar 2018 18:20:38 +0300 Subject: Support scala milestone releases (with fixes for 2.13.0-M3) (#247) * return full scala version for milestone releases * complete support for scala 2.13.0-M2 * match 2.13 milestone releases for compiler bridge sources * add hello world test case for scala 2.13.0-M3 --- scalajslib/src/mill/scalajslib/ScalaJSModule.scala | 13 ++----------- scalalib/src/mill/scalalib/Lib.scala | 11 ++++++++++- scalalib/src/mill/scalalib/ScalaModule.scala | 15 +++++++++++---- scalalib/src/mill/scalalib/ScalaWorkerApi.scala | 2 +- .../test/resources/hello-world/core/src-2.13/Shim.scala | 5 +++++ scalalib/test/src/mill/scalalib/HelloWorldTests.scala | 3 ++- scalaworker/src/mill/scalaworker/ScalaWorker.scala | 12 ++++-------- 7 files changed, 35 insertions(+), 26 deletions(-) create mode 100644 scalalib/test/resources/hello-world/core/src-2.13/Shim.scala diff --git a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala index 3b566e13..11b9eaf8 100644 --- a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala +++ b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala @@ -7,7 +7,7 @@ import coursier.maven.MavenRepository import mill.eval.{PathRef, Result} import mill.eval.Result.Success import mill.scalalib.Lib.resolveDependencies -import mill.scalalib.{CompilationResult, Dep, DepSyntax, TestModule} +import mill.scalalib.{DepSyntax, Lib, TestModule} import mill.util.{Ctx, Loose} trait ScalaJSModule extends scalalib.ScalaModule { outer => @@ -21,16 +21,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => override def moduleDeps = Seq(outer) } - private val ReleaseVersion = raw"""(\d+)\.(\d+)\.(\d+)""".r - private val MinorSnapshotVersion = raw"""(\d+)\.(\d+)\.([1-9]\d*)-SNAPSHOT""".r - - def scalaJSBinaryVersion = T{ - scalaJSVersion() match { - case ReleaseVersion(major, minor, _) => s"$major.$minor" - case MinorSnapshotVersion(major, minor, _) => s"$major.$minor" - case _ => scalaJSVersion() - } - } + def scalaJSBinaryVersion = T { Lib.scalaBinaryVersion(scalaJSVersion()) } def scalaJSBridgeVersion = T{ scalaJSVersion().split('.').dropRight(1).mkString(".") } diff --git a/scalalib/src/mill/scalalib/Lib.scala b/scalalib/src/mill/scalalib/Lib.scala index d8fd9963..e6a7a255 100644 --- a/scalalib/src/mill/scalalib/Lib.scala +++ b/scalalib/src/mill/scalalib/Lib.scala @@ -16,7 +16,16 @@ case class CompilationResult(analysisFile: Path, classes: PathRef) object Lib{ - def scalaBinaryVersion(scalaVersion: String) = scalaVersion.split('.').dropRight(1).mkString(".") + private val ReleaseVersion = raw"""(\d+)\.(\d+)\.(\d+)""".r + private val MinorSnapshotVersion = raw"""(\d+)\.(\d+)\.([1-9]\d*)-SNAPSHOT""".r + + def scalaBinaryVersion(scalaVersion: String) = { + scalaVersion match { + case ReleaseVersion(major, minor, _) => s"$major.$minor" + case MinorSnapshotVersion(major, minor, _) => s"$major.$minor" + case _ => scalaVersion + } + } def grepJar(classPath: Agg[Path], s: String) = { classPath diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala index 0fe7e3dc..b5106e3e 100644 --- a/scalalib/src/mill/scalalib/ScalaModule.scala +++ b/scalalib/src/mill/scalalib/ScalaModule.scala @@ -98,13 +98,20 @@ trait ScalaModule extends mill.Module with TaskModule { outer => def platformSuffix = T{ "" } - def scalaCompilerBridgeSources = T{ + private val Milestone213 = raw"""2.13.(\d+)-M(\d+)""".r + + def scalaCompilerBridgeSources = T { + val (scalaVersion0, scalaBinaryVersion0) = scalaVersion() match { + case Milestone213(_, _) => ("2.13.0-M2", "2.13.0-M2") + case _ => (scalaVersion(), Lib.scalaBinaryVersion(scalaVersion())) + } + resolveDependencies( repositories, - scalaVersion(), + scalaVersion0, Seq(ivy"org.scala-sbt::compiler-bridge:1.1.0"), sources = true - ) + ).map(_.find(_.path.last == s"compiler-bridge_${scalaBinaryVersion0}-1.1.0-sources.jar").map(_.path).get) } def scalacPluginClasspath: T[Agg[PathRef]] = T { @@ -154,7 +161,7 @@ trait ScalaModule extends mill.Module with TaskModule { outer => scalaWorker.worker().compileScala( scalaVersion(), allSourceFiles().map(_.path), - scalaCompilerBridgeSources().map(_.path), + scalaCompilerBridgeSources(), compileClasspath().map(_.path), scalaCompilerClasspath().map(_.path), scalacOptions(), diff --git a/scalalib/src/mill/scalalib/ScalaWorkerApi.scala b/scalalib/src/mill/scalalib/ScalaWorkerApi.scala index 84db1dd8..a3760aed 100644 --- a/scalalib/src/mill/scalalib/ScalaWorkerApi.scala +++ b/scalalib/src/mill/scalalib/ScalaWorkerApi.scala @@ -54,7 +54,7 @@ trait ScalaWorkerModule extends mill.Module{ trait ScalaWorkerApi { def compileScala(scalaVersion: String, sources: Agg[Path], - compileBridgeSources: Agg[Path], + compilerBridgeSources: Path, compileClasspath: Agg[Path], compilerClasspath: Agg[Path], scalacOptions: Seq[String], diff --git a/scalalib/test/resources/hello-world/core/src-2.13/Shim.scala b/scalalib/test/resources/hello-world/core/src-2.13/Shim.scala new file mode 100644 index 00000000..cedeb26b --- /dev/null +++ b/scalalib/test/resources/hello-world/core/src-2.13/Shim.scala @@ -0,0 +1,5 @@ +object Shim{ + def main(args: Array[String]): Unit = { + Main0(args(0), scala.util.Properties.versionNumberString + " idk") + } +} diff --git a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala index 61d2b724..8b7c459f 100644 --- a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala +++ b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala @@ -30,7 +30,7 @@ object HelloWorldTests extends TestSuite { object core extends HelloWorldModule } object CrossHelloWorld extends HelloBase { - object core extends Cross[HelloWorldCross]("2.10.6", "2.11.11", "2.12.3", "2.12.4") + object core extends Cross[HelloWorldCross]("2.10.6", "2.11.11", "2.12.3", "2.12.4", "2.13.0-M3") class HelloWorldCross(val crossScalaVersion: String) extends CrossScalaModule } @@ -250,6 +250,7 @@ object HelloWorldTests extends TestSuite { 'v211 - TestUtil.disableInJava9OrAbove(workspaceTest(CrossHelloWorld)(cross(_, "2.11.11", "2.11.11 pwns"))) 'v2123 - workspaceTest(CrossHelloWorld)(cross(_, "2.12.3", "2.12.3 leet")) 'v2124 - workspaceTest(CrossHelloWorld)(cross(_, "2.12.4", "2.12.4 leet")) + 'v2130M3 - workspaceTest(CrossHelloWorld)(cross(_, "2.13.0-M3", "2.13.0-M3 idk")) } diff --git a/scalaworker/src/mill/scalaworker/ScalaWorker.scala b/scalaworker/src/mill/scalaworker/ScalaWorker.scala index c7aa4cd5..f26c98b3 100644 --- a/scalaworker/src/mill/scalaworker/ScalaWorker.scala +++ b/scalaworker/src/mill/scalaworker/ScalaWorker.scala @@ -87,7 +87,7 @@ class ScalaWorker(ctx0: mill.util.Ctx, @volatile var scalaInstanceCache = Option.empty[(Long, ScalaInstance)] def compileZincBridge(scalaVersion: String, - compileBridgeSources: Agg[Path], + sourcesJar: Path, compilerJars: Array[File]) = { val workingDir = ctx0.dest / scalaVersion val compiledDest = workingDir / 'compiled @@ -98,11 +98,7 @@ class ScalaWorker(ctx0: mill.util.Ctx, mkdir(workingDir) mkdir(compiledDest) - val sourceJar = compileBridgeSources - .find(_.last == s"compiler-bridge_${Lib.scalaBinaryVersion(scalaVersion)}-1.1.0-sources.jar") - .get - - val sourceFolder = mill.modules.Util.unpackZip(sourceJar)(workingDir) + val sourceFolder = mill.modules.Util.unpackZip(sourcesJar)(workingDir) val classloader = mill.util.ClassLoader.create(compilerJars.map(_.toURI.toURL), null)(ctx0) val scalacMain = classloader.loadClass("scala.tools.nsc.Main") val argsArray = Array[String]( @@ -137,7 +133,7 @@ class ScalaWorker(ctx0: mill.util.Ctx, def compileScala(scalaVersion: String, sources: Agg[Path], - compileBridgeSources: Agg[Path], + compilerBridgeSources: Path, compileClasspath: Agg[Path], compilerClasspath: Agg[Path], scalacOptions: Seq[String], @@ -148,7 +144,7 @@ class ScalaWorker(ctx0: mill.util.Ctx, val compileClasspathFiles = compileClasspath.map(_.toIO).toArray val compilerJars = compilerClasspath.toArray.map(_.toIO) - val compilerBridge = compileZincBridge(scalaVersion, compileBridgeSources, compilerJars) + val compilerBridge = compileZincBridge(scalaVersion, compilerBridgeSources, compilerJars) val pluginJars = scalacPluginClasspath.toArray.map(_.toIO) -- cgit v1.2.3