summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-01-02 10:39:32 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-01-02 10:42:23 -0800
commit21478c5fa057d60399f7fdae1ce322ab0a8ea298 (patch)
treea51adbd2eb9f17b7e18e03c286c98db5ca571679
parent4d159657fe11b0dd7849e4c37d835e1f532accac (diff)
downloadmill-21478c5fa057d60399f7fdae1ce322ab0a8ea298.tar.gz
mill-21478c5fa057d60399f7fdae1ce322ab0a8ea298.tar.bz2
mill-21478c5fa057d60399f7fdae1ce322ab0a8ea298.zip
Make `--watch` properly handle the case where the evaluator is cached, where previously it would forget the `build.sc` files it was meant to watch
-rw-r--r--core/src/main/scala/mill/Main.scala1
-rw-r--r--core/src/main/scala/mill/main/MainRunner.scala37
-rw-r--r--core/src/main/scala/mill/main/RunScript.scala58
3 files changed, 52 insertions, 44 deletions
diff --git a/core/src/main/scala/mill/Main.scala b/core/src/main/scala/mill/Main.scala
index c506cf43..3a00bdb8 100644
--- a/core/src/main/scala/mill/Main.scala
+++ b/core/src/main/scala/mill/Main.scala
@@ -1,6 +1,7 @@
package mill
import ammonite.ops._
+
object Main {
case class Config(home: ammonite.ops.Path = pwd/'out/'ammonite,
colored: Option[Boolean] = None,
diff --git a/core/src/main/scala/mill/main/MainRunner.scala b/core/src/main/scala/mill/main/MainRunner.scala
index 895576bd..1b2322b0 100644
--- a/core/src/main/scala/mill/main/MainRunner.scala
+++ b/core/src/main/scala/mill/main/MainRunner.scala
@@ -26,36 +26,19 @@ class MainRunner(config: ammonite.main.Cli.Config, show: Boolean,
isRepl = false,
printing = true,
mainCfg => {
- mainCfg.instantiateInterpreter() match{
- case Left(problems) => problems
- case Right(interp) =>
- val interpWatched = interp.watchedFiles
+ val (result, interpWatched) = RunScript.runScript(
+ mainCfg.wd, scriptPath, mainCfg.instantiateInterpreter(), scriptArgs, lastEvaluator,
+ errPrintStream, errPrintStream
+ )
- val result = RunScript.runScript(
- mainCfg.wd, scriptPath, interp, scriptArgs, lastEvaluator,
- errPrintStream, errPrintStream
- )
- result match{
- case Res.Success(data) =>
- val (eval, evaluationWatches0, res) = data
- val alreadyStale = evaluationWatches0.exists(p => p.sig != PathRef(p.path, p.quick).sig)
- // If the file changed between the creation of the original
- // `PathRef` and the current moment, use random junk .sig values
- // to force an immediate re-run. Otherwise calculate the
- // pathSignatures the same way Ammonite would and hand over the
- // values, so Ammonite can watch them and only re-run if they
- // subsequently change
- val evaluationWatches =
- if (alreadyStale) evaluationWatches0.map(_.path -> util.Random.nextLong())
- else evaluationWatches0.map(p => p.path -> Interpreter.pathSignature(p.path))
-
- lastEvaluator = Some((interpWatched, eval))
- (Res(res.map(_.flatMap(_._2))), interpWatched ++ evaluationWatches)
- case _ =>
- (result, interpWatched)
- }
+ result match{
+ case Res.Success(data) =>
+ val (eval, evaluationWatches, res) = data
+ lastEvaluator = Some((interpWatched, eval))
+ (Res(res), interpWatched ++ evaluationWatches)
+ case _ => (result, interpWatched)
}
}
)
diff --git a/core/src/main/scala/mill/main/RunScript.scala b/core/src/main/scala/mill/main/RunScript.scala
index 34a569fb..f5523bb6 100644
--- a/core/src/main/scala/mill/main/RunScript.scala
+++ b/core/src/main/scala/mill/main/RunScript.scala
@@ -11,8 +11,9 @@ import mill.{PathRef, define}
import mill.define.Task
import mill.discover.Mirror.Segment
import mill.discover.{Discovered, Mirror}
-import mill.eval.{Evaluator, Result}
+import mill.eval.{Evaluator, PathRef, Result}
import mill.util.{OSet, PrintLogger}
+import upickle.Js
/**
* Custom version of ammonite.main.Scripts, letting us run the build.sc script
@@ -20,29 +21,52 @@ import mill.util.{OSet, PrintLogger}
* subsystem
*/
object RunScript{
-
def runScript(wd: Path,
path: Path,
- interp: ammonite.interp.Interpreter,
+ instantiateInterpreter: => Either[(Res.Failing, Seq[(Path, Long)]), ammonite.interp.Interpreter],
scriptArgs: Seq[String],
lastEvaluator: Option[(Seq[(Path, Long)], Evaluator[_])],
infoStream: PrintStream,
- errStream: PrintStream) = {
+ errStream: PrintStream)
+ : (Res[(Evaluator[_], Seq[(Path, Long)], Either[String, Seq[Js.Value]])], Seq[(Path, Long)]) = {
val log = new PrintLogger(true, infoStream, errStream)
- for{
- evaluator <- lastEvaluator match{
- case Some((prevInterpWatchedSig, prevEvaluator))
- if watchedSigUnchanged(prevInterpWatchedSig) =>
- Res.Success(prevEvaluator)
-
- case _ =>
- interp.watch(path)
- for(mapping <- evaluateMapping(wd, path, interp))
- yield new Evaluator(wd / 'out, wd, mapping, log)
- }
- (watches, res) <- Res(evaluateTarget(evaluator, scriptArgs))
- } yield (evaluator, watches, res)
+ val (evalRes, interpWatched) = lastEvaluator match{
+ case Some((prevInterpWatchedSig, prevEvaluator))
+ if watchedSigUnchanged(prevInterpWatchedSig) =>
+
+ (Res.Success(prevEvaluator), prevInterpWatchedSig)
+
+ case _ =>
+ instantiateInterpreter match{
+ case Left((res, watched)) => (res, watched)
+ case Right(interp) =>
+ interp.watch(path)
+ val eval =
+ for(mapping <- evaluateMapping(wd, path, interp))
+ yield new Evaluator(wd / 'out, wd, mapping, log)
+ (eval, interp.watchedFiles)
+ }
+ }
+
+ val evaluated = for{
+ evaluator <- evalRes
+ (evalWatches, res) <- Res(evaluateTarget(evaluator, scriptArgs))
+ } yield {
+ val alreadyStale = evalWatches.exists(p => p.sig != new PathRef(p.path, p.quick).sig)
+ // If the file changed between the creation of the original
+ // `PathRef` and the current moment, use random junk .sig values
+ // to force an immediate re-run. Otherwise calculate the
+ // pathSignatures the same way Ammonite would and hand over the
+ // values, so Ammonite can watch them and only re-run if they
+ // subsequently change
+ val evaluationWatches =
+ if (alreadyStale) evalWatches.map(_.path -> util.Random.nextLong())
+ else evalWatches.map(p => p.path -> Interpreter.pathSignature(p.path))
+
+ (evaluator, evaluationWatches, res.map(_.flatMap(_._2)))
+ }
+ (evaluated, interpWatched)
}
def watchedSigUnchanged(sig: Seq[(Path, Long)]) = {