diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-12-18 21:11:47 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-18 21:11:47 -0800 |
commit | de175e69977082e35539097a54d381e465dddf8e (patch) | |
tree | cedf8de1dde57b7c9f70dfaa4b212906db775684 /scalalib/src/ZincWorkerModule.scala | |
parent | ea36ea3da18d3720e124b60235e1153f6c31518c (diff) | |
download | mill-de175e69977082e35539097a54d381e465dddf8e.tar.gz mill-de175e69977082e35539097a54d381e465dddf8e.tar.bz2 mill-de175e69977082e35539097a54d381e465dddf8e.zip |
Generalize Zinc Worker (#514)
* Generalize Zinc worker
- Compiler bridges can now be either pre-compiled or on-demand-compiled
- Scala library/compiler jar discovery is now configurable
- Zinc compiler cache is now configurable, rather than being hardcoded at n=1
* .
* update constructor args
* remove duplicate util/AggWrapper.scala file
* fix
* fix
* fix
* cleanup
Diffstat (limited to 'scalalib/src/ZincWorkerModule.scala')
-rw-r--r-- | scalalib/src/ZincWorkerModule.scala | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/scalalib/src/ZincWorkerModule.scala b/scalalib/src/ZincWorkerModule.scala index 5ca824ce..97d84aaf 100644 --- a/scalalib/src/ZincWorkerModule.scala +++ b/scalalib/src/ZincWorkerModule.scala @@ -4,9 +4,12 @@ import coursier.Cache import coursier.maven.MavenRepository import mill.Agg import mill.T +import mill.api.KeyedLockedCache import mill.define.{Discover, Worker} import mill.scalalib.Lib.resolveDependencies -import mill.util.Loose +import mill.scalalib.api.Util.isDotty +import mill.scalalib.api.ZincWorkerApi +import mill.api.Loose import mill.util.JsonFormatters._ object ZincWorkerModule extends mill.define.ExternalModule with ZincWorkerModule{ @@ -40,11 +43,61 @@ trait ZincWorkerModule extends mill.Module{ getClass.getClassLoader ) val cls = cl.loadClass("mill.scalalib.worker.ZincWorkerImpl") - val instance = cls.getConstructor(classOf[mill.api.Ctx], classOf[Array[String]]) - .newInstance(T.ctx(), compilerInterfaceClasspath().map(_.path.toString).toArray[String]) + val instance = cls.getConstructor( + classOf[ + Either[ + (ZincWorkerApi.Ctx, Array[os.Path], (String, String) => os.Path), + String => os.Path + ] + ], + classOf[(Agg[os.Path], String) => os.Path], + classOf[(Agg[os.Path], String) => os.Path], + classOf[KeyedLockedCache[_]] + ) + .newInstance( + Left(( + T.ctx(), + compilerInterfaceClasspath().map(_.path).toArray, + (x: String, y: String) => scalaCompilerBridgeSourceJar(x, y).asSuccess.get.value + )), + mill.scalalib.api.Util.grepJar(_, "scala-library", _, sources = false), + mill.scalalib.api.Util.grepJar(_, "scala-compiler", _, sources = false), + new KeyedLockedCache.RandomBoundedCache(1, 1) + ) instance.asInstanceOf[mill.scalalib.api.ZincWorkerApi] } + private val Milestone213 = raw"""2.13.(\d+)-M(\d+)""".r + def scalaCompilerBridgeSourceJar(scalaVersion: String, + scalaOrganization: String) = { + val (scalaVersion0, scalaBinaryVersion0) = scalaVersion match { + case Milestone213(_, _) => ("2.13.0-M2", "2.13.0-M2") + case _ => (scalaVersion, mill.scalalib.api.Util.scalaBinaryVersion(scalaVersion)) + } + + val (bridgeDep, bridgeName, bridgeVersion) = + if (isDotty(scalaVersion0)) { + val org = scalaOrganization + val name = "dotty-sbt-bridge" + val version = scalaVersion + (ivy"$org:$name:$version", name, version) + } else { + val org = "org.scala-sbt" + val name = "compiler-bridge" + val version = Versions.zinc + (ivy"$org::$name:$version", s"${name}_$scalaBinaryVersion0", version) + } + + resolveDependencies( + repositories, + Lib.depToDependency(_, scalaVersion0, ""), + Seq(bridgeDep), + sources = true + ).map(deps => + mill.scalalib.api.Util.grepJar(deps.map(_.path), bridgeName, bridgeVersion, sources = true) + ) + } + def compilerInterfaceClasspath = T{ resolveDependencies( repositories, |