From 2e50c963eecadcf7bd6ecd6956584ab099d5273a Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Fri, 2 Feb 2018 20:15:00 -0800 Subject: compile zinc compiler bridges on demand to remove restriction on supported scala versions --- scalalib/src/mill/scalalib/GenIdea.scala | 1 - scalalib/src/mill/scalalib/Lib.scala | 5 +-- scalalib/src/mill/scalalib/PublishModule.scala | 4 +-- scalalib/src/mill/scalalib/ScalaModule.scala | 42 +++++++------------------ scalalib/src/mill/scalalib/ScalaWorkerApi.scala | 19 ++++++----- 5 files changed, 29 insertions(+), 42 deletions(-) (limited to 'scalalib/src') diff --git a/scalalib/src/mill/scalalib/GenIdea.scala b/scalalib/src/mill/scalalib/GenIdea.scala index ea401b04..6511ee25 100644 --- a/scalalib/src/mill/scalalib/GenIdea.scala +++ b/scalalib/src/mill/scalalib/GenIdea.scala @@ -45,7 +45,6 @@ object GenIdea { val Result.Success(res) = scalalib.Lib.resolveDependencies( Seq(Cache.ivy2Local, MavenRepository("https://repo1.maven.org/maven2")), "2.12.4", - "2.12", for(name <- artifactNames) yield Dep("com.lihaoyi", s"mill-${name}", "0.0.1-SNAPSHOT") ) diff --git a/scalalib/src/mill/scalalib/Lib.scala b/scalalib/src/mill/scalalib/Lib.scala index 8fbbfc0f..ae10bd00 100644 --- a/scalalib/src/mill/scalalib/Lib.scala +++ b/scalalib/src/mill/scalalib/Lib.scala @@ -18,6 +18,8 @@ case class CompilationResult(analysisFile: Path, classes: PathRef) object Lib{ + def scalaBinaryVersion(scalaVersion: String) = scalaVersion.split('.').dropRight(1).mkString(".") + def grepJar(classPath: Agg[Path], s: String) = { classPath .find(_.toString.endsWith(s)) @@ -34,13 +36,12 @@ object Lib{ */ def resolveDependencies(repositories: Seq[Repository], scalaVersion: String, - scalaBinaryVersion: String, deps: TraversableOnce[Dep], sources: Boolean = false): Result[Agg[PathRef]] = { val flattened = deps.map{ case Dep.Java(dep) => dep case Dep.Scala(dep) => - dep.copy(module = dep.module.copy(name = dep.module.name + "_" + scalaBinaryVersion)) + dep.copy(module = dep.module.copy(name = dep.module.name + "_" + scalaBinaryVersion(scalaVersion))) case Dep.Point(dep) => dep.copy(module = dep.module.copy(name = dep.module.name + "_" + scalaVersion)) }.toSet diff --git a/scalalib/src/mill/scalalib/PublishModule.scala b/scalalib/src/mill/scalalib/PublishModule.scala index 64efce77..cedcdf8a 100644 --- a/scalalib/src/mill/scalalib/PublishModule.scala +++ b/scalalib/src/mill/scalalib/PublishModule.scala @@ -15,7 +15,7 @@ trait PublishModule extends ScalaModule { outer => def pom = T { val dependencies = - ivyDeps().map(Artifact.fromDep(_, scalaVersion(), scalaBinaryVersion())) + ivyDeps().map(Artifact.fromDep(_, scalaVersion(), Lib.scalaBinaryVersion(scalaVersion()))) val pom = Pom(artifact(), dependencies, artifactName(), pomSettings()) val pomPath = T.ctx().dest / s"${artifactId()}-${publishVersion()}.pom" @@ -25,7 +25,7 @@ trait PublishModule extends ScalaModule { outer => def ivy = T { val dependencies = - ivyDeps().map(Artifact.fromDep(_, scalaVersion(), scalaBinaryVersion())) + ivyDeps().map(Artifact.fromDep(_, scalaVersion(), Lib.scalaBinaryVersion(scalaVersion()))) val ivy = Ivy(artifact(), dependencies) val ivyPath = T.ctx().dest / "ivy.xml" write.over(ivyPath, ivy) diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala index 8f635906..47326c6c 100644 --- a/scalalib/src/mill/scalalib/ScalaModule.scala +++ b/scalalib/src/mill/scalalib/ScalaModule.scala @@ -7,10 +7,12 @@ import mill.define.{Cross, Task} import mill.define.TaskModule import mill.eval.{PathRef, Result} import mill.modules.Jvm -import mill.modules.Jvm.{createAssembly, createJar, interactiveSubprocess, subprocess, runLocal} +import mill.modules.Jvm.{createAssembly, createJar, interactiveSubprocess, runLocal, subprocess} import Lib._ import mill.define.Cross.Resolver import mill.util.Loose.Agg +import mill.util.Strict + /** * Core configuration required to compile a single Scala compilation target */ @@ -23,7 +25,6 @@ trait ScalaModule extends mill.Module with TaskModule { outer => def scalaVersion: T[String] def mainClass: T[Option[String]] = None - def scalaBinaryVersion = T{ scalaVersion().split('.').dropRight(1).mkString(".") } def ivyDeps = T{ Agg.empty[Dep] } def compileIvyDeps = T{ Agg.empty[Dep] } def scalacPluginIvyDeps = T{ Agg.empty[Dep] } @@ -60,7 +61,6 @@ trait ScalaModule extends mill.Module with TaskModule { outer => resolveDependencies( repositories, scalaVersion(), - scalaBinaryVersion(), deps(), sources ) @@ -90,31 +90,13 @@ trait ScalaModule extends mill.Module with TaskModule { outer => depClasspath() } - /** - * Strange compiler-bridge jar that the Zinc incremental compile needs - */ - def compilerBridge: T[PathRef] = T{ - val compilerBridgeKey = "MILL_COMPILER_BRIDGE_" + scalaVersion().replace('.', '_') - val compilerBridgePath = sys.props(compilerBridgeKey) - if (compilerBridgePath != null) PathRef(Path(compilerBridgePath), quick = true) - else { - val dep = compilerBridgeIvyDep(scalaVersion()) - val classpath = resolveDependencies( - repositories, - scalaVersion(), - scalaBinaryVersion(), - Seq(dep) - ) - classpath match { - case Result.Success(resolved) => - resolved.filter(_.path.ext != "pom").toSeq match { - case Seq(single) => PathRef(single.path, quick = true) - case Seq() => throw new Exception(dep + " resolution failed") // TODO: find out, is it possible? - case _ => throw new Exception(dep + " resolution resulted in more than one file") - } - case f: Result.Failure => throw new Exception(dep + s" resolution failed.\n + ${f.msg}") // TODO: remove, resolveDependencies will take care of this. - } - } + def compilerBridgeSources = T{ + resolveDependencies( + repositories, + scalaVersion(), + Seq(ivy"org.scala-sbt::compiler-bridge:1.1.0"), + sources = true + ) } def scalacPluginClasspath: T[Agg[PathRef]] = @@ -153,10 +135,10 @@ trait ScalaModule extends mill.Module with TaskModule { outer => mill.scalalib.ScalaWorkerApi.scalaWorker().compileScala( scalaVersion(), allSources().map(_.path), + compilerBridgeSources().map(_.path), compileDepClasspath().map(_.path), scalaCompilerClasspath().map(_.path), scalacPluginClasspath().map(_.path), - compilerBridge().path, scalacOptions(), scalacPluginClasspath().map(_.path), javacOptions(), @@ -270,7 +252,7 @@ trait ScalaModule extends mill.Module with TaskModule { outer => def artifactName: T[String] = basePath.last.toString def artifactScalaVersion: T[String] = T { if (crossFullScalaVersion()) scalaVersion() - else scalaBinaryVersion() + else Lib.scalaBinaryVersion(scalaVersion()) } def artifactId: T[String] = T { s"${artifactName()}_${artifactScalaVersion()}" } diff --git a/scalalib/src/mill/scalalib/ScalaWorkerApi.scala b/scalalib/src/mill/scalalib/ScalaWorkerApi.scala index 7db48a41..4f9c527c 100644 --- a/scalalib/src/mill/scalalib/ScalaWorkerApi.scala +++ b/scalalib/src/mill/scalalib/ScalaWorkerApi.scala @@ -1,7 +1,5 @@ package mill.scalalib -import java.lang.reflect.{InvocationHandler, Method} -import java.net.URI import ammonite.ops.Path import coursier.Cache @@ -9,8 +7,7 @@ import coursier.maven.MavenRepository import mill.Agg import mill.scalalib.TestRunner.Result import mill.T -import mill.define.{Task, Worker} -import mill.eval.PathRef +import mill.define.Worker import mill.scalalib.Lib.resolveDependencies import mill.util.Loose import mill.util.JsonFormatters._ @@ -22,7 +19,6 @@ object ScalaWorkerApi extends mill.define.ExternalModule { val mill.eval.Result.Success(v) = resolveDependencies( Seq(Cache.ivy2Local, MavenRepository("https://repo1.maven.org/maven2")), "2.12.4", - "2.12", Seq(ivy"com.lihaoyi::mill-scalaworker:0.0.1-SNAPSHOT") ) v.map(_.path) @@ -34,18 +30,27 @@ object ScalaWorkerApi extends mill.define.ExternalModule { getClass.getClassLoader ) val cls = cl.loadClass("mill.scalaworker.ScalaWorker") - val instance = cls.getConstructor(classOf[mill.util.Ctx]).newInstance(T.ctx()) + val instance = cls.getConstructor(classOf[mill.util.Ctx], classOf[Array[String]]) + .newInstance(T.ctx(), compilerInterfaceClasspath().map(_.path.toString).toArray[String]) instance.asInstanceOf[ScalaWorkerApi] } + + def compilerInterfaceClasspath = T{ + resolveDependencies( + Seq(Cache.ivy2Local, MavenRepository("https://repo1.maven.org/maven2")), + "2.12.4", + Seq(ivy"org.scala-sbt:compiler-interface:1.1.0") + ) + } } trait ScalaWorkerApi { def compileScala(scalaVersion: String, sources: Agg[Path], + compileBridgeSources: Agg[Path], compileClasspath: Agg[Path], compilerClasspath: Agg[Path], pluginClasspath: Agg[Path], - compilerBridge: Path, scalacOptions: Seq[String], scalacPluginClasspath: Agg[Path], javacOptions: Seq[String], -- cgit v1.2.3