diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-12-13 09:46:40 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-12-13 09:46:40 -0800 |
commit | 056ccd28b64434974bf3a06cf32f0dd8b7954d70 (patch) | |
tree | a3793bbfaada12934e379ea511a908f3c6bdc69b | |
parent | 7fc589857d7943668ac045997cc5eb128d2e24d1 (diff) | |
download | mill-056ccd28b64434974bf3a06cf32f0dd8b7954d70.tar.gz mill-056ccd28b64434974bf3a06cf32f0dd8b7954d70.tar.bz2 mill-056ccd28b64434974bf3a06cf32f0dd8b7954d70.zip |
Allow `classPathSig` to be injected into `Evaluator`, and in `ReplApplyHandler` keep using the same one every time to avoid busting caches due to REPL commands being added to the classpath
Reverts https://github.com/lihaoyi/mill/pull/60, which seems to break `mill.scalaplugin.AcyclicTests.scala2123` (reproducible in master)
Tweak `build.sbt` to properly set the forked test working directory in `test-only` as well as `test`
-rw-r--r-- | build.sbt | 4 | ||||
-rw-r--r-- | core/src/main/scala/mill/eval/Evaluator.scala | 22 | ||||
-rw-r--r-- | core/src/main/scala/mill/main/ReplApplyHandler.scala | 10 |
3 files changed, 20 insertions, 16 deletions
@@ -100,8 +100,8 @@ lazy val scalaplugin = project sharedSettings, name := "mill-scalaplugin", fork in Test := true, - baseDirectory in (Test, test) := (baseDirectory in (Test, test)).value / "..", - javaOptions in (Test, test) := bridgeProps.value.toSeq + baseDirectory in Test := (baseDirectory in Test).value / "..", + javaOptions in Test := bridgeProps.value.toSeq ) lazy val bin = project .dependsOn(scalaplugin) diff --git a/core/src/main/scala/mill/eval/Evaluator.scala b/core/src/main/scala/mill/eval/Evaluator.scala index 19fbb637..e1d0428a 100644 --- a/core/src/main/scala/mill/eval/Evaluator.scala +++ b/core/src/main/scala/mill/eval/Evaluator.scala @@ -16,7 +16,8 @@ import scala.collection.mutable class Evaluator(workspacePath: Path, labeling: Map[Target[_], LabelledTarget[_]], log: Logger, - sel: List[Mirror.Segment] = List()){ + sel: List[Mirror.Segment] = List(), + classLoaderSig: Seq[(Path, Long)] = Evaluator.classLoaderSig){ def evaluate(goals: OSet[Task[_]]): Evaluator.Results = { mkdir(workspacePath) @@ -71,15 +72,6 @@ class Evaluator(workspacePath: Path, val externalInputs = group.items.flatMap(_.inputs).filter(!group.contains(_)) - // check if the build itself has changed - val classLoaderSig = group.toVector.map(_.getClass.getClassLoader).map { cl => - signatureCache.getOrElseUpdate(cl, cl match { - case scl: SpecialClassLoader => scl.classpathSignature - case ucl: URLClassLoader => SpecialClassLoader.initialClasspathSignature(ucl) - case _ => Nil - }) - } - val inputsHash = externalInputs.map(results).toVector.hashCode + group.toIterator.map(_.sideHash).toVector.hashCode() + @@ -125,9 +117,7 @@ class Evaluator(workspacePath: Path, .write(v) write.over(metadataPath, upickle.default.write(inputsHash -> terminalResult, indent = 4)) - case Result.Skipped => - // Do nothing - case _: Result.Failing => + case _ => // Wipe out any cached metadata.mill.json file that exists, so // a following run won't look at the cached metadata file and // assume it's associated with the possibly-borked state of the @@ -229,7 +219,13 @@ class Evaluator(workspacePath: Path, object Evaluator{ + // check if the build itself has changed + def classLoaderSig = Thread.currentThread().getContextClassLoader match { + case scl: SpecialClassLoader => scl.classpathSignature + case ucl: URLClassLoader => SpecialClassLoader.initialClasspathSignature(ucl) + case _ => Nil + } case class Results(rawValues: Seq[Result[Any]], evaluated: OSet[Task[_]], transitive: OSet[Task[_]], diff --git a/core/src/main/scala/mill/main/ReplApplyHandler.scala b/core/src/main/scala/mill/main/ReplApplyHandler.scala index fe8c13b6..2e8d2da7 100644 --- a/core/src/main/scala/mill/main/ReplApplyHandler.scala +++ b/core/src/main/scala/mill/main/ReplApplyHandler.scala @@ -9,12 +9,20 @@ import mill.eval.Evaluator import mill.util.{OSet, PrintLogger} class ReplApplyHandler[T: Discovered](obj: T) extends ApplyHandler[Task] { + // Evaluate classLoaderSig only once in the REPL to avoid busting caches + // as the user enters more REPL commands and changes the classpath + val classLoaderSig = Evaluator.classLoaderSig override def apply[V](t: Task[V]) = discoverMirror(obj) match{ case Left(err) => throw new Exception("Failed discovery consistency check: " + err) case Right(mirror) => val log = new PrintLogger(true) - val evaluator = new Evaluator(pwd / 'out, Discovered.mapping(obj)(mirror), log) + val evaluator = new Evaluator( + pwd / 'out, + Discovered.mapping(obj)(mirror), + log, + classLoaderSig = classLoaderSig + ) evaluator.evaluate(OSet(t)).values.head.asInstanceOf[V] } } |