From bbaf5674389e39c85bba296f7120707a2599169e Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Tue, 20 Feb 2018 21:46:04 -0800 Subject: Only invalidate Evaluator.State cache if the `interpWatched` files we used to create the Evaluator change, not when other random files we're building do --- main/src/mill/main/MainRunner.scala | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'main/src') diff --git a/main/src/mill/main/MainRunner.scala b/main/src/mill/main/MainRunner.scala index 8f546ced..3f0f961a 100644 --- a/main/src/mill/main/MainRunner.scala +++ b/main/src/mill/main/MainRunner.scala @@ -5,15 +5,14 @@ import ammonite.Main import ammonite.interp.{Interpreter, Preprocessor} import ammonite.ops.Path import ammonite.util._ -import mill.define.Discover import mill.eval.{Evaluator, PathRef} import mill.main.MainRunner.WatchInterrupted import mill.util.PrintLogger -import mill.main.RunScript -import upickle.Js + object MainRunner{ case class WatchInterrupted(stateCache: Option[Evaluator.State]) extends Exception } + /** * Customized version of [[ammonite.MainRunner]], allowing us to run Mill * `build.sc` scripts with mill-specific tweaks such as a custom @@ -31,6 +30,7 @@ class MainRunner(val config: ammonite.main.Cli.Config, ){ var stateCache = stateCache0 + override def watchAndWait(watched: Seq[(Path, Long)]) = { printInfo(s"Watching for changes to ${watched.length} files... (Ctrl-C to exit)") def statAll() = watched.forall{ case (file, lastMTime) => @@ -67,11 +67,9 @@ class MainRunner(val config: ammonite.main.Cli.Config, case Res.Success(data) => val (eval, evaluationWatches, res) = data - val watched = interpWatched ++ evaluationWatches + stateCache = Some(Evaluator.State(eval.rootModule, eval.classLoaderSig, eval.workerCache, interpWatched)) - stateCache = Some(Evaluator.State(eval.rootModule, eval.classLoaderSig, eval.workerCache, watched)) - - (Res(res), watched) + (Res(res), interpWatched ++ evaluationWatches) case _ => (result, interpWatched) } } @@ -82,7 +80,6 @@ class MainRunner(val config: ammonite.main.Cli.Config, case Res.Success(value) => true case _ => super.handleWatchRes(res, printing) } - } override def initMain(isRepl: Boolean) = { @@ -93,6 +90,7 @@ class MainRunner(val config: ammonite.main.Cli.Config, wd = config.wd ) } + object CustomCodeWrapper extends Preprocessor.CodeWrapper { def top(pkgName: Seq[Name], imports: Imports, indexedWrapperName: Name) = { val wrapName = indexedWrapperName.backticked -- cgit v1.2.3