From 9d21724129bb267b598bd0ae91322df6bcddaf9a Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Wed, 27 Mar 2013 09:17:53 -0400 Subject: [PATCH] API for evaluating a setting or task in multiple scopes --- util/collection/src/main/scala/sbt/INode.scala | 4 +++- util/collection/src/main/scala/sbt/Settings.scala | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/util/collection/src/main/scala/sbt/INode.scala b/util/collection/src/main/scala/sbt/INode.scala index 6c2e845ba..4ce5ef8bb 100644 --- a/util/collection/src/main/scala/sbt/INode.scala +++ b/util/collection/src/main/scala/sbt/INode.scala @@ -20,12 +20,14 @@ abstract class EvaluateSettings[Scope] private[this] val complete = new LinkedBlockingQueue[Option[Throwable]] private[this] val static = PMap.empty[ScopedKey, INode] + private[this] val allScopes: Set[Scope] = compiledSettings.map(_.key.scope).toSet private[this] def getStatic[T](key: ScopedKey[T]): INode[T] = static get key getOrElse sys.error("Illegal reference to key " + key) private[this] val transform: Initialize ~> INode = new (Initialize ~> INode) { def apply[T](i: Initialize[T]): INode[T] = i match { case k: Keyed[s, T] => single(getStatic(k.scopedKey), k.transform) case a: Apply[k,T] => new MixedNode[k,T]( a.alist.transform[Initialize, INode](a.inputs, transform), a.f, a.alist) case b: Bind[s,T] => new BindNode[s,T]( transform(b.in), x => transform(b.f(x))) + case init.StaticScopes => constant(() => allScopes.asInstanceOf[T]) // can't convince scalac that StaticScopes => T == Set[Scope] case v: Value[T] => constant(v.value) case t: TransformCapture => constant(() => t.f) case o: Optional[s,T] => o.a match { @@ -33,7 +35,7 @@ abstract class EvaluateSettings[Scope] case Some(i) => single[s,T](transform(i), x => o.f(Some(x))) } }} - private[this] val roots: Seq[INode[_]] = compiledSettings flatMap { cs => + private[this] lazy val roots: Seq[INode[_]] = compiledSettings flatMap { cs => (cs.settings map { s => val t = transform(s.init) static(s.key) = t diff --git a/util/collection/src/main/scala/sbt/Settings.scala b/util/collection/src/main/scala/sbt/Settings.scala index 08f347ccd..cf12a58fc 100644 --- a/util/collection/src/main/scala/sbt/Settings.scala +++ b/util/collection/src/main/scala/sbt/Settings.scala @@ -353,6 +353,7 @@ trait Init[Scope] def mapConstant(g: MapConstant) = this def evaluate(map: Settings[Scope]): T = value() } + private[sbt] final val StaticScopes: Initialize[Set[Scope]] = new Value(() => error("internal sbt error: GetScopes not substituted")) private[sbt] final class Apply[K[L[x]], T](val f: K[Id] => T, val inputs: K[Initialize], val alist: AList[K]) extends Initialize[T] { def dependencies = deps(alist.toList(inputs))