diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-12 14:13:50 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-12 14:13:50 -0800 |
commit | 51aa1f11de43808c4604d15b23523867d13d9e44 (patch) | |
tree | 099b89b8e8a7bbbf0d00e0e5734665c094bb55f3 /core/src | |
parent | b12c3f0f040a2b6caf1f94ad789d80b91313e381 (diff) | |
download | mill-51aa1f11de43808c4604d15b23523867d13d9e44.tar.gz mill-51aa1f11de43808c4604d15b23523867d13d9e44.tar.bz2 mill-51aa1f11de43808c4604d15b23523867d13d9e44.zip |
Clean up `mill.Main`
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/scala/mill/Main.scala | 53 | ||||
-rw-r--r-- | core/src/main/scala/mill/eval/Evaluator.scala | 6 | ||||
-rw-r--r-- | core/src/test/scala/mill/EvaluationTests.scala | 4 | ||||
-rw-r--r-- | core/src/test/scala/mill/JavaCompileJarTests.scala | 1 |
4 files changed, 33 insertions, 31 deletions
diff --git a/core/src/main/scala/mill/Main.scala b/core/src/main/scala/mill/Main.scala index 2b33fb78..9e7a9d11 100644 --- a/core/src/main/scala/mill/Main.scala +++ b/core/src/main/scala/mill/Main.scala @@ -3,7 +3,7 @@ package mill import ammonite.ops._ import ammonite.util.{Name, Res} import mill.define.Task -import mill.discover.{CommandInfo, Discovered, Info, LabelInfo} +import mill.discover._ import mill.eval.Evaluator import mill.util.OSet import play.api.libs.json.Format @@ -11,49 +11,52 @@ import play.api.libs.json.Format object Main { def apply[T: Discovered](args: Seq[String], obj: T, watch: Path => Unit) = { + val startTime = System.currentTimeMillis() val Seq(selectorString, rest @_*) = args val selector = selectorString.split('.') val discovered = implicitly[Discovered[T]] val consistencyErrors = Discovered.consistencyCheck(obj, discovered) - pprint.log(consistencyErrors) if (consistencyErrors.nonEmpty) println("Failed Discovered.consistencyCheck: " + consistencyErrors) else { val mapping = Discovered.mapping(obj)(discovered) val workspacePath = pwd / 'out - val evaluator = new Evaluator(workspacePath, mapping) + val mainRoutes = discovered.mains.map(x => (x.path :+ x.entryPoint.name, x: Info[T, _])) val targetRoutes = discovered.targets.map(x => (x.path, x: Info[T, _])) val routeList: Seq[(Seq[String], Info[T, _])] = mainRoutes ++ targetRoutes - val allRoutes = routeList.toMap[Seq[String], Info[_, _]] - allRoutes.get(selector) match{ - case Some(nestedEntryPoint: CommandInfo[T, _]) => - nestedEntryPoint.invoke( - obj, - ammonite.main.Scripts.groupArgs(rest.toList) - ) match{ - case error: mill.discover.Router.Result.Error => - println("Failed to evaluate main method: " + error) - case mill.discover.Router.Result.Success(target) => - println("Found target! " + target) - val evaluated = evaluator.evaluate(OSet(target)) + val routeMap = routeList.toMap + routeMap.get(selector) match{ + case Some(info) => + val target = getTarget(obj, info, rest.toList) + val evaluator = new Evaluator(workspacePath, mapping) + val evaluated = evaluator.evaluate(OSet(target)) - evaluated.transitive.foreach{ - case t: define.Source => - println("Watching " + t.handle.path) - watch(t.handle.path) - case _ => // do nothing - } + val delta = System.currentTimeMillis() - startTime + println(fansi.Color.Blue("Finished in " + delta/1000.0 + "s")) + evaluated.transitive.foreach{ + case t: define.Source => watch(t.handle.path) + case _ => // do nothing } - case Some(labelled: LabelInfo[T, _]) => - val target = labelled.run(obj) - val evaluated = evaluator.evaluate(OSet(target)) - pprint.log(evaluated) case None => println("Unknown selector: " + selector) } } } + def getTarget[T](obj: T, info: Info[T, _], args: List[String]) = info match{ + case nestedEntryPoint: CommandInfo[T, _] => + nestedEntryPoint.invoke( + obj, + ammonite.main.Scripts.groupArgs(args) + ) match{ + case error: Router.Result.Error => + throw new Exception("Failed to evaluate main method: " + error) + case mill.discover.Router.Result.Success(target) => target + } + case labelled: LabelInfo[T, _] => labelled.run(obj) + } + + def main(args: Array[String]): Unit = { val List(buildFile, rest @_*) = args.toList diff --git a/core/src/main/scala/mill/eval/Evaluator.scala b/core/src/main/scala/mill/eval/Evaluator.scala index e0c13044..da6e2656 100644 --- a/core/src/main/scala/mill/eval/Evaluator.scala +++ b/core/src/main/scala/mill/eval/Evaluator.scala @@ -71,6 +71,11 @@ class Evaluator(workspacePath: Path, (newResults, Nil) case _ => + + val labeled = group.collect(labeling) + if (labeled.nonEmpty){ + println(fansi.Color.Blue("Running " + labeled.map(_.segments.mkString(".")).mkString(", "))) + } val (newResults, newEvaluated, terminalResults) = evaluateGroup(group, results, targetDestPath) metadataPath.foreach( @@ -110,7 +115,6 @@ class Evaluator(workspacePath: Path, ) val args = new Args(targetInputValues, targetDestPath.orNull) - val res = target.evaluate(args) for(targetLabel <- labeling.get(target)){ terminalResults(target) = targetLabel diff --git a/core/src/test/scala/mill/EvaluationTests.scala b/core/src/test/scala/mill/EvaluationTests.scala index 1cfc93fa..09dd6731 100644 --- a/core/src/test/scala/mill/EvaluationTests.scala +++ b/core/src/test/scala/mill/EvaluationTests.scala @@ -62,7 +62,6 @@ object EvaluationTests extends TestSuite{ import graphs._ 'evaluateSingle - { - 'singleton - { import singleton._ val check = new Checker(singleton) @@ -284,9 +283,6 @@ object EvaluationTests extends TestSuite{ check(middle, expValue = 100, expEvaled = OSet(), extraEvaled = 2, secondRunNoOp = false) assert(leftCount == 4, middleCount == 4, rightCount == 1) } - - } - } } diff --git a/core/src/test/scala/mill/JavaCompileJarTests.scala b/core/src/test/scala/mill/JavaCompileJarTests.scala index 8272ed71..87fb55f0 100644 --- a/core/src/test/scala/mill/JavaCompileJarTests.scala +++ b/core/src/test/scala/mill/JavaCompileJarTests.scala @@ -127,7 +127,6 @@ object JavaCompileJarTests extends TestSuite{ val executed = %%('java, "-cp", workspacePath/'jar, "test.Foo")(workspacePath).out.string assert(executed == (31337 + 271828) + "\n") - println("="*20 + "Run Main" + "="*20) for(i <- 0 until 3){ // Build.run is not cached, so every time we eval it it has to // re-evaluate |