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) diff --git a/sbt/src/sbt-test/project/thisProject/build.sbt b/sbt/src/sbt-test/project/thisProject/build.sbt new file mode 100644 index 000000000..6fc79c53d --- /dev/null +++ b/sbt/src/sbt-test/project/thisProject/build.sbt @@ -0,0 +1,10 @@ +val proj2 = project + +name := "proj1" + +val check = taskKey[Unit]("Ensure each project is named appropriately") + +check := { + require(name.value == "proj1") + require((name in proj2).value == "boo") +} diff --git a/sbt/src/sbt-test/project/thisProject/proj2/build.sbt b/sbt/src/sbt-test/project/thisProject/proj2/build.sbt new file mode 100644 index 000000000..7f48be956 --- /dev/null +++ b/sbt/src/sbt-test/project/thisProject/proj2/build.sbt @@ -0,0 +1 @@ +name in ThisProject := "boo" diff --git a/sbt/src/sbt-test/project/thisProject/test b/sbt/src/sbt-test/project/thisProject/test new file mode 100644 index 000000000..15675b169 --- /dev/null +++ b/sbt/src/sbt-test/project/thisProject/test @@ -0,0 +1 @@ +> check