diff --git a/main/src/main/scala/sbt/internal/Act.scala b/main/src/main/scala/sbt/internal/Act.scala index ca12939a4..f3da90b61 100644 --- a/main/src/main/scala/sbt/internal/Act.scala +++ b/main/src/main/scala/sbt/internal/Act.scala @@ -49,12 +49,22 @@ object Act { new ParsedKey(makeScopedKey(proj, conf, task, extra, key), mask) } - for { - rawProject <- optProjectRef(index, current) - proj = resolveProject(rawProject, current) - confAmb <- config(index configs proj) - partialMask = ScopeMask(rawProject.isExplicit, confAmb.isExplicit, false, false) - } yield taskKeyExtra(proj, confAmb, partialMask) + val projectKeys = + for { + rawProject <- optProjectRef(index, current) + proj = resolveProject(rawProject, current) + confAmb <- config(index configs proj) + partialMask = ScopeMask(rawProject.isExplicit, confAmb.isExplicit, false, false) + } yield taskKeyExtra(proj, confAmb, partialMask) + + val build = Some(BuildRef(current.build)) + val buildKeys = + for { + confAmb <- config(index configs build) + partialMask = ScopeMask(false, confAmb.isExplicit, false, false) + } yield taskKeyExtra(build, confAmb, partialMask) + + buildKeys combinedWith projectKeys map (_.flatten) } def makeScopedKey(proj: Option[ResolvedReference], conf: Option[String], task: Option[AttributeKey[_]], extra: ScopeAxis[AttributeMap], key: AttributeKey[_]): ScopedKey[_] = ScopedKey(Scope(toAxis(proj, Global), toAxis(conf map ConfigKey.apply, Global), toAxis(task, Global), extra), key) @@ -68,11 +78,16 @@ object Act { selectFromValid(ss filter isValid(data), default) } def selectFromValid(ss: Seq[ParsedKey], default: Parser[ParsedKey])(implicit show: Show[ScopedKey[_]]): Parser[ParsedKey] = - selectByTask(selectByConfig(ss)) match { - case Seq() => default - case Seq(single) => success(single) - case multi => failure("Ambiguous keys: " + showAmbiguous(keys(multi))) + selectByTask(selectByConfig(ss)) partition isBuildKey match { + case (_, Seq(single)) => success(single) + case (Seq(single), Seq()) => success(single) + case (Seq(), Seq()) => default + case (buildKeys, projectKeys) => failure("Ambiguous keys: " + showAmbiguous(keys(buildKeys ++ projectKeys))) } + private def isBuildKey(parsed: ParsedKey): Boolean = parsed.key.scope.project match { + case Select(_: BuildReference) => true + case _ => false + } private[this] def keys(ss: Seq[ParsedKey]): Seq[ScopedKey[_]] = ss.map(_.key) def selectByConfig(ss: Seq[ParsedKey]): Seq[ParsedKey] = ss match { diff --git a/main/src/test/scala/ParseKey.scala b/main/src/test/scala/ParseKey.scala index cc41901a7..147b54bf2 100644 --- a/main/src/test/scala/ParseKey.scala +++ b/main/src/test/scala/ParseKey.scala @@ -31,7 +31,7 @@ object ParseKey extends Properties("Key parser test") { parseExpected(structure, string, expected, mask) } - property("An unspecified project axis resolves to the current project") = + property("An unspecified project axis resolves to the current project or the build of the current project") = forAllNoShrink(structureDefinedKey) { (skm: StructureKeyMask) => import skm.{ structure, key } @@ -43,7 +43,7 @@ object ParseKey extends Properties("Key parser test") { ("Current: " + structure.current) |: parse(structure, string) { case Left(err) => false - case Right(sk) => sk.scope.project == Select(structure.current) + case Right(sk) => sk.scope.project == Select(structure.current) || sk.scope.project == Select(BuildRef(structure.current.build)) } } diff --git a/sbt/src/sbt-test/project/build-level-keys/test b/sbt/src/sbt-test/project/build-level-keys/test new file mode 100644 index 000000000..a04b77809 --- /dev/null +++ b/sbt/src/sbt-test/project/build-level-keys/test @@ -0,0 +1,4 @@ +> baseDirectory + +> {.}/baseDirectory +