Add a toolchains= attribute to *_binary, *_test, cc_library and extra_action rules to declare which Make variables they need.
The idea is that they would depend on the future java_runtime_alias / cc_toolchain_alias and similar rules and thus Bazel will know which Make variables they actually need instead of pulling in the whole BuildConfiguration and also making it possible to compute these Make variables during analysis instead of configuration creation.
RELNOTES: None.
PiperOrigin-RevId: 161785868
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 8987fed..61daf33 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
@@ -96,6 +96,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -1072,27 +1073,23 @@
}
public ImmutableMap<String, String> getMakeVariables(Iterable<String> attributeNames) {
- // Using an ImmutableBuilder to complain about duplicate keys. This traversal order of
- // getPrerequisites isn't well-defined, so this makes sure providers don't secretly stomp on
- // each other.
- ImmutableMap.Builder<String, String> makeVariableBuilder = ImmutableMap.builder();
- ImmutableSet.Builder<MakeVariableProvider> makeVariableProvidersBuilder =
- ImmutableSet.builder();
+ ArrayList<MakeVariableProvider> makeVariableProviders = new ArrayList<>();
for (String attributeName : attributeNames) {
// TODO(b/37567440): Remove this continue statement.
if (!attributes().has(attributeName)) {
continue;
}
- makeVariableProvidersBuilder.addAll(
+ Iterables.addAll(makeVariableProviders,
getPrerequisites(attributeName, Mode.TARGET, MakeVariableProvider.SKYLARK_CONSTRUCTOR));
}
- for (MakeVariableProvider makeVariableProvider : makeVariableProvidersBuilder.build()) {
- makeVariableBuilder.putAll(makeVariableProvider.getMakeVariables());
+ LinkedHashMap<String, String> makeVariables = new LinkedHashMap<>();
+ for (MakeVariableProvider makeVariableProvider : makeVariableProviders) {
+ makeVariables.putAll(makeVariableProvider.getMakeVariables());
}
- return makeVariableBuilder.build();
+ return ImmutableMap.copyOf(makeVariables);
}
/**