summaryrefslogtreecommitdiff
path: root/scalaplugin/src/main
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-12-13 23:28:15 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2017-12-13 23:28:15 -0800
commita97697a3c7294eb6dda30740fc6cdd92a9966ccd (patch)
treec34dc6c2587c69dd496682c003036b8b65028119 /scalaplugin/src/main
parente83989f4e15fc80820794a0f4e2db806f117a1a9 (diff)
downloadmill-a97697a3c7294eb6dda30740fc6cdd92a9966ccd.tar.gz
mill-a97697a3c7294eb6dda30740fc6cdd92a9966ccd.tar.bz2
mill-a97697a3c7294eb6dda30740fc6cdd92a9966ccd.zip
First pass at implementing long-lived `Worker` objects. These currently are managed by the `Evaluator`, which is now a stateful object that shouldn't be thrown away every time.
We still need to update the code/test-suite to make the `Evaluator` hang around in between `evaluate` calls
Diffstat (limited to 'scalaplugin/src/main')
-rw-r--r--scalaplugin/src/main/scala/mill/scalaplugin/Lib.scala28
1 files changed, 17 insertions, 11 deletions
diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/Lib.scala b/scalaplugin/src/main/scala/mill/scalaplugin/Lib.scala
index 5c9aa4f7..637906a5 100644
--- a/scalaplugin/src/main/scala/mill/scalaplugin/Lib.scala
+++ b/scalaplugin/src/main/scala/mill/scalaplugin/Lib.scala
@@ -7,6 +7,7 @@ import java.util.Optional
import ammonite.ops._
import coursier.{Cache, Fetch, MavenRepository, Repository, Resolution}
+import mill.define.Worker
import mill.eval.{PathRef, Result}
import mill.util.Ctx
import sbt.internal.inc._
@@ -21,6 +22,12 @@ object CompilationResult {
// analysisFile is represented by Path, so we won't break caches after file changes
case class CompilationResult(analysisFile: Path, classes: PathRef)
+object ZincWorker extends Worker[ZincWorker]{
+ def make() = new ZincWorker
+}
+class ZincWorker{
+ var scalaInstanceCache = Option.empty[(Long, ScalaInstance)]
+}
object Lib{
case class MockedLookup(am: File => Optional[CompileAnalysis]) extends PerClasspathEntryLookup {
override def analysis(classpathEntry: File): Optional[CompileAnalysis] =
@@ -30,9 +37,15 @@ object Lib{
Locate.definesClass(classpathEntry)
}
- var scalaInstanceCache = Option.empty[(Long, ScalaInstance)]
+ def grepJar(classPath: Seq[Path], s: String) = {
+ classPath
+ .find(_.toString.endsWith(s))
+ .getOrElse(throw new Exception("Cannot find " + s))
+ .toIO
+ }
- def compileScala(scalaVersion: String,
+ def compileScala(zincWorker: ZincWorker,
+ scalaVersion: String,
sources: Seq[Path],
compileClasspath: Seq[Path],
compilerClasspath: Seq[Path],
@@ -44,18 +57,11 @@ object Lib{
(implicit ctx: Ctx): CompilationResult = {
val compileClasspathFiles = compileClasspath.map(_.toIO).toArray
- def grepJar(classPath: Seq[Path], s: String) = {
- classPath
- .find(_.toString.endsWith(s))
- .getOrElse(throw new Exception("Cannot find " + s))
- .toIO
- }
-
val compilerJars = compilerClasspath.toArray.map(_.toIO)
val classloaderSig = compilerClasspath.map(p => p.toString().hashCode + p.mtime.toMillis).sum
- val scalaInstance = scalaInstanceCache match{
+ val scalaInstance = zincWorker.scalaInstanceCache match{
case Some((k, v)) if k == classloaderSig => v
case _ =>
val scalaInstance = new ScalaInstance(
@@ -66,7 +72,7 @@ object Lib{
allJars = compilerJars,
explicitActual = None
)
- scalaInstanceCache = Some((classloaderSig, scalaInstance))
+ zincWorker.scalaInstanceCache = Some((classloaderSig, scalaInstance))
scalaInstance
}