diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/src/mill/define/Task.scala | 63 | ||||
-rw-r--r-- | core/src/mill/main/MainRunner.scala | 1 | ||||
-rw-r--r-- | core/src/mill/main/RunScript.scala | 3 | ||||
-rw-r--r-- | core/test/resources/examples/javac/build.sc | 8 | ||||
-rw-r--r-- | core/test/src/mill/eval/JavaCompileJarTests.scala | 10 |
5 files changed, 55 insertions, 30 deletions
diff --git a/core/src/mill/define/Task.scala b/core/src/mill/define/Task.scala index a94d9703..230089bf 100644 --- a/core/src/mill/define/Task.scala +++ b/core/src/mill/define/Task.scala @@ -126,32 +126,47 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul ) } - def source(value: Result[ammonite.ops.Path]) - (implicit r: R[PathRef], - w: W[PathRef], - ctx: mill.define.Ctx): Input[PathRef] = macro sourceImpl - - def sourceImpl(c: Context) - (value: c.Expr[Result[ammonite.ops.Path]]) - (r: c.Expr[R[PathRef]], - w: c.Expr[W[PathRef]], - ctx: c.Expr[mill.define.Ctx]): c.Expr[Input[PathRef]] = { + def sources(values: Result[ammonite.ops.Path]*) + (implicit ctx: mill.define.Ctx): Sources = macro sourcesImpl1 + + def sourcesImpl1(c: Context) + (values: c.Expr[Result[ammonite.ops.Path]]*) + (ctx: c.Expr[mill.define.Ctx]): c.Expr[Sources] = { import c.universe._ - val wrapped: c.Expr[Result[PathRef]] = reify(value.splice match{ - case Result.Success(p) => Result.Success(PathRef(p)) - case x: Result.Failing => x - }) - mill.moduledefs.Cacher.impl0[Input[PathRef]](c)( + val wrapped = + for (value <- values.toList) + yield Applicative.impl0[Task, PathRef, mill.util.Ctx](c)( + reify(value.splice.map(PathRef(_))).tree + ).tree + + mill.moduledefs.Cacher.impl0[Sources](c)( reify( - new Input[PathRef]( - Applicative.impl0[Task, PathRef, mill.util.Ctx](c)(wrapped.tree).splice, - ctx.splice, - RW(w.splice.write, r.splice.read), + new Sources( + Task.sequence(c.Expr[List[Task[PathRef]]](q"scala.List(..$wrapped)").splice), + ctx.splice ) ) ) } + def sources(values: Result[Seq[PathRef]]) + (implicit ctx: mill.define.Ctx): Sources = macro sourcesImpl2 + + def sourcesImpl2(c: Context) + (values: c.Expr[Result[Seq[PathRef]]]) + (ctx: c.Expr[mill.define.Ctx]): c.Expr[Sources] = { + import c.universe._ + + + mill.moduledefs.Cacher.impl0[Sources](c)( + reify( + new Sources( + Applicative.impl0[Task, Seq[PathRef], mill.util.Ctx](c)(values.tree).splice, + ctx.splice + ) + ) + ) + } def input[T](value: Result[T]) (implicit r: R[T], w: W[T], @@ -305,7 +320,15 @@ class Input[T](t: Task[T], val readWrite: RW[_]) extends NamedTaskImpl[T](ctx0, t) with Target[T]{ override def sideHash = util.Random.nextInt() } - +class Sources(t: Task[Seq[PathRef]], + ctx0: mill.define.Ctx) extends Input[Seq[PathRef]]( + t, + ctx0, + RW( + upickle.default.SeqishW[PathRef, Seq].write, + upickle.default.SeqishR[Seq, PathRef].read + ) +) object Task { class Task0[T](t: T) extends Task[T]{ diff --git a/core/src/mill/main/MainRunner.scala b/core/src/mill/main/MainRunner.scala index 06e1795f..e3820e3d 100644 --- a/core/src/mill/main/MainRunner.scala +++ b/core/src/mill/main/MainRunner.scala @@ -24,6 +24,7 @@ class MainRunner(config: ammonite.main.Cli.Config, config, outprintStream, errPrintStream, stdIn, outprintStream, errPrintStream ){ + var lastEvaluator: Option[(Seq[(Path, Long)], Evaluator[Any])] = None override def runScript(scriptPath: Path, scriptArgs: List[String]) = diff --git a/core/src/mill/main/RunScript.scala b/core/src/mill/main/RunScript.scala index e5c92e3e..a05c7623 100644 --- a/core/src/mill/main/RunScript.scala +++ b/core/src/mill/main/RunScript.scala @@ -161,8 +161,9 @@ object RunScript{ val watched = evaluated.results .iterator .collect { - case (t: define.Input[_], Result.Success(p: PathRef)) => p + case (t: define.Sources, Result.Success(p: Seq[PathRef])) => p } + .flatten .toSeq val errorStr = diff --git a/core/test/resources/examples/javac/build.sc b/core/test/resources/examples/javac/build.sc index 8f250014..0783ac17 100644 --- a/core/test/resources/examples/javac/build.sc +++ b/core/test/resources/examples/javac/build.sc @@ -12,11 +12,11 @@ def resourceRootPath = millSourcePath / 'resources // | // v // resourceRoot ----> jar -def sourceRoot = T.source{ sourceRootPath } -def resourceRoot = T.source{ resourceRootPath } -def allSources = T{ ls.rec(sourceRoot().path).map(PathRef(_)) } +def sourceRoot = T.sources{ sourceRootPath } +def resourceRoot = T.sources{ resourceRootPath } +def allSources = T{ sourceRoot().flatMap(p => ls.rec(p.path)).map(PathRef(_)) } def classFiles = T{ compileAll(allSources()) } -def jar = T{ Jvm.createJar(Loose.Agg(resourceRoot().path, classFiles().path)) } +def jar = T{ Jvm.createJar(Loose.Agg(classFiles().path) ++ resourceRoot().map(_.path)) } def run(mainClsName: String) = T.command{ %%('java, "-cp", classFiles().path, mainClsName)(T.ctx().dest) diff --git a/core/test/src/mill/eval/JavaCompileJarTests.scala b/core/test/src/mill/eval/JavaCompileJarTests.scala index a67d669d..71feebda 100644 --- a/core/test/src/mill/eval/JavaCompileJarTests.scala +++ b/core/test/src/mill/eval/JavaCompileJarTests.scala @@ -35,11 +35,11 @@ object JavaCompileJarTests extends TestSuite{ // | // v // resourceRoot ----> jar - def sourceRoot = T.source{ sourceRootPath } - def resourceRoot = T.source{ resourceRootPath } - def allSources = T{ ls.rec(sourceRoot().path).map(PathRef(_)) } + def sourceRoot = T.sources{ sourceRootPath } + def resourceRoot = T.sources{ resourceRootPath } + def allSources = T{ sourceRoot().flatMap(p => ls.rec(p.path)).map(PathRef(_)) } def classFiles = T{ compileAll(allSources()) } - def jar = T{ Jvm.createJar(Loose.Agg(resourceRoot().path, classFiles().path)) } + def jar = T{ Jvm.createJar(Loose.Agg(classFiles().path) ++ resourceRoot().map(_.path)) } def run(mainClsName: String) = T.command{ %%('java, "-cp", classFiles().path, mainClsName) @@ -108,12 +108,12 @@ object JavaCompileJarTests extends TestSuite{ val jarContents = %%('jar, "-tf", evaluator.outPath/'jar/'dest/"out.jar")(evaluator.outPath).out.string val expectedJarContents = """META-INF/MANIFEST.MF - |hello.txt |test/Bar.class |test/BarThree.class |test/BarTwo.class |test/Foo.class |test/FooTwo.class + |hello.txt |""".stripMargin assert(jarContents == expectedJarContents) |