diff options
Diffstat (limited to 'core/src/main')
-rw-r--r-- | core/src/main/scala/mill/define/Task.scala | 84 |
1 files changed, 64 insertions, 20 deletions
diff --git a/core/src/main/scala/mill/define/Task.scala b/core/src/main/scala/mill/define/Task.scala index a5007d45..2b488037 100644 --- a/core/src/main/scala/mill/define/Task.scala +++ b/core/src/main/scala/mill/define/Task.scala @@ -44,69 +44,110 @@ trait Target[+T] extends NamedTask[T]{ object Target extends TargetGenerated with Applicative.Applyer[Task, Task, Result, Ctx] { - implicit def apply[T](t: T)(implicit r: R[T], w: W[T]): Target[T] = macro targetImpl[T] - - implicit def apply[T](t: Result[T])(implicit r: R[T], w: W[T]): Target[T] = macro targetResultImpl[T] - - def apply[T](t: Task[T])(implicit r: R[T], w: W[T]): Target[T] = macro targetTaskImpl[T] - - def command[T](t: Result[T]): Command[T] = macro commandImpl[T] + implicit def apply[T](t: T) + (implicit r: R[T], + w: W[T], + e: sourcecode.Enclosing, + n: sourcecode.Name, + cl: Caller[mill.define.Task.Module]): Target[T] = macro targetImpl[T] + + implicit def apply[T](t: Result[T]) + (implicit r: R[T], + w: W[T], + e: sourcecode.Enclosing, + n: sourcecode.Name, + cl: Caller[mill.define.Task.Module]): Target[T] = macro targetResultImpl[T] + + def apply[T](t: Task[T]) + (implicit r: R[T], + w: W[T], + e: sourcecode.Enclosing, + n: sourcecode.Name, + cl: Caller[mill.define.Task.Module]): Target[T] = macro targetTaskImpl[T] + + def command[T](t: Result[T])(implicit w: W[T]): Command[T] = macro commandImpl[T] def source(path: ammonite.ops.Path) = new Source(path) - def command[T](t: Task[T])(implicit c: Caller[Task.Module], n: sourcecode.Name): Command[T] = new Command(t, c.value, n.value) + def command[T](t: Task[T]) + (implicit c: Caller[Task.Module], + n: sourcecode.Name, + w: W[T]): Command[T] = new Command(t, c.value, n.value, w) def task[T](t: Result[T]): Task[T] = macro Applicative.impl[Task, T, Ctx] def task[T](t: Task[T]): Task[T] = t - def persistent[T](t: Result[T])(implicit r: R[T], w: W[T]): Target[T] = macro persistentImpl[T] + def persistent[T](t: Result[T])(implicit r: R[T], + w: W[T], + e: sourcecode.Enclosing, + n: sourcecode.Name, + cl: Caller[mill.define.Task.Module]): Target[T] = macro persistentImpl[T] + def persistentImpl[T: c.WeakTypeTag](c: Context) (t: c.Expr[T]) - (r: c.Expr[R[T]], w: c.Expr[W[T]]): c.Expr[Persistent[T]] = { + (r: c.Expr[R[T]], + w: c.Expr[W[T]], + e: c.Expr[sourcecode.Enclosing], + n: c.Expr[sourcecode.Name], + cl: c.Expr[Caller[mill.define.Task.Module]]): c.Expr[Persistent[T]] = { import c.universe._ c.Expr[Persistent[T]]( mill.plugin.Cacher.wrapCached(c)( - q"new ${weakTypeOf[Persistent[T]]}(${Applicative.impl[Task, T, Ctx](c)(t).tree}, _root_.sourcecode.Enclosing(), _root_.mill.define.Caller[mill.define.Task.Module](), _root_.sourcecode.Name(), upickle.default.ReadWriter($w.write, $r.read))" + q"new ${weakTypeOf[Persistent[T]]}(${Applicative.impl[Task, T, Ctx](c)(t).tree}, $e.value, $cl.value, $n.value, upickle.default.ReadWriter($w.write, $r.read))" ) ) } - def commandImpl[T: c.WeakTypeTag](c: Context)(t: c.Expr[T]): c.Expr[Command[T]] = { + def commandImpl[T: c.WeakTypeTag](c: Context) + (t: c.Expr[T]) + (w: c.Expr[W[T]]): c.Expr[Command[T]] = { import c.universe._ c.Expr[Command[T]]( - q"new ${weakTypeOf[Command[T]]}(${Applicative.impl[Task, T, Ctx](c)(t).tree}, _root_.mill.define.Caller[mill.define.Task.Module](), _root_.sourcecode.Name())" + q"new ${weakTypeOf[Command[T]]}(${Applicative.impl[Task, T, Ctx](c)(t).tree}, _root_.mill.define.Caller[mill.define.Task.Module](), _root_.sourcecode.Name(), $w)" ) } def targetTaskImpl[T: c.WeakTypeTag](c: Context) (t: c.Expr[Task[T]]) - (r: c.Expr[R[T]], w: c.Expr[W[T]]): c.Expr[Target[T]] = { + (r: c.Expr[R[T]], + w: c.Expr[W[T]], + e: c.Expr[sourcecode.Enclosing], + n: c.Expr[sourcecode.Name], + cl: c.Expr[Caller[mill.define.Task.Module]]): c.Expr[Target[T]] = { import c.universe._ c.Expr[Target[T]]( mill.plugin.Cacher.wrapCached(c)( - q"new ${weakTypeOf[TargetImpl[T]]}($t, _root_.sourcecode.Enclosing(), _root_.mill.define.Caller[mill.define.Task.Module](), _root_.sourcecode.Name(), upickle.default.ReadWriter($w.write, $r.read))" + q"new ${weakTypeOf[TargetImpl[T]]}($t, $e.value, $cl.value, $n.value, upickle.default.ReadWriter($w.write, $r.read))" ) ) } def targetImpl[T: c.WeakTypeTag](c: Context) (t: c.Expr[T]) - (r: c.Expr[R[T]], w: c.Expr[W[T]]): c.Expr[Target[T]] = { + (r: c.Expr[R[T]], + w: c.Expr[W[T]], + e: c.Expr[sourcecode.Enclosing], + n: c.Expr[sourcecode.Name], + cl: c.Expr[Caller[mill.define.Task.Module]]): c.Expr[Target[T]] = { import c.universe._ c.Expr[Target[T]]( mill.plugin.Cacher.wrapCached(c)( - q"new ${weakTypeOf[TargetImpl[T]]}(${Applicative.impl0[Task, T, Ctx](c)(q"mill.eval.Result.Success($t)").tree}, _root_.sourcecode.Enclosing(), _root_.mill.define.Caller[mill.define.Task.Module](), _root_.sourcecode.Name(), upickle.default.ReadWriter($w.write, $r.read))" + q"new ${weakTypeOf[TargetImpl[T]]}(${Applicative.impl0[Task, T, Ctx](c)(q"mill.eval.Result.Success($t)").tree}, $e.value, $cl.value, $n.value, upickle.default.ReadWriter($w.write, $r.read))" ) ) } def targetResultImpl[T: c.WeakTypeTag](c: Context) (t: c.Expr[Result[T]]) - (r: c.Expr[R[T]], w: c.Expr[W[T]]): c.Expr[Target[T]] = { + (r: c.Expr[R[T]], + w: c.Expr[W[T]], + e: c.Expr[sourcecode.Enclosing], + n: c.Expr[sourcecode.Name], + cl: c.Expr[Caller[mill.define.Task.Module]]): c.Expr[Target[T]] = { import c.universe._ c.Expr[Target[T]]( mill.plugin.Cacher.wrapCached(c)( - q"new ${weakTypeOf[TargetImpl[T]]}(${Applicative.impl0[Task, T, Ctx](c)(t.tree).tree}, _root_.sourcecode.Enclosing(), _root_.mill.define.Caller[mill.define.Task.Module](), _root_.sourcecode.Name(), upickle.default.ReadWriter($w.write, $r.read))" + q"new ${weakTypeOf[TargetImpl[T]]}(${Applicative.impl0[Task, T, Ctx](c)(t.tree).tree}, $e.value, $cl.value, $n.value, upickle.default.ReadWriter($w.write, $r.read))" ) ) } @@ -142,7 +183,10 @@ class TargetImpl[+T](t: Task[T], def evaluate(args: Ctx) = args[T](0) override def toString = enclosing + "@" + Integer.toHexString(System.identityHashCode(this)) } -class Command[+T](t: Task[T], val owner: Task.Module, val name: String) extends NamedTask[T] { +class Command[+T](t: Task[T], + val owner: Task.Module, + val name: String, + val writer: W[_]) extends NamedTask[T] { val inputs = Seq(t) def evaluate(args: Ctx) = args[T](0) override def asCommand = Some(this) |