diff options
author | 2016-07-11 17:22:55 +0000 | |
---|---|---|
committer | 2016-07-12 11:17:34 +0000 | |
commit | 270f59b3630ef009f4a3e973581b3fc65a24ecc9 (patch) | |
tree | b081e7a5135d9b43c445d02b90b48c7c9efbcea1 /src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java | |
parent | 633e48a4ce8747575b156639608ee18afe4b386e (diff) |
RELNOTES: Improve Android split transition handling.
--
MOS_MIGRATED_REVID=127099896
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java index d946aae9a0..dc6064c485 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java @@ -16,6 +16,7 @@ package com.google.devtools.build.lib.analysis; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Joiner; +import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableBiMap; @@ -661,8 +662,8 @@ public final class RuleContext extends TargetContext // deeply nested and we can't easily inject the behavior we want. However, we should fix all // such call sites. checkAttribute(attributeName, Mode.SPLIT); - Map<String, ? extends List<? extends TransitiveInfoCollection>> map = - getSplitPrerequisites(attributeName, /*requireSplit=*/false); + Map<Optional<String>, ? extends List<? extends TransitiveInfoCollection>> map = + getSplitPrerequisites(attributeName); return map.isEmpty() ? ImmutableList.<TransitiveInfoCollection>of() : map.entrySet().iterator().next().getValue(); @@ -673,16 +674,12 @@ public final class RuleContext extends TargetContext } /** - * Returns the a prerequisites keyed by the CPU of their configurations; this method throws an - * exception if the split transition is not active. + * Returns the a prerequisites keyed by the CPU of their configurations. + * If no cpu is explicitly specified, an empty Optional is the only key. + * This method throws if the attribute cannot split. */ - public Map<String, ? extends List<? extends TransitiveInfoCollection>> + public Map<Optional<String>, ? extends List<? extends TransitiveInfoCollection>> getSplitPrerequisites(String attributeName) { - return getSplitPrerequisites(attributeName, /*requireSplit*/true); - } - - private Map<String, ? extends List<? extends TransitiveInfoCollection>> - getSplitPrerequisites(String attributeName, boolean requireSplit) { checkAttribute(attributeName, Mode.SPLIT); Attribute attributeDefinition = getAttribute(attributeName); @@ -693,15 +690,10 @@ public final class RuleContext extends TargetContext // There are two cases here: // 1. Splitting is enabled, but only one target cpu. // 2. Splitting is disabled, and no --cpu value was provided on the command line. - // In the first case, the cpu value is non-null, but in the second case it is null. We only - // allow that to proceed if the caller specified that he is going to ignore the cpu value - // anyway. + // In the first case, the cpu value is non-null, but in the second case it is null. + // If --cpu was null, we use an empty Optional in the map. String cpu = configurations.get(0).getCpu(); - if (cpu == null) { - Preconditions.checkState(!requireSplit); - cpu = "DO_NOT_USE"; - } - return ImmutableMap.of(cpu, targetMap.get(attributeName)); + return ImmutableMap.of(Optional.fromNullable(cpu), targetMap.get(attributeName)); } Set<String> cpus = new HashSet<>(); @@ -713,15 +705,15 @@ public final class RuleContext extends TargetContext } // Use an ImmutableListMultimap.Builder here to preserve ordering. - ImmutableListMultimap.Builder<String, TransitiveInfoCollection> result = + ImmutableListMultimap.Builder<Optional<String>, TransitiveInfoCollection> result = ImmutableListMultimap.builder(); for (TransitiveInfoCollection t : targetMap.get(attributeName)) { if (t.getConfiguration() != null) { - result.put(t.getConfiguration().getCpu(), t); + result.put(Optional.of(t.getConfiguration().getCpu()), t); } else { // Source files don't have a configuration, so we add them to all architecture entries. for (String cpu : cpus) { - result.put(cpu, t); + result.put(Optional.of(cpu), t); } } } |