Route fdo logic that deals with the path to the fdo profile through CcToolchainProvider
As --fdo_optimize can point to a label, the path to the fdo profile can not be reliably determined in CppConfiguration.
In order to enable the fdo features (which depend on the path to the fdo profile), the logic from CppConfiguration.configurationEnabledFeatures() has been moved to CcCommon.configureFeatures(). The latter method has access to the fdo profile path through CcToolchainProvider.
RELNOTES: None.
PiperOrigin-RevId: 186278311
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 8d7979b..2be6796 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
@@ -177,7 +177,8 @@
private final ListMultimap<String, ConfiguredFilesetEntry> filesetEntryMap;
private final ImmutableMap<Label, ConfigMatchingProvider> configConditions;
private final AspectAwareAttributeMapper attributes;
- private final ImmutableSet<String> features;
+ private final ImmutableSet<String> enabledFeatures;
+ private final ImmutableSet<String> disabledFeatures;
private final String ruleClassNameForLogging;
private final BuildConfiguration hostConfiguration;
private final PatchTransition disableLipoTransition;
@@ -217,7 +218,11 @@
this.filesetEntryMap = filesetEntryMap;
this.configConditions = configConditions;
this.attributes = new AspectAwareAttributeMapper(attributes, aspectAttributes);
- this.features = getEnabledFeatures();
+ Set<String> allEnabledFeatures = new HashSet<>();
+ Set<String> allDisabledFeatures = new HashSet<>();
+ getAllFeatures(allEnabledFeatures, allDisabledFeatures);
+ this.enabledFeatures = ImmutableSortedSet.copyOf(allEnabledFeatures);
+ this.disabledFeatures = ImmutableSortedSet.copyOf(allDisabledFeatures);
this.ruleClassNameForLogging = ruleClassNameForLogging;
this.hostConfiguration = builder.hostConfiguration;
this.disableLipoTransition = builder.disableLipoTransition;
@@ -225,7 +230,7 @@
this.toolchainContext = toolchainContext;
}
- private ImmutableSet<String> getEnabledFeatures() {
+ private void getAllFeatures(Set<String> allEnabledFeatures, Set<String> allDisabledFeatures) {
Set<String> globallyEnabled = new HashSet<>();
Set<String> globallyDisabled = new HashSet<>();
parseFeatures(getConfiguration().getDefaultFeatures(), globallyEnabled, globallyDisabled);
@@ -237,23 +242,26 @@
if (attributes().has("features", Type.STRING_LIST)) {
parseFeatures(attributes().get("features", Type.STRING_LIST), ruleEnabled, ruleDisabled);
}
+
Set<String> ruleDisabledFeatures =
Sets.union(ruleDisabled, Sets.difference(packageDisabled, ruleEnabled));
- Set<String> disabledFeatures = Sets.union(ruleDisabledFeatures, globallyDisabled);
+ allDisabledFeatures.addAll(Sets.union(ruleDisabledFeatures, globallyDisabled));
for (ImmutableMap.Entry<Class<? extends Fragment>, Fragment> entry :
getConfiguration().getAllFragments().entrySet()) {
if (isLegalFragment(entry.getKey())) {
globallyEnabled.addAll(
entry
.getValue()
- .configurationEnabledFeatures(this, ImmutableSortedSet.copyOf(disabledFeatures)));
+ .configurationEnabledFeatures(
+ this, ImmutableSortedSet.copyOf(allDisabledFeatures)));
}
}
+
Set<String> packageFeatures =
Sets.difference(Sets.union(globallyEnabled, packageEnabled), packageDisabled);
Set<String> ruleFeatures =
Sets.difference(Sets.union(packageFeatures, ruleEnabled), ruleDisabled);
- return ImmutableSortedSet.copyOf(Sets.difference(ruleFeatures, globallyDisabled));
+ allEnabledFeatures.addAll(Sets.difference(ruleFeatures, globallyDisabled));
}
private void parseFeatures(Iterable<String> features, Set<String> enabled, Set<String> disabled) {
@@ -1371,7 +1379,12 @@
* @return the set of features applicable for the current rule's package.
*/
public ImmutableSet<String> getFeatures() {
- return features;
+ return enabledFeatures;
+ }
+
+ /** @return the set of features that are disabled for the current rule's package. */
+ public ImmutableSet<String> getDisabledFeatures() {
+ return disabledFeatures;
}
@Override