mirror of https://github.com/sbt/sbt.git
Fix triggeredBy and runBefore
This commit is contained in:
parent
e2c7a294f8
commit
654d35d1ba
|
|
@ -398,27 +398,18 @@ object Index {
|
|||
def triggers(ss: Settings[Scope]): Triggers = {
|
||||
val runBefore = new TriggerMap
|
||||
val triggeredBy = new TriggerMap
|
||||
ss.data.values foreach (
|
||||
_.entries foreach {
|
||||
case AttributeEntry(_, value: Task[?]) =>
|
||||
val as = value.info.attributes
|
||||
update(runBefore, value, as.get(Def.runBefore.asInstanceOf))
|
||||
update(triggeredBy, value, as.get(Def.triggeredBy.asInstanceOf))
|
||||
case _ => ()
|
||||
}
|
||||
)
|
||||
val onComplete = (GlobalScope / Def.onComplete) get ss getOrElse (() => ())
|
||||
for
|
||||
a <- ss.data.values
|
||||
case AttributeEntry(_, base: Task[?]) <- a.entries
|
||||
do
|
||||
def update(map: TriggerMap, key: AttributeKey[Seq[Task[?]]]): Unit =
|
||||
base.info.attributes.get(key).getOrElse(Seq.empty).foreach { task =>
|
||||
map(task) = base +: map.getOrElse(task, Nil)
|
||||
}
|
||||
update(runBefore, Def.runBefore)
|
||||
update(triggeredBy, Def.triggeredBy)
|
||||
val onComplete = (GlobalScope / Def.onComplete).get(ss).getOrElse(() => ())
|
||||
new Triggers(runBefore, triggeredBy, map => { onComplete(); map })
|
||||
}
|
||||
|
||||
private[this] def update(
|
||||
map: TriggerMap,
|
||||
base: Task[?],
|
||||
tasksOpt: Option[Seq[Task[?]]]
|
||||
): Unit =
|
||||
for {
|
||||
tasks <- tasksOpt
|
||||
task <- tasks
|
||||
}
|
||||
map(task) = base +: map.getOrElse(task, Nil)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,13 +25,6 @@ object InitializeInstance:
|
|||
Def.flatMap[A1, A2](fa)(f)
|
||||
end InitializeInstance
|
||||
|
||||
private[std] object ComposeInstance:
|
||||
import InitializeInstance.initializeMonad
|
||||
val InitInstance = summon[Applicative[Initialize]]
|
||||
val F1F2: Applicative[[a] =>> Initialize[Task[a]]] =
|
||||
summon[Applicative[[a] =>> Initialize[Task[a]]]]
|
||||
end ComposeInstance
|
||||
|
||||
object ParserInstance:
|
||||
type F1[x] = State => Parser[x]
|
||||
// import sbt.internal.util.Classes.Applicative
|
||||
|
|
@ -59,11 +52,17 @@ object FullInstance:
|
|||
KeyRanks.DTask
|
||||
)
|
||||
|
||||
given Monad[Initialize] = InitializeInstance.initializeMonad
|
||||
val F1F2: Applicative[[a] =>> Initialize[Task[a]]] = ComposeInstance.F1F2
|
||||
val F1F2: Applicative[[a] =>> Initialize[Task[a]]] = Applicative.given_Applicative_F1(using
|
||||
InitializeInstance.initializeMonad,
|
||||
Task.taskMonad
|
||||
)
|
||||
given initializeTaskMonad: Monad[[a] =>> Initialize[Task[a]]] with
|
||||
type F[x] = Initialize[Task[x]]
|
||||
override def pure[A1](x: () => A1): Initialize[Task[A1]] = F1F2.pure(x)
|
||||
|
||||
override def map[A1, A2](fa: Initialize[Task[A1]])(f: A1 => A2): Initialize[Task[A2]] =
|
||||
F1F2.map(fa)(f)
|
||||
|
||||
override def ap[A1, A2](ff: Initialize[Task[A1 => A2]])(
|
||||
fa: Initialize[Task[A1]]
|
||||
): Initialize[Task[A2]] =
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ val taskB = taskKey[File]("")
|
|||
val taskE = taskKey[File]("")
|
||||
val taskF = taskKey[File]("")
|
||||
|
||||
scalaVersion := "3.3.1"
|
||||
name := "task-map"
|
||||
taskA := touch(target.value / "a")
|
||||
taskB := touch(target.value / "b")
|
||||
|
||||
|
|
@ -14,13 +16,13 @@ taskF := touch(target.value / "f")
|
|||
// means "a" will be triggered by "b"
|
||||
// said differently, invoking "b" will run "b" and then run "a"
|
||||
|
||||
taskA := (taskA triggeredBy taskB).value
|
||||
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
|
||||
taskE := taskE.runBefore(taskF).value
|
||||
|
||||
// test utils
|
||||
def touch(f: File): File = { IO.touch(f); f }
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
> taskB
|
||||
$ exists target/b
|
||||
$ exists target/a
|
||||
|
||||
> taskF
|
||||
$ exists target/e
|
||||
$ exists target/f
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
> taskB
|
||||
$ exists target/out/jvm/scala-3.3.1/task-map/b
|
||||
$ exists target/out/jvm/scala-3.3.1/task-map/a
|
||||
|
||||
> taskF
|
||||
$ exists target/out/jvm/scala-3.3.1/task-map/e
|
||||
$ exists target/out/jvm/scala-3.3.1/task-map/f
|
||||
|
|
@ -40,7 +40,7 @@ abstract class EvaluateSettings[ScopeType]:
|
|||
case k: Keyed[s, A] => single(getStatic(k.scopedKey), k.transform)
|
||||
case u: Uniform[s, A] => UniformNode(u.inputs.map(transform[s]), u.f)
|
||||
case a: Apply[k, A] =>
|
||||
MixedNode[k, A](TupleMapExtension.transform(a.inputs) { transform }, a.f)
|
||||
MixedNode[k, A](TupleMapExtension.transform(a.inputs)(transform), a.f)
|
||||
case b: Bind[s, A] => BindNode[s, A](transform(b.in), x => transform(b.f(x)))
|
||||
case v: Value[A] => constant(v.value)
|
||||
case v: ValidationCapture[a] => strictConstant(v.key: A)
|
||||
|
|
@ -89,8 +89,7 @@ abstract class EvaluateSettings[ScopeType]:
|
|||
|
||||
private[this] def submit(work: => Unit): Unit =
|
||||
startWork()
|
||||
// new Runnable { def run = if (!cancel.get()) run0(work) }
|
||||
executor.execute(() => if !cancel.get() then run0(work) else ())
|
||||
executor.execute(() => if !cancel.get() then run0(work))
|
||||
|
||||
private[this] def run0(work: => Unit): Unit =
|
||||
try {
|
||||
|
|
@ -102,7 +101,6 @@ abstract class EvaluateSettings[ScopeType]:
|
|||
|
||||
private[this] def workComplete(): Unit =
|
||||
if running.decrementAndGet() == 0 then complete.put(None)
|
||||
else ()
|
||||
|
||||
private[this] sealed abstract class INode[A1]:
|
||||
private[this] var state: EvaluationState = New
|
||||
|
|
@ -116,9 +114,12 @@ abstract class EvaluateSettings[ScopeType]:
|
|||
keyString
|
||||
|
||||
private[this] def keyString =
|
||||
(static.toSeq.flatMap { case (key, value) =>
|
||||
if (value eq this) init.showFullKey.show(key) :: Nil else List.empty[String]
|
||||
}).headOption getOrElse "non-static"
|
||||
static.toSeq
|
||||
.flatMap { case (key, value) =>
|
||||
if (value eq this) init.showFullKey.show(key) :: Nil else Nil
|
||||
}
|
||||
.headOption
|
||||
.getOrElse("non-static")
|
||||
|
||||
final def get: A1 = synchronized {
|
||||
assert(value != null, toString + " not evaluated")
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ object Applicative:
|
|||
val F1 = summon[Applicative[F1]]
|
||||
val F2 = summon[Applicative[F2]]
|
||||
override def pure[A1](x: () => A1): F1[F2[A1]] = F1.pure(() => F2.pure(x))
|
||||
override def map[A1, A2](fa: F1[F2[A1]])(f: A1 => A2): F1[F2[A2]] =
|
||||
F1.map(fa)(f2 => F2.map(f2)(f))
|
||||
override def ap[A1, A2](f1f2f: F1[F2[A1 => A2]])(f1f2a: F1[F2[A1]]): F1[F2[A2]] =
|
||||
F1.ap(F1.map(f1f2f) { (f2f: F2[A1 => A2]) => (f2a: F2[A1]) => F2.ap(f2f)(f2a) })(f1f2a)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue