Fix runBefore with :=

This commit is contained in:
Dale Wijnand 2017-01-12 14:41:12 +00:00
parent 9bad462f7a
commit 2404d609ce
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
4 changed files with 37 additions and 11 deletions

View File

@ -3,11 +3,21 @@ val taskB = taskKey[File]("")
val taskC = taskKey[File]("")
val taskD = taskKey[File]("")
val taskE = taskKey[File]("")
val taskF = taskKey[File]("")
val taskG = taskKey[File]("")
val taskH = taskKey[File]("")
taskA := touch(target.value / "a")
taskB := touch(target.value / "b")
taskC := touch(target.value / "c")
taskD := touch(target.value / "d")
taskE := touch(target.value / "e")
taskF := touch(target.value / "f")
taskG := touch(target.value / "g")
taskH := touch(target.value / "h")
// a <<= a triggeredBy b
// means "a" will be triggered by "b"
// said differently, invoking "b" will run "b" and then run "a"
@ -15,6 +25,13 @@ taskD := touch(target.value / "d")
taskA <<= taskA triggeredBy taskB
taskC := (taskC triggeredBy taskD).value
// e <<= e runBefore f
// means "e" will be run before running "f"
// said differently, invoking "f" will run "e" and then run "f"
taskE <<= taskE runBefore taskF
taskG := (taskG runBefore taskH).value
// test utils

View File

@ -0,0 +1,15 @@
> taskB
$ exists target/b
$ exists target/a
> taskD
$ exists target/d
$ exists target/c
> taskF
$ exists target/e
$ exists target/f
> taskH
$ exists target/g
$ exists target/h

View File

@ -1,7 +0,0 @@
> taskB
$ exists target/b
$ exists target/a
> taskD
$ exists target/d
$ exists target/c

View File

@ -118,10 +118,11 @@ trait TaskExtra {
def result: Task[Result[S]] = mapR(idFun)
private val triggeredByKey = AttributeKey[Seq[Task[_]]]("triggered-by")
private def newInfo[A]: Info[A] = {
val i = Info[A]()
(in.info get triggeredByKey).fold(i)(i.set(triggeredByKey, _))
}
private val runBeforeKey = AttributeKey[Seq[Task[_]]]("run-before")
private def newInfo[A]: Info[A] =
Seq(triggeredByKey, runBeforeKey)
.flatMap(k => (in.info get k) map (k -> _))
.foldLeft(Info[A]()) { case (i, (k, v)) => i.set(k, v) }
def flatMapR[T](f: Result[S] => Task[T]): Task[T] = Task(Info(), new FlatMapped[T, K](in, f, ml))
def mapR[T](f: Result[S] => T): Task[T] = Task(newInfo, new Mapped[T, K](in, f, ml))