From 5deb103ef6441f971afbd587d486492c38723516 Mon Sep 17 00:00:00 2001 From: Dan Sanduleac Date: Tue, 20 May 2014 18:13:06 +0100 Subject: [PATCH] Fix resolving Select(ThisProject) --- main/settings/src/main/scala/sbt/Scope.scala | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/main/settings/src/main/scala/sbt/Scope.scala b/main/settings/src/main/scala/sbt/Scope.scala index c9f0211f9..d921225fd 100644 --- a/main/settings/src/main/scala/sbt/Scope.scala +++ b/main/settings/src/main/scala/sbt/Scope.scala @@ -20,10 +20,10 @@ object Scope { val GlobalScope = Scope(Global, Global, Global, Global) def resolveScope(thisScope: Scope, current: URI, rootProject: URI => String): Scope => Scope = - resolveProject(current, rootProject) compose replaceThis(thisScope) + resolveProject(current, rootProject) compose replaceThis(thisScope) compose subThisProject def resolveBuildScope(thisScope: Scope, current: URI): Scope => Scope = - buildResolve(current) compose replaceThis(thisScope) + buildResolve(current) compose replaceThis(thisScope) compose subThisProject def replaceThis(thisScope: Scope): Scope => Scope = (scope: Scope) => Scope(subThis(thisScope.project, scope.project), subThis(thisScope.config, scope.config), subThis(thisScope.task, scope.task), subThis(thisScope.extra, scope.extra)) @@ -31,6 +31,15 @@ object Scope { def subThis[T](sub: ScopeAxis[T], into: ScopeAxis[T]): ScopeAxis[T] = if (into == This) sub else into + /** + * `Select(ThisProject)` cannot be resolved by [[resolveProject]] (it doesn't know what to replace it with), so we + * perform this transformation so that [[replaceThis]] picks it up. + */ + def subThisProject: Scope => Scope = { + case s @ Scope(Select(ThisProject), _, _, _) => s.copy(project = This) + case s => s + } + def fillTaskAxis(scope: Scope, key: AttributeKey[_]): Scope = scope.task match { case _: Select[_] => scope @@ -59,7 +68,6 @@ object Scope { } def resolveProjectBuild(current: URI, ref: ProjectReference): ProjectReference = ref match { - case ThisProject => RootProject(current) case LocalRootProject => RootProject(current) case LocalProject(id) => ProjectRef(current, id) case RootProject(uri) => RootProject(resolveBuild(current, uri)) @@ -79,8 +87,8 @@ object Scope { def resolveProjectRef(current: URI, rootProject: URI => String, ref: ProjectReference): ProjectRef = ref match { - case ThisProject | LocalRootProject => ProjectRef(current, rootProject(current)) - case LocalProject(id) => ProjectRef(current, id) + case LocalRootProject => ProjectRef(current, rootProject(current)) + case LocalProject(id) => ProjectRef(current, id) case RootProject(uri) => val res = resolveBuild(current, uri); ProjectRef(res, rootProject(res)) case ProjectRef(uri, id) => ProjectRef(resolveBuild(current, uri), id)