local settings, sbt-package-private for now

This commit is contained in:
Mark Harrah 2011-10-01 14:39:40 -04:00
parent f8e3084e8f
commit 5874d45525
3 changed files with 40 additions and 5 deletions

View File

@ -14,33 +14,46 @@ sealed trait AttributeKey[T] {
def label: String
def description: Option[String]
def extend: Seq[AttributeKey[_]]
def isLocal: Boolean
}
private[sbt] abstract class SharedAttributeKey[T] extends AttributeKey[T] {
override final def toString = label
override final def hashCode = label.hashCode
override final def equals(o: Any) = (this eq o.asInstanceOf[AnyRef]) || (o match {
case a: AttributeKey[t] => a.label == this.label && a.manifest == this.manifest
case a: SharedAttributeKey[t] => a.label == this.label && a.manifest == this.manifest
case _ => false
})
final def isLocal: Boolean = false
}
object AttributeKey
{
def apply[T](name: String)(implicit mf: Manifest[T]): AttributeKey[T] = new AttributeKey[T] {
def apply[T](name: String)(implicit mf: Manifest[T]): AttributeKey[T] = new SharedAttributeKey[T] {
def manifest = mf
def label = name
def description = None
def extend = Nil
}
def apply[T](name: String, description0: String)(implicit mf: Manifest[T]): AttributeKey[T] = new AttributeKey[T] {
def apply[T](name: String, description0: String)(implicit mf: Manifest[T]): AttributeKey[T] = new SharedAttributeKey[T] {
def manifest = mf
def label = name
def description = Some(description0)
def extend = Nil
}
def apply[T](name: String, description0: String, extend0: Seq[AttributeKey[_]])(implicit mf: Manifest[T]): AttributeKey[T] = new AttributeKey[T] {
def apply[T](name: String, description0: String, extend0: Seq[AttributeKey[_]])(implicit mf: Manifest[T]): AttributeKey[T] = new SharedAttributeKey[T] {
def manifest = mf
def label = name
def description = Some(description0)
def extend = extend0
}
private[sbt] def local[T](implicit mf: Manifest[T]): AttributeKey[T] = new AttributeKey[T] {
def manifest = mf
def label = LocalLabel
def description = None
def extend = Nil
override def toString = label
def isLocal: Boolean = true
}
private[sbt] final val LocalLabel = "$local"
}
trait AttributeMap

View File

@ -55,7 +55,10 @@ abstract class EvaluateSettings[Scope]
}
getResults(delegates)
}
private[this] def getResults(implicit delegates: Scope => Seq[Scope]) = (empty /: static.toTypedSeq) { case (ss, static.TPair(key, node)) => ss.set(key.scope, key.key, node.get) }
private[this] def getResults(implicit delegates: Scope => Seq[Scope]) =
(empty /: static.toTypedSeq) { case (ss, static.TPair(key, node)) =>
if(key.key.isLocal) ss else ss.set(key.scope, key.key, node.get)
}
private[this] val getValue = new (INode ~> Id) { def apply[T](node: INode[T]) = node.get }
private[this] def submitEvaluate(node: INode[_]) = submit(node.evaluate())

View File

@ -193,6 +193,25 @@ trait Init[Scope]
{
override def toString = showFullKey(key)
}
final class Flattened(val key: ScopedKey[_], val dependencies: Iterable[ScopedKey[_]])
def flattenLocals(compiled: CompiledMap): Map[ScopedKey[_],Flattened] =
{
import collection.breakOut
val locals = compiled.flatMap { case (key, comp) => if(key.key.isLocal) Seq[Compiled[_]](comp) else Nil }(breakOut)
val ordered = Dag.topologicalSort(locals)(_.dependencies.flatMap(dep => if(dep.key.isLocal) Seq[Compiled[_]](compiled(dep)) else Nil))
def flatten(cmap: Map[ScopedKey[_],Flattened], key: ScopedKey[_], deps: Iterable[ScopedKey[_]]): Flattened =
new Flattened(key, deps.flatMap(dep => if(dep.key.isLocal) cmap(dep).dependencies else dep :: Nil))
val empty = Map.empty[ScopedKey[_],Flattened]
val flattenedLocals = (empty /: ordered) { (cmap, c) => cmap.updated(c.key, flatten(cmap, c.key, c.dependencies)) }
compiled.flatMap{ case (key, comp) =>
if(key.key.isLocal)
Nil
else
Seq[ (ScopedKey[_], Flattened)]( (key, flatten(flattenedLocals, key, comp.dependencies)) )
}(breakOut)
}
sealed trait Initialize[T]
{