Make sure disabled FDO features are filtered out.

Without this, the FDO features enabled under --fdo* blaze options are not removed when BUILD files contain "features = ['-fdo_instrument', '-fdo_optimize']".

--
MOS_MIGRATED_REVID=103431508
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 7ec5899..8c226b4 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
@@ -163,6 +163,12 @@
     Set<String> globallyEnabled = new HashSet<>();
     Set<String> globallyDisabled = new HashSet<>();
     parseFeatures(getConfiguration().getDefaultFeatures(), globallyEnabled, globallyDisabled);
+    for (ImmutableMap.Entry<Class<? extends Fragment>, Fragment> entry :
+        getConfiguration().getAllFragments().entrySet()) {
+      if (rule.getRuleClassObject().isLegalConfigurationFragment(entry.getKey())) {
+        globallyEnabled.addAll(entry.getValue().configurationEnabledFeatures(this));
+      }
+    }
     Set<String> packageEnabled = new HashSet<>();
     Set<String> packageDisabled = new HashSet<>();
     parseFeatures(getRule().getPackage().getFeatures(), packageEnabled, packageDisabled);
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
index 4ea1509..2ae028b 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/config/BuildConfiguration.java
@@ -36,6 +36,7 @@
 import com.google.devtools.build.lib.analysis.BlazeDirectories;
 import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
 import com.google.devtools.build.lib.analysis.DependencyResolver;
+import com.google.devtools.build.lib.analysis.RuleContext;
 import com.google.devtools.build.lib.analysis.ViewCreationFailedException;
 import com.google.devtools.build.lib.analysis.config.BuildConfigurationCollection.Transitions;
 import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
@@ -270,6 +271,13 @@
      */
     public void declareSkyframeDependencies(Environment env) {
     }
+
+    /**
+     * Return set of features enabled by this configuration.
+     */
+    public ImmutableSet<String> configurationEnabledFeatures(RuleContext ruleContext) {
+      return ImmutableSet.of();
+    }
   }
 
   /**
@@ -1013,6 +1021,12 @@
    */
   private final Map<String, OptionDetails> transitiveOptionsMap;
 
+  /**
+   * Returns map of all the fragments for this configuration.
+   */
+  public ImmutableMap<Class<? extends Fragment>, Fragment> getAllFragments() {
+    return fragments;
+  }
 
   /**
    * Validates the options for this BuildConfiguration. Issues warnings for the