diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-26 17:53:47 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-26 18:31:40 -0800 |
commit | 8986f9755a026691d1839bac806b0b75c2e3e74d (patch) | |
tree | 240c4acf7f0fd23676f0da2c1f08d0b56b43d95e /core/src/mill/define/Task.scala | |
parent | 11c194da920cd6a4196ddfbb875c0d1faa47fcff (diff) | |
download | mill-8986f9755a026691d1839bac806b0b75c2e3e74d.tar.gz mill-8986f9755a026691d1839bac806b0b75c2e3e74d.tar.bz2 mill-8986f9755a026691d1839bac806b0b75c2e3e74d.zip |
Fix `dest`-assignment for overriden `T.command`s, and add basic unit tests to validate the `dest` paths of overriden commands and overriden targets
Diffstat (limited to 'core/src/mill/define/Task.scala')
-rw-r--r-- | core/src/mill/define/Task.scala | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/core/src/mill/define/Task.scala b/core/src/mill/define/Task.scala index a6d90922..f74171ec 100644 --- a/core/src/mill/define/Task.scala +++ b/core/src/mill/define/Task.scala @@ -1,13 +1,26 @@ package mill.define +import ammonite.main.Router.Overrides import mill.define.Applicative.Applyable import mill.eval.{PathRef, Result} - +import sourcecode.Compat.Context import upickle.default.{ReadWriter => RW, Reader => R, Writer => W} import scala.language.experimental.macros import scala.reflect.macros.blackbox.Context +case class EnclosingClass(value: Class[_]) +object EnclosingClass{ + def apply()(implicit c: EnclosingClass) = c.value + implicit def generate: EnclosingClass = macro impl + def impl(c: Context): c.Tree = { + import c.universe._ + val cls = c.internal.enclosingOwner.owner.asType.asClass +// q"new _root_.mill.define.EnclosingClass(classOf[$cls])" + q"new _root_.mill.define.EnclosingClass(this.getClass)" + } +} + /** * Models a single node in the Mill build graph, with a list of inputs and a * single output of type [[T]]. @@ -164,19 +177,33 @@ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Resul def command[T](t: Task[T]) (implicit ctx: mill.define.Ctx, - w: W[T]): Command[T] = new Command(t, ctx, w) + w: W[T], + cls: EnclosingClass, + overrides: Overrides): Command[T] = { + new Command(t, ctx, w, cls.value, overrides.value) + } def command[T](t: Result[T]) (implicit w: W[T], - ctx: mill.define.Ctx): Command[T] = macro commandImpl[T] + ctx: mill.define.Ctx, + cls: EnclosingClass, + overrides: Overrides): Command[T] = macro commandImpl[T] def commandImpl[T: c.WeakTypeTag](c: Context) (t: c.Expr[T]) (w: c.Expr[W[T]], - ctx: c.Expr[mill.define.Ctx]): c.Expr[Command[T]] = { + ctx: c.Expr[mill.define.Ctx], + cls: c.Expr[EnclosingClass], + overrides: c.Expr[Overrides]): c.Expr[Command[T]] = { import c.universe._ reify( - new Command[T](Applicative.impl[Task, T, mill.util.Ctx](c)(t).splice, ctx.splice, w.splice) + new Command[T]( + Applicative.impl[Task, T, mill.util.Ctx](c)(t).splice, + ctx.splice, + w.splice, + cls.splice.value, + overrides.splice.value + ) ) } @@ -255,7 +282,9 @@ class TargetImpl[+T](t: Task[T], class Command[+T](t: Task[T], ctx0: mill.define.Ctx, - val writer: W[_]) extends NamedTaskImpl[T](ctx0, t) { + val writer: W[_], + val cls: Class[_], + val overrides: Int) extends NamedTaskImpl[T](ctx0, t) { override def asCommand = Some(this) } |