Fix triggeredBy with :=

Fixes #1444
This commit is contained in:
Dale Wijnand 2017-01-11 17:06:05 +00:00
parent 4e267e5cb5
commit 88ded6cb21
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
3 changed files with 35 additions and 1 deletions

View File

@ -0,0 +1,21 @@
val taskA = taskKey[File]("")
val taskB = taskKey[File]("")
val taskC = taskKey[File]("")
val taskD = taskKey[File]("")
taskA := touch(target.value / "a")
taskB := touch(target.value / "b")
taskC := touch(target.value / "c")
taskD := touch(target.value / "d")
// a <<= a triggeredBy b
// means "a" will be triggered by "b"
// said differently, invoking "b" will run "b" and then run "a"
taskA <<= taskA triggeredBy taskB
taskC := (taskC triggeredBy taskD).value
// test utils
def touch(f: File): File = { IO touch f; f }

View File

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

View File

@ -120,8 +120,14 @@ trait TaskExtra {
def failure: Task[Incomplete] = mapFailure(idFun)
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, _))
}
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(Info(), new Mapped[T, K](in, f, ml))
def mapR[T](f: Result[S] => T): Task[T] = Task(newInfo, new Mapped[T, K](in, f, ml))
def dependsOn(tasks: Task[_]*): Task[S] = Task(Info(), new DependsOn(in, tasks))
def flatMap[T](f: S => Task[T]): Task[T] = flatMapR(f compose successM)