summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2017-12-29 08:36:42 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2017-12-29 08:36:42 -0800
commit3d5bb4f9fcbe7aec00b80e0195afe9184bbc30c0 (patch)
treef7f8183d7a3e61390abb51af76583f83559ee198 /core/src
parent23cef1eccce3030166a6731823fc78d67b345261 (diff)
downloadmill-3d5bb4f9fcbe7aec00b80e0195afe9184bbc30c0.tar.gz
mill-3d5bb4f9fcbe7aec00b80e0195afe9184bbc30c0.tar.bz2
mill-3d5bb4f9fcbe7aec00b80e0195afe9184bbc30c0.zip
Tidy up Task.scala macros...
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/scala/mill/define/Task.scala84
-rw-r--r--core/src/test/scala/mill/define/MacroErrorTests.scala2
2 files changed, 65 insertions, 21 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)
diff --git a/core/src/test/scala/mill/define/MacroErrorTests.scala b/core/src/test/scala/mill/define/MacroErrorTests.scala
index 7fc79f62..fd0116d8 100644
--- a/core/src/test/scala/mill/define/MacroErrorTests.scala
+++ b/core/src/test/scala/mill/define/MacroErrorTests.scala
@@ -30,7 +30,7 @@ object MacroErrorTests extends TestSuite{
}
}
""")
- assert(e.msg.contains("must be defs"))
+ assert(e.msg.contains("required: mill.define.Task.Module"))
}
'neg - {