diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-18 03:49:11 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-18 03:49:11 -0800 |
commit | 8e64e290c1969a78cd972f63ab58d32ca57d9fff (patch) | |
tree | ec1c6ac11370347386ca5a38a96f4d190784d086 /core | |
parent | e6ee4fe513c19547ecbfd232f908a828d788fc99 (diff) | |
download | mill-8e64e290c1969a78cd972f63ab58d32ca57d9fff.tar.gz mill-8e64e290c1969a78cd972f63ab58d32ca57d9fff.tar.bz2 mill-8e64e290c1969a78cd972f63ab58d32ca57d9fff.zip |
Cleanup
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/scala/mill/Main.scala | 86 | ||||
-rw-r--r-- | core/src/main/scala/mill/define/Task.scala | 113 | ||||
-rw-r--r-- | core/src/main/scala/mill/package.scala | 6 | ||||
-rw-r--r-- | core/src/test/scala/mill/DiscoveredTests.scala | 1 | ||||
-rw-r--r-- | core/src/test/scala/mill/EvaluationTests.scala | 1 | ||||
-rw-r--r-- | core/src/test/scala/mill/GraphTests.scala | 4 | ||||
-rw-r--r-- | core/src/test/scala/mill/JavaCompileJarTests.scala | 5 | ||||
-rw-r--r-- | core/src/test/scala/mill/TestGraphs.scala | 1 |
8 files changed, 116 insertions, 101 deletions
diff --git a/core/src/main/scala/mill/Main.scala b/core/src/main/scala/mill/Main.scala index 1f43a3e9..0dc6707d 100644 --- a/core/src/main/scala/mill/Main.scala +++ b/core/src/main/scala/mill/Main.scala @@ -1,5 +1,6 @@ package mill +import ammonite.interp.Interpreter import ammonite.main.Scripts import ammonite.ops._ import ammonite.util.Res @@ -7,10 +8,9 @@ import mill.define.Task import mill.discover._ import mill.eval.Evaluator import mill.util.OSet - import ammonite.main.Scripts.pathScoptRead import ammonite.repl.Repl -import mill.discover.Router.EntryPoint + object Main { def timed[T](t: => T) = { val startTime = System.currentTimeMillis() @@ -100,44 +100,60 @@ object Main { (c, v) => c.copy(watch = true) ) ) + ammonite.main.Cli.groupArgs(args.toList, signature, Config()) match{ case Left(err) => case Right((config, leftover)) => - if (config.help){ - val leftMargin = signature.map(ammonite.main.Cli.showArg(_).length).max + 2 - println(ammonite.main.Cli.formatBlock(signature, leftMargin).mkString("\n")) - }else if (config.repl){ - val repl = ammonite.Main( - predefFile = Some(pwd/"build.sc") - ).instantiateRepl(remoteLogger = None) - repl.right.get.interp.initializePredef() - repl.right.get.run() - }else { - val interp = ammonite.Main( - predefFile = Some(pwd/"build.sc") - ).instantiateInterpreter() - - interp.right.get.initializePredef() - val syntheticPath = pwd/'out/"run.sc" - write.over( - syntheticPath, - """@main def run(args: String*) = mill.Main(args, ammonite.predef.FilePredef, interp.watch) - | - |@main def idea() = mill.scalaplugin.GenIdea(ammonite.predef.FilePredef) - """.stripMargin - ) - - val res = ammonite.main.Scripts.runScript( - pwd, - syntheticPath, - interp.right.get, - Scripts.groupArgs(leftover) - ) - - handleWatchRes(res, true) - } + val loop = config.watch + do { + if (config.help) { + val leftMargin = signature.map(ammonite.main.Cli.showArg(_).length).max + 2 + println(ammonite.main.Cli.formatBlock(signature, leftMargin).mkString("\n")) + } else if (config.repl) { + val repl = ammonite.Main( + predefFile = Some(pwd / "build.sc") + ).instantiateRepl(remoteLogger = None).right.get + repl.interp.initializePredef() + repl.run() + watchAndWait(repl.interp.watchedFiles) + } else { + val interp = ammonite.Main( + predefFile = Some(pwd / "build.sc") + ).instantiateInterpreter().right.get + + interp.initializePredef() + val syntheticPath = pwd / 'out / "run.sc" + write.over( + syntheticPath, + """@main def run(args: String*) = mill.Main(args, ammonite.predef.FilePredef, interp.watch) + | + |@main def idea() = mill.scalaplugin.GenIdea(ammonite.predef.FilePredef) + """.stripMargin + ) + + val res = ammonite.main.Scripts.runScript( + pwd, + syntheticPath, + interp, + Scripts.groupArgs(leftover) + ) + + handleWatchRes(res, true) + watchAndWait(interp.watchedFiles) + } + + } while(loop) } } + def watchAndWait(watched: Seq[(Path, Long)]) = { + println(s"Watching for changes to ${watched.length} files... (Ctrl-C to exit)") + def statAll() = watched.forall{ case (file, lastMTime) => + Interpreter.pathSignature(file) == lastMTime + } + + while(statAll()) Thread.sleep(100) + } + def handleWatchRes[T](res: Res[T], printing: Boolean) = { val success = res match { case Res.Failure(msg) => diff --git a/core/src/main/scala/mill/define/Task.scala b/core/src/main/scala/mill/define/Task.scala index c256d3db..0e2591c6 100644 --- a/core/src/main/scala/mill/define/Task.scala +++ b/core/src/main/scala/mill/define/Task.scala @@ -1,7 +1,7 @@ package mill.define import mill.define.Applicative.Applyable -import mill.define.Task.targetImpl + import mill.eval.PathRef import mill.util.Args @@ -27,8 +27,62 @@ abstract class Task[+T] extends Task.Ops[T] with Applyable[T]{ } trait Target[+T] extends Task[T] -object Target{ +object Target extends Applicative.Applyer[Task, Task, Args]{ + implicit def apply[T](t: T): Target[T] = macro targetImpl[T] + + def apply[T](t: Task[T]): Target[T] = macro Cacher.impl0[Task, T] + + def command[T](t: T): Command[T] = macro commandImpl[T] + + def source(path: ammonite.ops.Path) = new Source(path) + + def command[T](t: Task[T]): Command[T] = new Command(t) + + def task[T](t: T): Task[T] = macro Applicative.impl[Task, T, Args] + def task[T](t: Task[T]): Task[T] = t + + def commandImpl[T: c.WeakTypeTag](c: Context)(t: c.Expr[T]): c.Expr[Command[T]] = { + import c.universe._ + + c.Expr[Command[T]]( + q"new ${weakTypeOf[Command[T]]}(${Applicative.impl[Task, T, Args](c)(t).tree})" + ) + } + + def targetImpl[T: c.WeakTypeTag](c: Context)(t: c.Expr[T]): c.Expr[Target[T]] = { + c.Expr[Target[T]]( + mill.define.Cacher.wrapCached(c)( + Applicative.impl[Task, T, Args](c)(t).tree + ) + ) + } + + def underlying[A](v: Task[A]) = v + def mapCtx[A, B](t: Task[A])(f: (A, Args) => B) = t.mapDest(f) + def zip() = new Task.Task0(()) + def zip[A](a: Task[A]) = a.map(Tuple1(_)) + def zip[A, B](a: Task[A], b: Task[B]) = a.zip(b) + def zip[A, B, C](a: Task[A], b: Task[B], c: Task[C]) = new Task[(A, B, C)]{ + val inputs = Seq(a, b, c) + def evaluate(args: Args) = (args[A](0), args[B](1), args[C](2)) + } + def zip[A, B, C, D](a: Task[A], b: Task[B], c: Task[C], d: Task[D]) = new Task[(A, B, C, D)]{ + val inputs = Seq(a, b, c, d) + def evaluate(args: Args) = (args[A](0), args[B](1), args[C](2), args[D](3)) + } + def zip[A, B, C, D, E](a: Task[A], b: Task[B], c: Task[C], d: Task[D], e: Task[E]) = new Task[(A, B, C, D, E)]{ + val inputs = Seq(a, b, c, d, e) + def evaluate(args: Args) = (args[A](0), args[B](1), args[C](2), args[D](3), args[E](4)) + } + def zip[A, B, C, D, E, F](a: Task[A], b: Task[B], c: Task[C], d: Task[D], e: Task[E], f: Task[F]) = new Task[(A, B, C, D, E, F)]{ + val inputs = Seq(a, b, c, d, e, f) + def evaluate(args: Args) = (args[A](0), args[B](1), args[C](2), args[D](3), args[E](4), args[F](5)) + } + def zip[A, B, C, D, E, F, G](a: Task[A], b: Task[B], c: Task[C], d: Task[D], e: Task[E], f: Task[F], g: Task[G]) = new Task[(A, B, C, D, E, F, G)]{ + val inputs = Seq(a, b, c, d, e, f, g) + def evaluate(args: Args) = (args[A](0), args[B](1), args[C](2), args[D](3), args[E](4), args[F](5), args[G](6)) + } } class TargetImpl[+T](t: Task[T], enclosing: String) extends Target[T] { val inputs = Seq(t) @@ -49,11 +103,9 @@ class Source(path: ammonite.ops.Path) extends Task[PathRef]{ val inputs = Nil } -object Task extends Applicative.Applyer[Task, Task, Args]{ - def apply[T](t: T): Target[T] = macro targetImpl[T] - def underlying[A](v: Task[A]) = v +object Task { + - def source(path: ammonite.ops.Path) = new Source(path) trait Module extends mill.define.Cacher[Task, Target]{ def wrapCached[T](t: Task[T], enclosing: String): Target[T] = new TargetImpl(t, enclosing) @@ -66,30 +118,6 @@ object Task extends Applicative.Applyer[Task, Task, Args]{ - def apply[T](t: Task[T]): Target[T] = macro Cacher.impl0[Task, T] - - def command[T](t: T): Command[T] = macro commandImpl[T] - - def command[T](t: Task[T]): Command[T] = new Command(t) - - def task[T](t: T): Task[T] = macro Applicative.impl[Task, T, Args] - def task[T](t: Task[T]): Task[T] = t - - def commandImpl[T: c.WeakTypeTag](c: Context)(t: c.Expr[T]): c.Expr[Command[T]] = { - import c.universe._ - - c.Expr[Command[T]]( - q"new ${weakTypeOf[Command[T]]}(${Applicative.impl[Task, T, Args](c)(t).tree})" - ) - } - - def targetImpl[T: c.WeakTypeTag](c: Context)(t: c.Expr[T]): c.Expr[Target[T]] = { - c.Expr[Target[T]]( - mill.define.Cacher.wrapCached(c)( - Applicative.impl[Task, T, Args](c)(t).tree - ) - ) - } abstract class Ops[+T]{ this: Task[T] => def map[V](f: T => V) = new Task.Mapped(this, f) @@ -128,28 +156,5 @@ object Task extends Applicative.Applyer[Task, Task, Args]{ - def mapCtx[A, B](t: Task[A])(f: (A, Args) => B) = t.mapDest(f) - def zip() = new Task.Task0(()) - def zip[A](a: Task[A]) = a.map(Tuple1(_)) - def zip[A, B](a: Task[A], b: Task[B]) = a.zip(b) - def zip[A, B, C](a: Task[A], b: Task[B], c: Task[C]) = new Task[(A, B, C)]{ - val inputs = Seq(a, b, c) - def evaluate(args: Args) = (args[A](0), args[B](1), args[C](2)) - } - def zip[A, B, C, D](a: Task[A], b: Task[B], c: Task[C], d: Task[D]) = new Task[(A, B, C, D)]{ - val inputs = Seq(a, b, c, d) - def evaluate(args: Args) = (args[A](0), args[B](1), args[C](2), args[D](3)) - } - def zip[A, B, C, D, E](a: Task[A], b: Task[B], c: Task[C], d: Task[D], e: Task[E]) = new Task[(A, B, C, D, E)]{ - val inputs = Seq(a, b, c, d, e) - def evaluate(args: Args) = (args[A](0), args[B](1), args[C](2), args[D](3), args[E](4)) - } - def zip[A, B, C, D, E, F](a: Task[A], b: Task[B], c: Task[C], d: Task[D], e: Task[E], f: Task[F]) = new Task[(A, B, C, D, E, F)]{ - val inputs = Seq(a, b, c, d, e, f) - def evaluate(args: Args) = (args[A](0), args[B](1), args[C](2), args[D](3), args[E](4), args[F](5)) - } - def zip[A, B, C, D, E, F, G](a: Task[A], b: Task[B], c: Task[C], d: Task[D], e: Task[E], f: Task[F], g: Task[G]) = new Task[(A, B, C, D, E, F, G)]{ - val inputs = Seq(a, b, c, d, e, f, g) - def evaluate(args: Args) = (args[A](0), args[B](1), args[C](2), args[D](3), args[E](4), args[F](5), args[G](6)) - } + } diff --git a/core/src/main/scala/mill/package.scala b/core/src/main/scala/mill/package.scala index 81d87426..7dcb83d8 100644 --- a/core/src/main/scala/mill/package.scala +++ b/core/src/main/scala/mill/package.scala @@ -1,9 +1,9 @@ import mill.util.JsonFormatters package object mill extends JsonFormatters{ - val T = define.Task - type T[T] = define.Task[T] + val T = define.Target + type T[T] = define.Target[T] val PathRef = mill.eval.PathRef type PathRef = mill.eval.PathRef - + type Module = define.Task.Module } diff --git a/core/src/test/scala/mill/DiscoveredTests.scala b/core/src/test/scala/mill/DiscoveredTests.scala index 1a0893df..96c84d1b 100644 --- a/core/src/test/scala/mill/DiscoveredTests.scala +++ b/core/src/test/scala/mill/DiscoveredTests.scala @@ -2,7 +2,6 @@ package mill import utest._ import TestUtil.test -import mill.define.Task.Module import mill.discover.{Discovered, Mirror} object DiscoveredTests extends TestSuite{ diff --git a/core/src/test/scala/mill/EvaluationTests.scala b/core/src/test/scala/mill/EvaluationTests.scala index a5fd72a8..053fdd09 100644 --- a/core/src/test/scala/mill/EvaluationTests.scala +++ b/core/src/test/scala/mill/EvaluationTests.scala @@ -3,7 +3,6 @@ package mill import mill.TestUtil.{Test, test} import mill.define.{Target, Task} -import mill.define.Task.Module import mill.discover.Discovered import mill.eval.Evaluator import mill.util.OSet diff --git a/core/src/test/scala/mill/GraphTests.scala b/core/src/test/scala/mill/GraphTests.scala index d19b747d..a9a31971 100644 --- a/core/src/test/scala/mill/GraphTests.scala +++ b/core/src/test/scala/mill/GraphTests.scala @@ -1,10 +1,8 @@ package mill import utest._ -import TestUtil.test import mill.define.Task -import mill.define.Task.Module -import mill.discover.{Discovered, Mirror} +import mill.discover.Discovered import mill.eval.Evaluator import mill.util.OSet diff --git a/core/src/test/scala/mill/JavaCompileJarTests.scala b/core/src/test/scala/mill/JavaCompileJarTests.scala index e19073a4..3e470b9d 100644 --- a/core/src/test/scala/mill/JavaCompileJarTests.scala +++ b/core/src/test/scala/mill/JavaCompileJarTests.scala @@ -30,7 +30,7 @@ object JavaCompileJarTests extends TestSuite{ mkdir(pwd / 'target / 'workspace / 'javac) cp(javacSrcPath, javacDestPath) - object Build extends Task.Module{ + object Build extends Module{ def sourceRootPath = javacDestPath / 'src def resourceRootPath = javacDestPath / 'resources @@ -41,7 +41,7 @@ object JavaCompileJarTests extends TestSuite{ def sourceRoot = T.source{ sourceRootPath } def resourceRoot = T.source{ resourceRootPath } def allSources = T{ ls.rec(sourceRoot().path).map(PathRef(_)) } - def classFiles = T{ compileAll(Task.ctx().dest, allSources()) } + def classFiles = T{ compileAll(T.ctx().dest, allSources()) } def jar = T{ jarUp(resourceRoot, classFiles) } def run(mainClsName: String) = T.command{ @@ -164,7 +164,6 @@ object JavaCompileJarTests extends TestSuite{ evalCount3 == 1 ) - } } } diff --git a/core/src/test/scala/mill/TestGraphs.scala b/core/src/test/scala/mill/TestGraphs.scala index 1e69fc0b..094496c1 100644 --- a/core/src/test/scala/mill/TestGraphs.scala +++ b/core/src/test/scala/mill/TestGraphs.scala @@ -1,6 +1,5 @@ package mill -import mill.define.Task.Module import mill.TestUtil.test class TestGraphs(){ |