Merge pull request #2712 from Duhemm/fport/key-selection-build-level

Forward port #2469 & #2708
This commit is contained in:
Dale Wijnand 2016-09-01 09:23:01 +01:00 committed by GitHub
commit 1ba7bb0fb9
3 changed files with 31 additions and 12 deletions

View File

@ -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 {

View File

@ -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))
}
}

View File

@ -0,0 +1,4 @@
> baseDirectory
> {.}/baseDirectory