diff options
author | 2017-08-22 01:59:46 +0200 | |
---|---|---|
committer | 2017-08-22 09:15:29 +0200 | |
commit | 49b5bbc665b0cef3bcc9686cb2148e5a2d4ee7c6 (patch) | |
tree | 345a195a167f4fd3d5885ad4cec9c9fb57e6c275 /src/main/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlag.java | |
parent | e2eea44b6938bff56eafbd2a8d7beb751a925582 (diff) |
Remove FeaturePolicyConfiguration et al. in favor of the new Whitelisting.
This migrates the config_feature_flag implementation over and removes the
old flag (which was not used except to test it). Fare thee well, old flag.
RELNOTES: None.
PiperOrigin-RevId: 165995681
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlag.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlag.java | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlag.java b/src/main/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlag.java index 72b04dc28c..70fa67d8d1 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlag.java +++ b/src/main/java/com/google/devtools/build/lib/rules/config/ConfigFeatureFlag.java @@ -29,9 +29,12 @@ import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; import com.google.devtools.build.lib.analysis.RuleConfiguredTargetFactory; import com.google.devtools.build.lib.analysis.RuleContext; +import com.google.devtools.build.lib.analysis.RuleDefinitionEnvironment; import com.google.devtools.build.lib.analysis.RunfilesProvider; -import com.google.devtools.build.lib.analysis.featurecontrol.FeaturePolicyConfiguration; +import com.google.devtools.build.lib.analysis.whitelisting.Whitelist; +import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; +import com.google.devtools.build.lib.packages.Attribute; import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; import com.google.devtools.build.lib.syntax.Printer; import java.util.List; @@ -41,13 +44,36 @@ import java.util.List; */ public class ConfigFeatureFlag implements RuleConfiguredTargetFactory { /** The name of the policy that is used to restrict access to the config_feature_flag rule. */ - public static final String POLICY_NAME = "config_feature_flag"; + private static final String WHITELIST_NAME = "config_feature_flag"; + + /** Constructs a definition for the attribute used to restrict access to config_feature_flag. */ + public static Attribute.Builder<Label> getWhitelistAttribute(RuleDefinitionEnvironment env) { + return Whitelist.getAttributeFromWhitelistName( + WHITELIST_NAME, + env.getToolsLabel("//tools/whitelists/config_feature_flag:config_feature_flag")); + } + + /** + * Returns whether config_feature_flag and related features are available to the current rule. + * + * <p>The current rule must have an attribute defined on it created with {@link + * #getWhitelistAttribute}. + */ + public static boolean isAvailable(RuleContext ruleContext) { + return Whitelist.isAvailable(ruleContext, WHITELIST_NAME); + } @Override public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException { - FeaturePolicyConfiguration.checkAvailable( - ruleContext, POLICY_NAME, "the " + ruleContext.getRuleClassNameForLogging() + " rule"); + if (!ConfigFeatureFlag.isAvailable(ruleContext)) { + ruleContext.ruleError( + String.format( + "the %s rule is not available in package '%s'", + ruleContext.getRuleClassNameForLogging(), + ruleContext.getLabel().getPackageIdentifier())); + throw new RuleErrorException(); + } List<String> specifiedValues = ruleContext.attributes().get("allowed_values", STRING_LIST); ImmutableSet<String> values = ImmutableSet.copyOf(specifiedValues); |