summaryrefslogtreecommitdiff
path: root/scalalib
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-12-18 21:11:47 -0800
committerGitHub <noreply@github.com>2018-12-18 21:11:47 -0800
commitde175e69977082e35539097a54d381e465dddf8e (patch)
treecedf8de1dde57b7c9f70dfaa4b212906db775684 /scalalib
parentea36ea3da18d3720e124b60235e1153f6c31518c (diff)
downloadmill-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')
-rw-r--r--scalalib/api/src/ZincWorkerApi.scala16
-rw-r--r--scalalib/src/GenIdeaImpl.scala4
-rw-r--r--scalalib/src/JavaModule.scala2
-rw-r--r--scalalib/src/MiscModule.scala2
-rw-r--r--scalalib/src/ScalaModule.scala35
-rw-r--r--scalalib/src/ZincWorkerModule.scala59
-rw-r--r--scalalib/src/dependency/versions/VersionsFinder.scala2
-rw-r--r--scalalib/src/publish/Ivy.scala2
-rw-r--r--scalalib/src/publish/Pom.scala2
-rw-r--r--scalalib/test/src/ResolveDepsTests.scala2
-rw-r--r--scalalib/worker/src/ZincWorkerImpl.scala199
11 files changed, 177 insertions, 148 deletions
diff --git a/scalalib/api/src/ZincWorkerApi.scala b/scalalib/api/src/ZincWorkerApi.scala
index c5230ec5..d42be9f3 100644
--- a/scalalib/api/src/ZincWorkerApi.scala
+++ b/scalalib/api/src/ZincWorkerApi.scala
@@ -3,14 +3,16 @@ package mill.scalalib.api
import mill.api.Loose.Agg
import mill.api.PathRef
import mill.api.JsonFormatters._
-
+object ZincWorkerApi{
+ type Ctx = mill.api.Ctx.Dest with mill.api.Ctx.Log with mill.api.Ctx.Home
+}
trait ZincWorkerApi {
/** Compile a Java-only project */
def compileJava(upstreamCompileOutput: Seq[CompilationResult],
sources: Agg[os.Path],
compileClasspath: Agg[os.Path],
javacOptions: Seq[String])
- (implicit ctx: mill.api.Ctx): mill.api.Result[CompilationResult]
+ (implicit ctx: ZincWorkerApi.Ctx): mill.api.Result[CompilationResult]
/** Compile a mixed Scala/Java or Scala-only project */
def compileMixed(upstreamCompileOutput: Seq[CompilationResult],
@@ -18,21 +20,21 @@ trait ZincWorkerApi {
compileClasspath: Agg[os.Path],
javacOptions: Seq[String],
scalaVersion: String,
+ scalaOrganization: String,
scalacOptions: Seq[String],
- compilerBridgeSources: os.Path,
compilerClasspath: Agg[os.Path],
scalacPluginClasspath: Agg[os.Path])
- (implicit ctx: mill.api.Ctx): mill.api.Result[CompilationResult]
+ (implicit ctx: ZincWorkerApi.Ctx): mill.api.Result[CompilationResult]
def discoverMainClasses(compilationResult: CompilationResult)
- (implicit ctx: mill.api.Ctx): Seq[String]
+ (implicit ctx: ZincWorkerApi.Ctx): Seq[String]
def docJar(scalaVersion: String,
- compilerBridgeSources: os.Path,
+ scalaOrganization: String,
compilerClasspath: Agg[os.Path],
scalacPluginClasspath: Agg[os.Path],
args: Seq[String])
- (implicit ctx: mill.api.Ctx): Boolean
+ (implicit ctx: ZincWorkerApi.Ctx): Boolean
}
diff --git a/scalalib/src/GenIdeaImpl.scala b/scalalib/src/GenIdeaImpl.scala
index 548b8d4e..b8f9d35e 100644
--- a/scalalib/src/GenIdeaImpl.scala
+++ b/scalalib/src/GenIdeaImpl.scala
@@ -5,8 +5,8 @@ import coursier.{Cache, CoursierPaths, Repository}
import mill.define._
import mill.eval.{Evaluator, PathRef, Result}
import mill.api.Ctx.{Home, Log}
-import mill.util.Strict.Agg
-import mill.util.{Loose, Strict}
+import mill.api.Strict.Agg
+import mill.api.{Loose, Strict}
import mill.{T, scalalib}
import scala.util.Try
diff --git a/scalalib/src/JavaModule.scala b/scalalib/src/JavaModule.scala
index 78be8893..72c0a5a6 100644
--- a/scalalib/src/JavaModule.scala
+++ b/scalalib/src/JavaModule.scala
@@ -9,7 +9,7 @@ import mill.modules.{Assembly, Jvm}
import mill.modules.Jvm.{createAssembly, createJar}
import Lib._
import mill.scalalib.publish.{Artifact, Scope}
-import mill.util.Loose.Agg
+import mill.api.Loose.Agg
/**
* Core configuration required to compile a single Scala compilation target
diff --git a/scalalib/src/MiscModule.scala b/scalalib/src/MiscModule.scala
index c6449d6e..bf64f1f3 100644
--- a/scalalib/src/MiscModule.scala
+++ b/scalalib/src/MiscModule.scala
@@ -4,7 +4,7 @@ package scalalib
import mill.define.Cross.Resolver
import mill.define.{Cross, Task}
import mill.eval.{PathRef, Result}
-import mill.util.Loose.Agg
+import mill.api.Loose.Agg
object CrossModuleBase{
def scalaVersionPaths(scalaVersion: String, f: String => os.Path) = {
for(segments <- scalaVersion.split('.').inits.filter(_.nonEmpty))
diff --git a/scalalib/src/ScalaModule.scala b/scalalib/src/ScalaModule.scala
index 9d669bf4..5fad1664 100644
--- a/scalalib/src/ScalaModule.scala
+++ b/scalalib/src/ScalaModule.scala
@@ -8,7 +8,7 @@ import mill.modules.Jvm
import mill.modules.Jvm.createJar
import mill.scalalib.api.Util.isDotty
import Lib._
-import mill.util.Loose.Agg
+import mill.api.Loose.Agg
import mill.api.DummyInputStream
/**
@@ -79,36 +79,7 @@ trait ScalaModule extends JavaModule { outer =>
def scalaDocOptions = T{ scalacOptions() }
- 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(), 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, platformSuffix()),
- Seq(bridgeDep),
- sources = true
- ).map(deps =>
- mill.scalalib.api.Util.grepJar(deps.map(_.path), bridgeName, bridgeVersion, sources = true)
- )
- }
/**
* The local classpath of Scala compiler plugins on-disk; you can add
@@ -159,8 +130,8 @@ trait ScalaModule extends JavaModule { outer =>
compileClasspath().map(_.path),
javacOptions(),
scalaVersion(),
+ scalaOrganization(),
scalacOptions(),
- scalaCompilerBridgeSources(),
scalaCompilerClasspath().map(_.path),
scalacPluginClasspath().map(_.path),
)
@@ -187,7 +158,7 @@ trait ScalaModule extends JavaModule { outer =>
else {
zincWorker.worker().docJar(
scalaVersion(),
- scalaCompilerBridgeSources(),
+ scalaOrganization(),
scalaCompilerClasspath().map(_.path),
scalacPluginClasspath().map(_.path),
files ++ options
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,
diff --git a/scalalib/src/dependency/versions/VersionsFinder.scala b/scalalib/src/dependency/versions/VersionsFinder.scala
index a831ffc3..a9ecc763 100644
--- a/scalalib/src/dependency/versions/VersionsFinder.scala
+++ b/scalalib/src/dependency/versions/VersionsFinder.scala
@@ -5,7 +5,7 @@ import mill.eval.Evaluator
import mill.scalalib.dependency.metadata.MetadataLoaderFactory
import mill.scalalib.{Dep, JavaModule, Lib}
import mill.api.Ctx.{Home, Log}
-import mill.util.{Loose, Strict}
+import mill.api.{Loose, Strict}
private[dependency] object VersionsFinder {
diff --git a/scalalib/src/publish/Ivy.scala b/scalalib/src/publish/Ivy.scala
index 22e26ff6..e06efadd 100644
--- a/scalalib/src/publish/Ivy.scala
+++ b/scalalib/src/publish/Ivy.scala
@@ -1,6 +1,6 @@
package mill.scalalib.publish
-import mill.util.Loose.Agg
+import mill.api.Loose.Agg
import scala.xml.PrettyPrinter
diff --git a/scalalib/src/publish/Pom.scala b/scalalib/src/publish/Pom.scala
index 57a0e196..a7f1f6fc 100644
--- a/scalalib/src/publish/Pom.scala
+++ b/scalalib/src/publish/Pom.scala
@@ -1,6 +1,6 @@
package mill.scalalib.publish
-import mill.util.Loose.Agg
+import mill.api.Loose.Agg
import scala.xml.{Atom, Elem, NodeSeq, PrettyPrinter}
diff --git a/scalalib/test/src/ResolveDepsTests.scala b/scalalib/test/src/ResolveDepsTests.scala
index 78361625..ce905907 100644
--- a/scalalib/test/src/ResolveDepsTests.scala
+++ b/scalalib/test/src/ResolveDepsTests.scala
@@ -4,7 +4,7 @@ import coursier.Cache
import coursier.maven.MavenRepository
import mill.api.Result.{Failure, Success}
import mill.eval.{PathRef, Result}
-import mill.util.Loose.Agg
+import mill.api.Loose.Agg
import utest._
object ResolveDepsTests extends TestSuite {
diff --git a/scalalib/worker/src/ZincWorkerImpl.scala b/scalalib/worker/src/ZincWorkerImpl.scala
index 705d4682..c37ef162 100644
--- a/scalalib/worker/src/ZincWorkerImpl.scala
+++ b/scalalib/worker/src/ZincWorkerImpl.scala
@@ -4,13 +4,13 @@ import java.io.File
import java.util.Optional
import mill.api.Loose.Agg
-import mill.api.PathRef
+import mill.api.{KeyedLockedCache, PathRef}
import xsbti.compile.{CompilerCache => _, FileAnalysisStore => _, ScalaInstance => _, _}
-import mill.scalalib.api.Util.{isDotty, grepJar, scalaBinaryVersion}
+import mill.scalalib.api.Util.{grepJar, isDotty, scalaBinaryVersion}
import sbt.internal.inc._
import sbt.internal.util.{ConsoleOut, MainAppender}
import sbt.util.LogExchange
-import mill.scalalib.api.CompilationResult
+import mill.scalalib.api.{CompilationResult, ZincWorkerApi}
case class MockedLookup(am: File => Optional[CompileAnalysis]) extends PerClasspathEntryLookup {
override def analysis(classpathEntry: File): Optional[CompileAnalysis] =
am(classpathEntry)
@@ -19,10 +19,16 @@ case class MockedLookup(am: File => Optional[CompileAnalysis]) extends PerClassp
Locate.definesClass(classpathEntry)
}
-class ZincWorkerImpl(ctx0: mill.api.Ctx,
- compilerBridgeClasspath: Array[String]) extends mill.scalalib.api.ZincWorkerApi{
+class ZincWorkerImpl(compilerBridge: Either[
+ (ZincWorkerApi.Ctx, Array[os.Path], (String, String) => os.Path),
+ String => os.Path
+ ],
+ libraryJarNameGrep: (Agg[os.Path], String) => os.Path,
+ compilerJarNameGrep: (Agg[os.Path], String) => os.Path,
+ compilerCache: KeyedLockedCache[Compilers])
+ extends ZincWorkerApi{
private val ic = new sbt.internal.inc.IncrementalCompilerImpl()
- val javaOnlyCompilers = {
+ lazy val javaOnlyCompilers = {
// Keep the classpath as written by the user
val classpathOptions = ClasspathOptions.of(false, false, false, false, false)
@@ -42,68 +48,68 @@ class ZincWorkerImpl(ctx0: mill.api.Ctx,
)
}
- @volatile var mixedCompilersCache = Option.empty[(Long, Compilers)]
-
def docJar(scalaVersion: String,
- compilerBridgeSources: os.Path,
+ scalaOrganization: String,
compilerClasspath: Agg[os.Path],
scalacPluginClasspath: Agg[os.Path],
args: Seq[String])
- (implicit ctx: mill.api.Ctx): Boolean = {
- val compilers: Compilers = prepareCompilers(
+ (implicit ctx: ZincWorkerApi.Ctx): Boolean = {
+ withCompilers(
scalaVersion,
- compilerBridgeSources,
+ scalaOrganization,
compilerClasspath,
- scalacPluginClasspath
- )
- val scaladocClass = compilers.scalac().scalaInstance().loader().loadClass("scala.tools.nsc.ScalaDoc")
- val scaladocMethod = scaladocClass.getMethod("process", classOf[Array[String]])
- scaladocMethod.invoke(scaladocClass.newInstance(), args.toArray).asInstanceOf[Boolean]
+ scalacPluginClasspath,
+ ) { compilers: Compilers =>
+ val scaladocClass = compilers.scalac().scalaInstance().loader().loadClass("scala.tools.nsc.ScalaDoc")
+ val scaladocMethod = scaladocClass.getMethod("process", classOf[Array[String]])
+ scaladocMethod.invoke(scaladocClass.newInstance(), args.toArray).asInstanceOf[Boolean]
+ }
}
/** Compile the bridge if it doesn't exist yet and return the output directory.
- * TODO: Proper invalidation, see #389
- */
- def compileZincBridgeIfNeeded(scalaVersion: String,
- sourcesJar: os.Path,
- compilerJars: Array[File]): os.Path = {
- val workingDir = ctx0.dest / scalaVersion
- val compiledDest = workingDir / 'compiled
- if (!os.exists(workingDir)) {
-
- ctx0.log.info("Compiling compiler interface...")
-
- os.makeDir.all(workingDir)
- os.makeDir.all(compiledDest)
-
- val sourceFolder = mill.api.IO.unpackZip(sourcesJar)(workingDir)
- val classloader = mill.api.ClassLoader.create(compilerJars.map(_.toURI.toURL), null)(ctx0)
- val compilerMain = classloader.loadClass(
- if (isDotty(scalaVersion))
- "dotty.tools.dotc.Main"
- else
- "scala.tools.nsc.Main"
- )
- val argsArray = Array[String](
- "-d", compiledDest.toString,
- "-classpath", (compilerJars ++ compilerBridgeClasspath).mkString(File.pathSeparator)
- ) ++ os.walk(sourceFolder.path).filter(_.ext == "scala").map(_.toString)
-
- compilerMain.getMethod("process", classOf[Array[String]])
- .invoke(null, argsArray)
+ * TODO: Proper invalidation, see #389
+ */
+ def compileZincBridgeIfNeeded(scalaVersion: String, scalaOrganization: String, compilerJars: Array[File]): os.Path = {
+ compilerBridge match{
+ case Right(compiled) => compiled(scalaVersion)
+ case Left((ctx0, compilerBridgeClasspath, srcJars)) =>
+ val workingDir = ctx0.dest / scalaVersion
+ val compiledDest = workingDir / 'compiled
+ if (!os.exists(workingDir)) {
+ ctx0.log.info("Compiling compiler interface...")
+
+ os.makeDir.all(workingDir)
+ os.makeDir.all(compiledDest)
+
+ val sourceFolder = mill.api.IO.unpackZip(srcJars(scalaVersion, scalaOrganization))(workingDir)
+ val classloader = mill.api.ClassLoader.create(compilerJars.map(_.toURI.toURL), null)(ctx0)
+ val compilerMain = classloader.loadClass(
+ if (isDotty(scalaVersion)) "dotty.tools.dotc.Main"
+ else "scala.tools.nsc.Main"
+ )
+ val argsArray = Array[String](
+ "-d", compiledDest.toString,
+ "-classpath", (compilerJars ++ compilerBridgeClasspath).mkString(File.pathSeparator)
+ ) ++ os.walk(sourceFolder.path).filter(_.ext == "scala").map(_.toString)
+
+ compilerMain.getMethod("process", classOf[Array[String]])
+ .invoke(null, argsArray)
+ }
+ compiledDest
}
- compiledDest
+
}
- def discoverMainClasses(compilationResult: CompilationResult)(implicit ctx: mill.api.Ctx): Seq[String] = {
+ def discoverMainClasses(compilationResult: CompilationResult)
+ (implicit ctx: ZincWorkerApi.Ctx): Seq[String] = {
def toScala[A](o: Optional[A]): Option[A] = if (o.isPresent) Some(o.get) else None
toScala(FileAnalysisStore.binary(compilationResult.analysisFile.toIO).get())
.map(_.getAnalysis)
.flatMap{
case analysis: Analysis =>
- Some(analysis.infos.allInfos.values.map(_.getMainClasses).flatten.toSeq.sorted)
+ Some(analysis.infos.allInfos.values.flatMap(_.getMainClasses).toSeq.sorted)
case _ =>
None
}
@@ -114,7 +120,7 @@ class ZincWorkerImpl(ctx0: mill.api.Ctx,
sources: Agg[os.Path],
compileClasspath: Agg[os.Path],
javacOptions: Seq[String])
- (implicit ctx: mill.api.Ctx): mill.api.Result[CompilationResult] = {
+ (implicit ctx: ZincWorkerApi.Ctx): mill.api.Result[CompilationResult] = {
compileInternal(
upstreamCompileOutput,
sources,
@@ -130,73 +136,70 @@ class ZincWorkerImpl(ctx0: mill.api.Ctx,
compileClasspath: Agg[os.Path],
javacOptions: Seq[String],
scalaVersion: String,
+ scalaOrganization: String,
scalacOptions: Seq[String],
- compilerBridgeSources: os.Path,
compilerClasspath: Agg[os.Path],
scalacPluginClasspath: Agg[os.Path])
- (implicit ctx: mill.api.Ctx): mill.api.Result[CompilationResult] = {
- val compilers: Compilers = prepareCompilers(
+ (implicit ctx: ZincWorkerApi.Ctx): mill.api.Result[CompilationResult] = {
+ withCompilers(
scalaVersion,
- compilerBridgeSources,
+ scalaOrganization,
compilerClasspath,
- scalacPluginClasspath
- )
-
- compileInternal(
- upstreamCompileOutput,
- sources,
- compileClasspath,
- javacOptions,
- scalacOptions = scalacPluginClasspath.map(jar => s"-Xplugin:${jar}").toSeq ++ scalacOptions,
- compilers
- )
+ scalacPluginClasspath,
+ ) {compilers: Compilers =>
+ compileInternal(
+ upstreamCompileOutput,
+ sources,
+ compileClasspath,
+ javacOptions,
+ scalacOptions = scalacPluginClasspath.map(jar => s"-Xplugin:$jar").toSeq ++ scalacOptions,
+ compilers
+ )
+ }
}
- private def prepareCompilers(scalaVersion: String,
- compilerBridgeSources: os.Path,
+ private def withCompilers[T](scalaVersion: String,
+ scalaOrganization: String,
compilerClasspath: Agg[os.Path],
scalacPluginClasspath: Agg[os.Path])
- (implicit ctx: mill.api.Ctx)= {
+ (f: Compilers => T)
+ (implicit ctx: ZincWorkerApi.Ctx)= {
val combinedCompilerClasspath = compilerClasspath ++ scalacPluginClasspath
val combinedCompilerJars = combinedCompilerClasspath.toArray.map(_.toIO)
- val compilerBridge = compileZincBridgeIfNeeded(
+ val compiledCompilerBridge = compileZincBridgeIfNeeded(
scalaVersion,
- compilerBridgeSources,
+ scalaOrganization,
compilerClasspath.toArray.map(_.toIO)
)
- val compilerBridgeSig = os.mtime(compilerBridge)
+
+ val compilerBridgeSig = os.mtime(compiledCompilerBridge)
val compilersSig =
compilerBridgeSig +
combinedCompilerClasspath.map(p => p.toString().hashCode + os.mtime(p)).sum
- val compilers = mixedCompilersCache match {
- case Some((k, v)) if k == compilersSig => v
- case _ =>
- val compilerName =
- if (isDotty(scalaVersion))
- s"dotty-compiler_${scalaBinaryVersion(scalaVersion)}"
- else
- "scala-compiler"
- val scalaInstance = new ScalaInstance(
- version = scalaVersion,
- loader = mill.api.ClassLoader.create(combinedCompilerJars.map(_.toURI.toURL), null),
- libraryJar = grepJar(compilerClasspath, "scala-library", scalaVersion).toIO,
- compilerJar = grepJar(compilerClasspath, compilerName, scalaVersion).toIO,
- allJars = combinedCompilerJars,
- explicitActual = None
- )
- val compilers = ic.compilers(
- scalaInstance,
- ClasspathOptionsUtil.boot,
- None,
- ZincUtil.scalaCompiler(scalaInstance, compilerBridge.toIO)
- )
- mixedCompilersCache = Some((compilersSig, compilers))
- compilers
- }
- compilers
+ compilerCache.withCachedValue(compilersSig){
+ val compilerJar =
+ if (isDotty(scalaVersion))
+ grepJar(compilerClasspath, s"dotty-compiler_${scalaBinaryVersion(scalaVersion)}", scalaVersion)
+ else
+ compilerJarNameGrep(compilerClasspath, scalaVersion)
+ val scalaInstance = new ScalaInstance(
+ version = scalaVersion,
+ loader = mill.api.ClassLoader.create(combinedCompilerJars.map(_.toURI.toURL), null),
+ libraryJar = libraryJarNameGrep(compilerClasspath, scalaVersion).toIO,
+ compilerJar = compilerJar.toIO,
+ allJars = combinedCompilerJars,
+ explicitActual = None
+ )
+ ic.compilers(
+ scalaInstance,
+ ClasspathOptionsUtil.boot,
+ None,
+ ZincUtil.scalaCompiler(scalaInstance, compiledCompilerBridge.toIO)
+ )
+ }(f)
}
private def compileInternal(upstreamCompileOutput: Seq[CompilationResult],
@@ -205,7 +208,7 @@ class ZincWorkerImpl(ctx0: mill.api.Ctx,
javacOptions: Seq[String],
scalacOptions: Seq[String],
compilers: Compilers)
- (implicit ctx: mill.api.Ctx): mill.api.Result[CompilationResult] = {
+ (implicit ctx: ZincWorkerApi.Ctx): mill.api.Result[CompilationResult] = {
os.makeDir.all(ctx.dest)
val logger = {