diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-02-02 21:48:35 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-02-02 21:48:35 -0800 |
commit | 80c8ad730132145fc33b790657b14669f282d5b0 (patch) | |
tree | fa9d39763756cc07a3e9524cf146186cb2979516 /core | |
parent | 27273750636acbbff1b37cf53bba76684f0b96bb (diff) | |
download | mill-80c8ad730132145fc33b790657b14669f282d5b0.tar.gz mill-80c8ad730132145fc33b790657b14669f282d5b0.tar.bz2 mill-80c8ad730132145fc33b790657b14669f282d5b0.zip |
- Rename `basePath` -> `millSourcePath`
- Make `T.worker`s not flush out their directories between instantiations
Diffstat (limited to 'core')
-rw-r--r-- | core/src/mill/define/Cross.scala | 2 | ||||
-rw-r--r-- | core/src/mill/define/Ctx.scala | 2 | ||||
-rw-r--r-- | core/src/mill/define/Module.scala | 12 | ||||
-rw-r--r-- | core/src/mill/define/Task.scala | 2 | ||||
-rw-r--r-- | core/src/mill/eval/Evaluator.scala | 34 | ||||
-rw-r--r-- | core/src/mill/main/RunScript.scala | 2 | ||||
-rw-r--r-- | core/test/resources/examples/javac/build.sc | 4 | ||||
-rw-r--r-- | core/test/src/mill/define/BasePathTests.scala | 14 | ||||
-rw-r--r-- | core/test/src/mill/eval/ModuleTests.scala | 2 | ||||
-rw-r--r-- | core/test/src/mill/util/TestEvaluator.scala | 14 |
10 files changed, 47 insertions, 41 deletions
diff --git a/core/src/mill/define/Cross.scala b/core/src/mill/define/Cross.scala index b51064be..aa730e0d 100644 --- a/core/src/mill/define/Cross.scala +++ b/core/src/mill/define/Cross.scala @@ -61,7 +61,7 @@ class Cross[T](cases: Any*) c, ctx.copy( segments = ctx.segments ++ Seq(ctx.segment), - basePath = ctx.basePath / relPath, + millSourcePath = ctx.millSourcePath / relPath, segment = Segment.Cross(crossValues) ) ) diff --git a/core/src/mill/define/Ctx.scala b/core/src/mill/define/Ctx.scala index 6d685521..ddbdca96 100644 --- a/core/src/mill/define/Ctx.scala +++ b/core/src/mill/define/Ctx.scala @@ -45,7 +45,7 @@ case class Segments(value: Segment*){ case class Ctx(enclosing: String, lineNum: Int, segment: Segment, - basePath: Path, + millSourcePath: Path, segments: Segments, overrides: Int){ } diff --git a/core/src/mill/define/Module.scala b/core/src/mill/define/Module.scala index 11a98d95..039011d8 100644 --- a/core/src/mill/define/Module.scala +++ b/core/src/mill/define/Module.scala @@ -24,8 +24,8 @@ class Module(implicit outerCtx0: mill.define.Ctx) extends mill.moduledefs.Cacher lazy val millModuleDirectChildren = millInternal.reflectNestedObjects[Module] def millOuterCtx = outerCtx0 - def basePath: Path = millOuterCtx.basePath / millOuterCtx.segment.pathSegments - implicit def millModuleBasePath: BasePath = BasePath(basePath) + def millSourcePath: Path = millOuterCtx.millSourcePath / millOuterCtx.segment.pathSegments + implicit def millModuleBasePath: BasePath = BasePath(millSourcePath) implicit def millModuleSegments: Segments = { millOuterCtx.segments ++ Seq(millOuterCtx.segment) } @@ -92,19 +92,19 @@ trait TaskModule extends Module { object BaseModule{ case class Implicit(value: BaseModule) } -class BaseModule(basePath0: Path) +class BaseModule(millSourcePath0: Path) (implicit millModuleEnclosing0: sourcecode.Enclosing, millModuleLine0: sourcecode.Line, millName0: sourcecode.Name) extends Module()( - mill.define.Ctx.make(implicitly, implicitly, implicitly, BasePath(basePath0), Segments(), Overrides(0)) + mill.define.Ctx.make(implicitly, implicitly, implicitly, BasePath(millSourcePath0), Segments(), Overrides(0)) ){ // A BaseModule should provide an empty Segments list to it's children, since // it is the root of the module tree, and thus must not include it's own // sourcecode.Name as part of the list, override implicit def millModuleSegments: Segments = Segments() - override def basePath = millOuterCtx.basePath - override implicit def millModuleBasePath: BasePath = BasePath(basePath) + override def millSourcePath = millOuterCtx.millSourcePath + override implicit def millModuleBasePath: BasePath = BasePath(millSourcePath) implicit def millImplicitBaseModule: BaseModule.Implicit = BaseModule.Implicit(this) } diff --git a/core/src/mill/define/Task.scala b/core/src/mill/define/Task.scala index f74171ec..a94d9703 100644 --- a/core/src/mill/define/Task.scala +++ b/core/src/mill/define/Task.scala @@ -289,7 +289,7 @@ class Command[+T](t: Task[T], } class Worker[+T](t: Task[T], ctx0: mill.define.Ctx) extends NamedTaskImpl[T](ctx0, t) { - + override def flushDest = false override def asWorker = Some(this) } class Persistent[+T](t: Task[T], diff --git a/core/src/mill/eval/Evaluator.scala b/core/src/mill/eval/Evaluator.scala index 31b59865..21e3d3a9 100644 --- a/core/src/mill/eval/Evaluator.scala +++ b/core/src/mill/eval/Evaluator.scala @@ -12,21 +12,21 @@ import mill.util.Strict.Agg import scala.collection.mutable import scala.util.control.NonFatal -case class Labelled[T](target: NamedTask[T], +case class Labelled[T](task: NamedTask[T], segments: Segments){ - def format = target match{ + def format = task match{ case t: Target[T] => Some(t.readWrite.asInstanceOf[upickle.default.ReadWriter[T]]) case _ => None } - def writer = target match{ + def writer = task match{ case t: mill.define.Command[T] => Some(t.writer.asInstanceOf[upickle.default.Writer[T]]) case t: Target[T] => Some(t.readWrite.asInstanceOf[upickle.default.ReadWriter[T]]) case _ => None } } -class Evaluator[T](val workspacePath: Path, - val basePath: Path, - val externalBasePath: Path, +class Evaluator[T](val outPath: Path, + val millSourcePath: Path, + val externalOutPath: Path, val rootModule: mill.Module, val discover: Discover[T], log: Logger, @@ -35,7 +35,7 @@ class Evaluator[T](val workspacePath: Path, val workerCache = mutable.Map.empty[Segments, (Int, Any)] def evaluate(goals: Agg[Task[_]]): Evaluator.Results = { - mkdir(workspacePath) + mkdir(outPath) val transitive = Graph.transitiveTargets(goals) val topoSorted = Graph.topoSorted(transitive) @@ -125,8 +125,13 @@ class Evaluator[T](val workspacePath: Path, counterMsg = counterMsg ) case Right(labelledNamedTask) => - val paths = Evaluator.resolveDestPaths(workspacePath, labelledNamedTask.segments) - val groupBasePath = basePath / Evaluator.makeSegmentStrings(labelledNamedTask.segments) + + val paths = if (labelledNamedTask.task.asTarget.exists(rootModule.millInternal.targets.contains)){ + Evaluator.resolveDestPaths(outPath, labelledNamedTask.segments) + }else{ + Evaluator.resolveDestPaths(externalOutPath, labelledNamedTask.segments) + } + val groupBasePath = millSourcePath / Evaluator.makeSegmentStrings(labelledNamedTask.segments) mkdir(paths.out) val cached = for{ json <- scala.util.Try(upickle.json.read(read(paths.meta))).toOption @@ -136,14 +141,14 @@ class Evaluator[T](val workspacePath: Path, parsed <- reader.read.lift(terminalResult) } yield parsed - val workerCached = labelledNamedTask.target.asWorker + val workerCached = labelledNamedTask.task.asWorker .flatMap{w => workerCache.get(w.ctx.segments)} .collect{case (`inputsHash`, v) => v} workerCached.map((_, inputsHash)) orElse cached.map(p => (p, p.hashCode())) match{ case Some((v, hashCode)) => val newResults = mutable.LinkedHashMap.empty[Task[_], Result[(Any, Int)]] - newResults(labelledNamedTask.target) = Result.Success((v, hashCode)) + newResults(labelledNamedTask.task) = Result.Success((v, hashCode)) (newResults, Nil) @@ -155,7 +160,8 @@ class Evaluator[T](val workspacePath: Path, case Segment.Cross(s) => "[" + s.mkString(",") + "]" } - if (labelledNamedTask.target.flushDest) rm(paths.dest) + if (labelledNamedTask.task.flushDest) rm(paths.dest) + val (newResults, newEvaluated) = evaluateGroup( group, results, @@ -166,9 +172,9 @@ class Evaluator[T](val workspacePath: Path, counterMsg = counterMsg ) - newResults(labelledNamedTask.target) match{ + newResults(labelledNamedTask.task) match{ case Result.Success((v, hashCode)) => - labelledNamedTask.target.asWorker match{ + labelledNamedTask.task.asWorker match{ case Some(w) => workerCache(w.ctx.segments) = (inputsHash, v) case None => diff --git a/core/src/mill/main/RunScript.scala b/core/src/mill/main/RunScript.scala index f09acf66..dfe49c57 100644 --- a/core/src/mill/main/RunScript.scala +++ b/core/src/mill/main/RunScript.scala @@ -185,7 +185,7 @@ object RunScript{ t match { case t: mill.define.NamedTask[_] => val jsonFile = Evaluator - .resolveDestPaths(evaluator.workspacePath, t.ctx.segments) + .resolveDestPaths(evaluator.outPath, t.ctx.segments) .meta val metadata = upickle.json.read(jsonFile.toIO) Some(metadata(1)) diff --git a/core/test/resources/examples/javac/build.sc b/core/test/resources/examples/javac/build.sc index 4a0882c6..8f250014 100644 --- a/core/test/resources/examples/javac/build.sc +++ b/core/test/resources/examples/javac/build.sc @@ -5,8 +5,8 @@ import mill.eval.PathRef import mill.modules.Jvm import mill.util.Loose -def sourceRootPath = basePath / 'src -def resourceRootPath = basePath / 'resources +def sourceRootPath = millSourcePath / 'src +def resourceRootPath = millSourcePath / 'resources // sourceRoot -> allSources -> classFiles // | diff --git a/core/test/src/mill/define/BasePathTests.scala b/core/test/src/mill/define/BasePathTests.scala index 62f84787..f7a1afa7 100644 --- a/core/test/src/mill/define/BasePathTests.scala +++ b/core/test/src/mill/define/BasePathTests.scala @@ -8,7 +8,7 @@ object BasePathTests extends TestSuite{ val testGraphs = new TestGraphs val tests = Tests{ def check(m: Module, segments: String*) = { - val remaining = m.basePath.relativeTo(pwd).segments.drop(1) + val remaining = m.millSourcePath.relativeTo(pwd).segments.drop(1) assert(remaining == segments) } 'singleton - { @@ -47,18 +47,18 @@ object BasePathTests extends TestSuite{ } 'overriden - { object overridenBasePath extends TestUtil.BaseModule { - override def basePath = pwd / 'overridenBasePathRootValue + override def millSourcePath = pwd / 'overridenBasePathRootValue object nested extends Module{ - override def basePath = super.basePath / 'overridenBasePathNested + override def millSourcePath = super.millSourcePath / 'overridenBasePathNested object nested extends Module{ - override def basePath = super.basePath / 'overridenBasePathDoubleNested + override def millSourcePath = super.millSourcePath / 'overridenBasePathDoubleNested } } } assert( - overridenBasePath.basePath == pwd / 'overridenBasePathRootValue, - overridenBasePath.nested.basePath == pwd / 'overridenBasePathRootValue / 'nested / 'overridenBasePathNested, - overridenBasePath.nested.nested.basePath == pwd / 'overridenBasePathRootValue / 'nested / 'overridenBasePathNested / 'nested / 'overridenBasePathDoubleNested + overridenBasePath.millSourcePath == pwd / 'overridenBasePathRootValue, + overridenBasePath.nested.millSourcePath == pwd / 'overridenBasePathRootValue / 'nested / 'overridenBasePathNested, + overridenBasePath.nested.nested.millSourcePath == pwd / 'overridenBasePathRootValue / 'nested / 'overridenBasePathNested / 'nested / 'overridenBasePathDoubleNested ) } diff --git a/core/test/src/mill/eval/ModuleTests.scala b/core/test/src/mill/eval/ModuleTests.scala index 110e8c79..56c1a47b 100644 --- a/core/test/src/mill/eval/ModuleTests.scala +++ b/core/test/src/mill/eval/ModuleTests.scala @@ -26,7 +26,7 @@ object ModuleTests extends TestSuite{ ) val Right((30, 1)) = check.apply(Build.z) - val base = check.evaluator.workspacePath + val base = check.evaluator.outPath assert( read(base / 'z / "meta.json").contains("30"), read(base / 'mill / 'eval / 'ModuleTests / 'ExternalModule / 'x / "meta.json").contains("13"), diff --git a/core/test/src/mill/util/TestEvaluator.scala b/core/test/src/mill/util/TestEvaluator.scala index 3b34e27d..26577f3e 100644 --- a/core/test/src/mill/util/TestEvaluator.scala +++ b/core/test/src/mill/util/TestEvaluator.scala @@ -10,16 +10,16 @@ import utest.assert import language.experimental.macros object TestEvaluator{ implicit def implicitDisover[T]: Discover[T] = macro applyImpl[T] - val externalBasePath = pwd / 'target / 'external + val externalOutPath = pwd / 'target / 'external } class TestEvaluator[T <: TestUtil.TestBuild](module: T, workspacePath: Path, - basePath: Path) + millSourcePath: Path) (implicit discover: Discover[T]){ - val evaluator = new Evaluator( - workspacePath, basePath, TestEvaluator.externalBasePath, module, discover, DummyLogger - ) -// val evaluator = new Evaluator(workspacePath, basePath, module, discover, new PrintLogger(true, ammonite.util.Colors.Default, System.out, System.out, System.err)) + val logger = DummyLogger +// val logger = new PrintLogger(true, ammonite.util.Colors.Default, System.out, System.out, System.err) + val evaluator = new Evaluator(workspacePath, millSourcePath, TestEvaluator.externalOutPath, module, discover, logger) + def apply[T](t: Task[T]): Either[Result.Failing, (T, Int)] = { val evaluated = evaluator.evaluate(Agg(t)) @@ -31,7 +31,7 @@ class TestEvaluator[T <: TestUtil.TestBuild](module: T, case t: Target[_] if module.millInternal.targets.contains(t) && !t.isInstanceOf[Input[_]] => t - case t: mill.define.Command[_] => t + case t: mill.define.Command[_] => t }.size )) } else { |