Merge pull request #3076 from eed3si9n/fport/2908

[fport] Fix triggeredBy/storeAs/etc using :=
This commit is contained in:
eugene yokota 2017-04-04 20:08:05 -07:00 committed by GitHub
commit 42b8da18c3
5 changed files with 44 additions and 6 deletions

View File

@ -18,7 +18,7 @@ object TaskInstance extends MonadInstance {
import TaskExtra._
final type M[x] = Task[x]
def app[K[L[x]], Z](in: K[Task], f: K[Id] => Z)(implicit a: AList[K]): Task[Z] = Task(Info(), new Mapped[Z, K](in, f compose allM, a))
def app[K[L[x]], Z](in: K[Task], f: K[Id] => Z)(implicit a: AList[K]): Task[Z] = in map f
def map[S, T](in: Task[S], f: S => T): Task[T] = in map f
def flatten[T](in: Task[Task[T]]): Task[T] = in flatMap idFun[Task[T]]
def pure[T](t: () => T): Task[T] = toTask(t)

View File

@ -14,7 +14,7 @@ lazy val d = taskKey[Unit]("")
lazy val input = (project in file("input")).
settings(
f := (inputTask { _ map { args => if (args(0) == "succeed") () else sys.error("fail") } }).evaluated,
f := (if (Def.spaceDelimited().parsed.head == "succeed") () else sys.error("fail")),
j := sys.error("j"),
g := (f dependsOn(j)).evaluated,
h := (f map { _ => IO.touch(file("h")) }).evaluated

View File

@ -0,0 +1,26 @@
val taskA = taskKey[File]("")
val taskB = taskKey[File]("")
val taskE = taskKey[File]("")
val taskF = taskKey[File]("")
taskA := touch(target.value / "a")
taskB := touch(target.value / "b")
taskE := touch(target.value / "e")
taskF := touch(target.value / "f")
// 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).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).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
> taskF
$ exists target/e
$ exists target/f

View File

@ -6,7 +6,7 @@ package std
import scala.sys.process.{ BasicIO, ProcessIO, ProcessBuilder }
import sbt.internal.util.AList
import sbt.internal.util.{ AList, AttributeMap }
import sbt.internal.util.Types._
import java.io.{ BufferedInputStream, BufferedReader, File, InputStream }
import sbt.io.IO
@ -120,9 +120,14 @@ trait TaskExtra {
def failure: Task[Incomplete] = mapFailure(idFun)
def result: Task[Result[S]] = mapR(idFun)
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 dependsOn(tasks: Task[_]*): Task[S] = Task(Info(), new DependsOn(in, tasks))
// The "taskDefinitionKey" is used, at least, by the ".previous" functionality.
// But apparently it *cannot* survive a task map/flatMap/etc. See actions/depends-on.
private def newInfo[A]: Info[A] =
Info[A](AttributeMap(in.info.attributes.entries.filter(_.key.label != "taskDefinitionKey")))
def flatMapR[T](f: Result[S] => Task[T]): Task[T] = Task(newInfo, 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))
def dependsOn(tasks: Task[_]*): Task[S] = Task(newInfo, new DependsOn(in, tasks))
def flatMap[T](f: S => Task[T]): Task[T] = flatMapR(f compose successM)
def flatFailure[T](f: Incomplete => Task[T]): Task[T] = flatMapR(f compose failM)