mirror of https://github.com/sbt/sbt.git
Use referential equality on Task
This commit is contained in:
parent
e5cedbe56b
commit
d54647a46c
|
|
@ -582,8 +582,8 @@ object EvaluateTask {
|
|||
Function.chain(
|
||||
results.toTypedSeq flatMap {
|
||||
case results.TPair(_, Result.Value(KeyValue(_, st: StateTransform))) => Some(st.transform)
|
||||
case results.TPair(Task(_, post, _), Result.Value(v)) => post(v).get(transformState)
|
||||
case _ => Nil
|
||||
case results.TPair(task: Task[?], Result.Value(v)) => task.post(v).get(transformState)
|
||||
case _ => Nil
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -16,21 +16,25 @@ import sbt.util.Monad
|
|||
/**
|
||||
* Combines metadata `attributes` and a computation `work` to define a task.
|
||||
*/
|
||||
final case class Task[A](attributes: AttributeMap, post: A => AttributeMap, work: Action[A])
|
||||
extends TaskId[A]:
|
||||
final class Task[A](
|
||||
val attributes: AttributeMap,
|
||||
val post: A => AttributeMap,
|
||||
val work: Action[A]
|
||||
) extends TaskId[A]:
|
||||
override def toString = name.getOrElse(s"Task($attributes)")
|
||||
override def hashCode = (attributes, post).hashCode
|
||||
|
||||
def name = attributes.get(Task.Name)
|
||||
def description = attributes.get(Task.Description)
|
||||
def name: Option[String] = get(Task.Name)
|
||||
def description: Option[String] = get(Task.Description)
|
||||
def get[B](key: AttributeKey[B]): Option[B] = attributes.get(key)
|
||||
def getOrElse[B](key: AttributeKey[B], default: => B): B = attributes.getOrElse(key, default)
|
||||
|
||||
def setName(name: String): Task[A] = set(Task.Name, name)
|
||||
def setDescription(description: String): Task[A] = set(Task.Description, description)
|
||||
def set[A](key: AttributeKey[A], value: A) = copy(attributes = this.attributes.put(key, value))
|
||||
def set[B](key: AttributeKey[B], value: B) =
|
||||
new Task(attributes.put(key, value), post, work)
|
||||
|
||||
def postTransform(f: (A, AttributeMap) => AttributeMap): Task[A] = copy(post = a => f(a, post(a)))
|
||||
def postTransform(f: (A, AttributeMap) => AttributeMap): Task[A] =
|
||||
new Task(attributes, a => f(a, post(a)), work)
|
||||
|
||||
def tag(tags: Tag*): Task[A] = tagw(tags.map(t => (t, 1))*)
|
||||
def tagw(tags: (Tag, Int)*): Task[A] =
|
||||
|
|
@ -49,6 +53,8 @@ object Task:
|
|||
def apply[A](attributes: AttributeMap, work: Action[A]): Task[A] =
|
||||
new Task[A](attributes, defaultAttributeMap, work)
|
||||
|
||||
def unapply[A](task: Task[A]): Option[Action[A]] = Some(task.work)
|
||||
|
||||
val Name = AttributeKey[String]("name")
|
||||
val Description = AttributeKey[String]("description")
|
||||
val defaultAttributeMap = const(AttributeMap.empty)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import sbt.internal.util.Types.*
|
|||
|
||||
object Transform:
|
||||
def fromDummy[A](original: Task[A])(action: => A): Task[A] =
|
||||
original.copy(work = Action.Pure(() => action, false))
|
||||
new Task(original.attributes, original.post, work = Action.Pure(() => action, false))
|
||||
|
||||
def fromDummyStrict[T](original: Task[T], value: T): Task[T] = fromDummy(original)(value)
|
||||
|
||||
|
|
@ -57,8 +57,8 @@ object Transform:
|
|||
case Join(in, f) => uniform(in)(f)
|
||||
|
||||
def inline1[T](t: TaskId[T]): Option[() => T] = t match
|
||||
case Task(_, _, Action.Pure(eval, true)) => Some(eval)
|
||||
case _ => None
|
||||
case Task(Action.Pure(eval, true)) => Some(eval)
|
||||
case _ => None
|
||||
|
||||
def uniform[A1, D](tasks: Seq[Task[D]])(
|
||||
f: Seq[Result[D]] => Either[Task[A1], A1]
|
||||
|
|
|
|||
Loading…
Reference in New Issue