From 270f59b3630ef009f4a3e973581b3fc65a24ecc9 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 11 Jul 2016 17:22:55 +0000 Subject: RELNOTES: Improve Android split transition handling. -- MOS_MIGRATED_REVID=127099896 --- .../devtools/build/lib/analysis/RuleContext.java | 34 +++++++++------------- 1 file changed, 13 insertions(+), 21 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java') 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> map = - getSplitPrerequisites(attributeName, /*requireSplit=*/false); + Map, ? extends List> map = + getSplitPrerequisites(attributeName); return map.isEmpty() ? ImmutableList.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> + public Map, ? extends List> getSplitPrerequisites(String attributeName) { - return getSplitPrerequisites(attributeName, /*requireSplit*/true); - } - - private Map> - 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 cpus = new HashSet<>(); @@ -713,15 +705,15 @@ public final class RuleContext extends TargetContext } // Use an ImmutableListMultimap.Builder here to preserve ordering. - ImmutableListMultimap.Builder result = + ImmutableListMultimap.Builder, 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); } } } -- cgit v1.2.3