Merge pull request #3633 from dwijnand/misc-2017-10-12

Misc 2017-10-12
This commit is contained in:
Dale Wijnand 2017-10-24 20:37:20 +01:00 committed by GitHub
commit 81c5eaec33
4 changed files with 30 additions and 14 deletions

View File

@ -534,6 +534,14 @@ trait Init[Scope] {
}
}
/** Abstractly defines a value of type `T`.
*
* Specifically it defines a node in a task graph,
* where the `dependencies` represents dependent nodes,
* and `evaluate` represents the calculation based on the existing body of knowledge.
*
* @tparam T the type of the value this defines.
*/
sealed trait Initialize[T] {
def dependencies: Seq[ScopedKey[_]]
def apply[S](g: T => S): Initialize[S]
@ -698,6 +706,10 @@ trait Init[Scope] {
private[this] def deps(ls: Seq[Initialize[_]]): Seq[ScopedKey[_]] = ls.flatMap(_.dependencies)
/** An `Initialize[T]` associated with a `ScopedKey[S]`.
* @tparam S the type of the associated `ScopedKey`
* @tparam T the type of the value this `Initialize` defines.
*/
sealed trait Keyed[S, T] extends Initialize[T] {
def scopedKey: ScopedKey[S]
def transform: S => T
@ -724,6 +736,9 @@ trait Init[Scope] {
private[this] final class GetValue[S, T](val scopedKey: ScopedKey[S], val transform: S => T)
extends Keyed[S, T]
/** A `Keyed` where the type of the value and the associated `ScopedKey` are the same.
* @tparam T the type of both the value this `Initialize` defines and the type of the associated `ScopedKey`.
*/
trait KeyedInitialize[T] extends Keyed[T, T] {
final val transform = idFun[T]
}

View File

@ -552,7 +552,7 @@ object Defaults extends BuildCommon {
val trigMsg = triggeredMessage.value
new Watched {
val scoped = watchTransitiveSources in base
val key = ScopedKey(scoped.scope, scoped.key)
val key = scoped.scopedKey
override def pollInterval = interval
override def watchingMessage(s: WatchState) = msg(s)
override def triggeredMessage(s: WatchState) = trigMsg(s)

View File

@ -460,6 +460,7 @@ object EvaluateTask {
onResult(result, log) { v =>
if (show) println("Result: " + v); v
}
def onResult[T, S](result: Result[T], log: Logger)(f: T => S): S =
result match {
case Value(v) => f(v)

View File

@ -15,6 +15,7 @@ import sbt.internal.util.complete.Parser
import sbt.internal.util.AttributeKey
import sbt.util.Show
import std.Transform.DummyTaskMap
import sbt.EvaluateTask.extractedTaskConfig
final case class Extracted(structure: BuildStructure,
session: SessionSettings,
@ -49,16 +50,16 @@ final case class Extracted(structure: BuildStructure,
* If the project axis is not defined for the key, it is resolved to be the current project.
* Other axes are resolved to `Zero` if unspecified.
*
* This method requests execution of only the given task and does not aggregate execution. See `runAggregated` for that.
* This method requests execution of only the given task and does not aggregate execution.
* See `runAggregated` for that.
*/
def runTask[T](key: TaskKey[T], state: State): (State, T) = {
import EvaluateTask._
val rkey = resolve(key.scopedKey)
val config = extractedTaskConfig(this, structure, state)
val value: Option[(State, Result[T])] =
apply(structure, key.scopedKey, state, currentRef, config)
EvaluateTask(structure, key.scopedKey, state, currentRef, config)
val (newS, result) = getOrError(rkey.scope, rkey.key, value)
(newS, processResult(result, newS.log))
(newS, EvaluateTask.processResult(result, newS.log))
}
/**
@ -71,25 +72,22 @@ final case class Extracted(structure: BuildStructure,
* This method requests execution of only the given task and does not aggregate execution.
*/
def runInputTask[T](key: InputKey[T], input: String, state: State): (State, T) = {
import EvaluateTask._
val scopedKey = Scoped.scopedSetting(
Scope.resolveScope(Load.projectScope(currentRef), currentRef.build, structure.rootProject)(
key.scope),
val scopedKey = ScopedKey(
Scope.resolveScope(Load.projectScope(currentRef), currentRef.build, rootProject)(key.scope),
key.key
)
val rkey = resolve(scopedKey.scopedKey)
val rkey = resolve(scopedKey)
val inputTask = get(Scoped.scopedSetting(rkey.scope, rkey.key))
val task = Parser.parse(input, inputTask.parser(state)) match {
case Right(t) => t
case Left(msg) => sys.error(s"Invalid programmatic input:\n$msg")
}
val config = extractedTaskConfig(this, structure, state)
withStreams(structure, state) { str =>
val nv = nodeView(state, str, rkey :: Nil)
EvaluateTask.withStreams(structure, state) { str =>
val nv = EvaluateTask.nodeView(state, str, rkey :: Nil)
val (newS, result) =
EvaluateTask.runTask(task, state, str, structure.index.triggers, config)(nv)
(newS, processResult(result, newS.log))
(newS, EvaluateTask.processResult(result, newS.log))
}
}
@ -112,9 +110,11 @@ final case class Extracted(structure: BuildStructure,
private[this] def resolve[T](key: ScopedKey[T]): ScopedKey[T] =
Project.mapScope(Scope.resolveScope(GlobalScope, currentRef.build, rootProject))(key.scopedKey)
private def getOrError[T](scope: Scope, key: AttributeKey[_], value: Option[T])(
implicit display: Show[ScopedKey[_]]): T =
value getOrElse sys.error(display.show(ScopedKey(scope, key)) + " is undefined.")
private def getOrError[T](scope: Scope, key: AttributeKey[T])(
implicit display: Show[ScopedKey[_]]): T =
structure.data.get(scope, key) getOrElse sys.error(