mirror of https://github.com/sbt/sbt.git
clean up scope delegation implementation
This commit is contained in:
parent
4d635e449f
commit
ed27a8077d
|
|
@ -46,8 +46,9 @@ object Load
|
|||
val rootProject = getRootProject(lb.units)
|
||||
def resolveRef(project: Reference): ResolvedReference = Scope.resolveReference(lb.root, rootProject, project)
|
||||
Scope.delegates(
|
||||
project => projectInherit(lb, resolveRef(project)),
|
||||
(project, config) => configInherit(lb, resolveRef(project), config, rootProject),
|
||||
resolveRef,
|
||||
project => projectInherit(lb, project),
|
||||
(project, config) => configInherit(lb, project, config, rootProject),
|
||||
(project, task) => Nil,
|
||||
(project, extra) => Nil
|
||||
)
|
||||
|
|
@ -269,7 +270,7 @@ object Load
|
|||
{
|
||||
IO.assertAbsolute(uri)
|
||||
val resolve = (_: Project).resolve(ref => Scope.resolveProjectRef(uri, rootProject, ref))
|
||||
new LoadedBuildUnit(unit.unit, unit.defined mapValues resolve, unit.rootProjects, unit.buildSettings)
|
||||
new LoadedBuildUnit(unit.unit, unit.defined mapValues resolve toMap, unit.rootProjects, unit.buildSettings)
|
||||
}
|
||||
def projects(unit: BuildUnit): Seq[Project] =
|
||||
{
|
||||
|
|
@ -417,7 +418,7 @@ object Load
|
|||
sealed trait BuildUnitBase { def rootProjects: Seq[String]; def buildSettings: Seq[Setting[_]] }
|
||||
final class PartBuildUnit(val unit: BuildUnit, val defined: Map[String, Project], val rootProjects: Seq[String], val buildSettings: Seq[Setting[_]]) extends BuildUnitBase
|
||||
{
|
||||
def resolve(f: Project => ResolvedProject): LoadedBuildUnit = new LoadedBuildUnit(unit, defined mapValues f, rootProjects, buildSettings)
|
||||
def resolve(f: Project => ResolvedProject): LoadedBuildUnit = new LoadedBuildUnit(unit, defined mapValues f toMap, rootProjects, buildSettings)
|
||||
def resolveRefs(f: ProjectReference => ProjectRef): LoadedBuildUnit = resolve(_ resolve f)
|
||||
}
|
||||
final class LoadedBuildUnit(val unit: BuildUnit, val defined: Map[String, ResolvedProject], val rootProjects: Seq[String], val buildSettings: Seq[Setting[_]]) extends BuildUnitBase
|
||||
|
|
@ -445,7 +446,7 @@ object Load
|
|||
// information that is not original, but can be reconstructed from the rest of BuildStructure
|
||||
final class StructureIndex(val keyMap: Map[String, AttributeKey[_]], val taskToKey: Map[Task[_], ScopedKey[Task[_]]], val keyIndex: KeyIndex)
|
||||
|
||||
private[this] def memo[A,B](implicit f: A => B): A => B =
|
||||
private[this] def memo[A,B](f: A => B): A => B =
|
||||
{
|
||||
val dcache = new mutable.HashMap[A,B]
|
||||
(a: A) => dcache.getOrElseUpdate(a, f(a))
|
||||
|
|
|
|||
|
|
@ -115,10 +115,12 @@ object Scope
|
|||
}
|
||||
|
||||
// *Inherit functions should be immediate delegates and not include argument itself. Transitivity will be provided by this method
|
||||
def delegates(projectInherit: Reference => Seq[Reference],
|
||||
configInherit: (Reference, ConfigKey) => Seq[ConfigKey],
|
||||
taskInherit: (Reference, AttributeKey[_]) => Seq[AttributeKey[_]],
|
||||
extraInherit: (Reference, AttributeMap) => Seq[AttributeMap])(rawScope: Scope): Seq[Scope] =
|
||||
def delegates(
|
||||
resolve: Reference => ResolvedReference,
|
||||
projectInherit: ResolvedReference => Seq[ResolvedReference],
|
||||
configInherit: (ResolvedReference, ConfigKey) => Seq[ConfigKey],
|
||||
taskInherit: (ResolvedReference, AttributeKey[_]) => Seq[AttributeKey[_]],
|
||||
extraInherit: (ResolvedReference, AttributeMap) => Seq[AttributeMap])(rawScope: Scope): Seq[Scope] =
|
||||
{
|
||||
val scope = Scope.replaceThis(GlobalScope)(rawScope)
|
||||
scope.project match
|
||||
|
|
@ -126,11 +128,11 @@ object Scope
|
|||
case Global => withGlobalScope(scope)
|
||||
case This => withGlobalScope(scope.copy(project = Global))
|
||||
case Select(proj) =>
|
||||
val projI = withRawBuilds(linearize(scope.project, Nil)(projectInherit)).distinct
|
||||
val resolvedProj = resolve(proj)
|
||||
val prod =
|
||||
for {
|
||||
px <- projI
|
||||
p = px.toOption getOrElse proj
|
||||
px <- withRawBuilds(linearize(scope.project map resolve, Nil)(projectInherit)).distinct
|
||||
p = px.toOption getOrElse resolvedProj
|
||||
c <- linearize(scope.config)(configInherit(p, _))
|
||||
t <- linearize(scope.task)(taskInherit(p,_))
|
||||
e <- linearize(scope.extra)(extraInherit(p,_))
|
||||
|
|
@ -140,11 +142,11 @@ object Scope
|
|||
}
|
||||
}
|
||||
def withGlobalScope(base: Scope): Seq[Scope] = if(base == GlobalScope) GlobalScope :: Nil else base :: GlobalScope :: Nil
|
||||
def withRawBuilds(ps: Seq[ScopeAxis[Reference]]): Seq[ScopeAxis[Reference]] =
|
||||
def withRawBuilds(ps: Seq[ScopeAxis[ResolvedReference]]): Seq[ScopeAxis[ResolvedReference]] =
|
||||
(ps ++ (ps flatMap rawBuilds).map(Select.apply) :+ Global).distinct
|
||||
|
||||
def rawBuilds(ps: ScopeAxis[Reference]): Seq[Reference] = ps match { case Select(ref) => rawBuilds(ref); case _ => Nil }
|
||||
def rawBuilds(ps: Reference): Seq[Reference] = (Reference.uri(ps) map BuildRef.apply).toList
|
||||
def rawBuilds(ps: ScopeAxis[ResolvedReference]): Seq[ResolvedReference] = ps match { case Select(ref) => rawBuilds(ref); case _ => Nil }
|
||||
def rawBuilds(ps: ResolvedReference): Seq[ResolvedReference] = (Reference.uri(ps) map BuildRef.apply).toList
|
||||
|
||||
def linearize[T](axis: ScopeAxis[T], append: Seq[ScopeAxis[T]] = Global :: Nil)(inherit: T => Seq[T]): Seq[ScopeAxis[T]] =
|
||||
axis match
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ object IMap
|
|||
put(k, f(this get k getOrElse init))
|
||||
|
||||
def mapValues[V2[_]](f: V ~> V2) =
|
||||
new IMap0[K,V2](backing.mapValues(x => f(x)))
|
||||
new IMap0[K,V2](backing.mapValues(x => f(x)).toMap)
|
||||
def toSeq = backing.toSeq
|
||||
|
||||
override def toString = backing.toString
|
||||
|
|
|
|||
Loading…
Reference in New Issue