diff options
-rwxr-xr-x | build.sc | 4 | ||||
-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 | ||||
-rw-r--r-- | scalaplugin/src/main/scala/mill/scalaplugin/Subproject.scala | 30 |
6 files changed, 52 insertions, 46 deletions
@@ -39,8 +39,8 @@ object Build{ def test() = T.command{ TestRunner.apply( "mill.UTestFramework", - runDepClasspath().map(_.path) :+ compiled().path, - Seq(compiled().path) + runDepClasspath().map(_.path) :+ compile().path, + Seq(compile().path) ) } } 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 diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/Subproject.scala b/scalaplugin/src/main/scala/mill/scalaplugin/Subproject.scala index c16e4433..61c6812b 100644 --- a/scalaplugin/src/main/scala/mill/scalaplugin/Subproject.scala +++ b/scalaplugin/src/main/scala/mill/scalaplugin/Subproject.scala @@ -161,15 +161,19 @@ trait Subproject extends Cacher{ def depClasspath = T{ Seq.empty[PathRef] } - def upstreamRunClasspath = Task.traverse( - for (p <- projectDeps) - yield T.task(p.runDepClasspath() ++ Seq(p.compiled())) - ) + def upstreamRunClasspath = T{ + Task.traverse( + for (p <- projectDeps) + yield T.task(p.runDepClasspath() ++ Seq(p.compile())) + ) + } - def upstreamCompileClasspath = Task.traverse( - for (p <- projectDeps) - yield T.task(p.compileDepClasspath() ++ Seq(p.compiled())) - ) + def upstreamCompileClasspath = T{ + Task.traverse( + for (p <- projectDeps) + yield T.task(p.compileDepClasspath() ++ Seq(p.compile())) + ) + } def compileDepClasspath: T[Seq[PathRef]] = T{ upstreamCompileClasspath().flatten ++ depClasspath() ++ resolveDependencies( @@ -193,23 +197,23 @@ trait Subproject extends Cacher{ def sources = T.source{ basePath / 'src } def resources = T.source{ basePath / 'resources } - def compiled = T{ + def compile = T{ compileScala(scalaVersion(), sources(), compileDepClasspath(), Task.ctx().dest) } - def classpath = T{ Seq(resources(), compiled()) } - def jar = T{ modules.Jvm.jarUp(resources, compiled) } + def classpath = T{ Seq(resources(), compile()) } + def jar = T{ modules.Jvm.jarUp(resources, compile) } def run(mainClass: String) = T.command{ import ammonite.ops._, ImplicitWd._ - %('java, "-cp", (runDepClasspath().map(_.path) :+ compiled().path).mkString(":"), mainClass) + %('java, "-cp", (runDepClasspath().map(_.path) :+ compile().path).mkString(":"), mainClass) } def console() = T.command{ import ammonite.ops._, ImplicitWd._ %('java, "-cp", - (runDepClasspath().map(_.path) :+ compiled().path).mkString(":"), + (runDepClasspath().map(_.path) :+ compile().path).mkString(":"), "scala.tools.nsc.MainGenericRunner", "-usejavacp" ) |