Replace 'whitelist' with 'allowlist' in Bazel source code. Phase 1: Rename class, methods, variables, and error messages. This change still leaves the list locations at hard coded paths to //tools/whitelists. Those may each require a separate migration. NOTE: We are not considering this a breaking change, even though the error messages might change. Also: Fix some things that ErrorProne complains about, but only if critique could provide a fix. I don't think that refactoring code to please a strident tricorder test should be part of a renaming CL. RELNOTES: None PiperOrigin-RevId: 316394382
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Whitelist.java b/src/main/java/com/google/devtools/build/lib/analysis/Allowlist.java similarity index 63% rename from src/main/java/com/google/devtools/build/lib/analysis/Whitelist.java rename to src/main/java/com/google/devtools/build/lib/analysis/Allowlist.java index 6d5f451..6485fd1 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/Whitelist.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/Allowlist.java
@@ -27,63 +27,65 @@ import com.google.devtools.build.lib.packages.PackageSpecification.PackageGroupContents; /** - * Class used for implementing whitelists using package groups. + * Class used for implementing allowlists using package groups. * - * <p>To use add an attribute {@link getAttributeFromWhitelistName(String,Label) to the rule class - * which needs the whitelisting mechanism and use {@link isAvailable(RuleContext,String)} to check + * <p>To use add an attribute {@link getAttributeFromAllowlistName(String) to the rule class + * which needs the allowlisting mechanism and use {@link isAvailable(RuleContext,String)} to check * during analysis if a rule is present */ -public final class Whitelist { +public final class Allowlist { - private Whitelist() {} + private Allowlist() {} /** * Returns an Attribute.Builder that can be used to add an implicit attribute to a rule containing - * a package group whitelist. + * a package group allowlist. * - * @param whitelistName The name of the whitelist. This has to comply with attribute naming + * @param allowlistName The name of the allowlist. This has to comply with attribute naming * standards and will be used as a suffix for the attribute name. */ - public static Attribute.Builder<Label> getAttributeFromWhitelistName(String whitelistName) { - String attributeName = getAttributeNameFromWhitelistName(whitelistName); + public static Attribute.Builder<Label> getAttributeFromAllowlistName(String allowlistName) { + String attributeName = getAttributeNameFromAllowlistName(allowlistName); return attr(attributeName, LABEL) .cfg(HostTransition.createFactory()) .mandatoryNativeProviders(ImmutableList.of(PackageSpecificationProvider.class)); } /** - * Returns whether the rule in the given RuleContext *was defined* in a whitelist. + * Returns whether the rule in the given RuleContext *was defined* in a allowlist. * * @param ruleContext The context in which this check is being executed. - * @param whitelistName The name of the whitelist being used. + * @param allowlistName The name of the allowlist being used. */ public static boolean isAvailableBasedOnRuleLocation( - RuleContext ruleContext, String whitelistName) { + RuleContext ruleContext, String allowlistName) { return isAvailableFor( ruleContext, - whitelistName, + allowlistName, ruleContext.getRule().getRuleClassObject().getRuleDefinitionEnvironmentLabel()); } /** - * Returns whether the rule in the given RuleContext *was instantiated* in a whitelist. + * Returns whether the rule in the given RuleContext *was instantiated* in a allowlist. * * @param ruleContext The context in which this check is being executed. - * @param whitelistName The name of the whitelist being used. + * @param allowlistName The name of the allowlist being used. */ - public static boolean isAvailable(RuleContext ruleContext, String whitelistName) { - return isAvailableFor(ruleContext, whitelistName, ruleContext.getLabel()); + public static boolean isAvailable(RuleContext ruleContext, String allowlistName) { + return isAvailableFor(ruleContext, allowlistName, ruleContext.getLabel()); } /** - * @param relevantLabel the label to check for in the whitelist. This allows features that - * whitelist on rule definition location and features that whitelist on rule instantiation + * @param ruleContext The context in which this check is being executed. + * @param allowlistName The name of the allowlist being used. + * @param relevantLabel The label to check for in the allowlist. This allows features that + * allowlist on rule definition location and features that allowlist on rule instantiation * location to share logic. */ public static boolean isAvailableFor( - RuleContext ruleContext, String whitelistName, Label relevantLabel) { + RuleContext ruleContext, String allowlistName, Label relevantLabel) { PackageSpecificationProvider packageSpecificationProvider = - fetchPackageSpecificationProvider(ruleContext, whitelistName); + fetchPackageSpecificationProvider(ruleContext, allowlistName); return isAvailableFor(packageSpecificationProvider.getPackageSpecifications(), relevantLabel); } @@ -94,8 +96,8 @@ } public static PackageSpecificationProvider fetchPackageSpecificationProvider( - RuleContext ruleContext, String whitelistName) { - String attributeName = getAttributeNameFromWhitelistName(whitelistName); + RuleContext ruleContext, String allowlistName) { + String attributeName = getAttributeNameFromAllowlistName(allowlistName); Preconditions.checkArgument(ruleContext.isAttrDefined(attributeName, LABEL)); TransitiveInfoCollection packageGroup = ruleContext.getPrerequisite(attributeName, TransitionMode.HOST); @@ -105,31 +107,31 @@ } /** - * Returns whether the given label is in the whitelist provided. + * Returns whether the given label is in the allowlist provided. * - * @param whitelist the whitelist provided - * @param relevantLabel the label to check for in the whitelist. + * @param allowlist the allowlist provided + * @param relevantLabel the label to check for in the allowlist. */ - public static boolean isAvailableForWhitelist( - TransitiveInfoCollection whitelist, Label relevantLabel) { + public static boolean isAvailableForAllowlist( + TransitiveInfoCollection allowlist, Label relevantLabel) { PackageSpecificationProvider packageSpecificationProvider = - whitelist.getProvider(PackageSpecificationProvider.class); + allowlist.getProvider(PackageSpecificationProvider.class); return isAvailableFor(packageSpecificationProvider.getPackageSpecifications(), relevantLabel); } /** - * Returns whether the rule from the given rule context has a whitelist by the given name. + * Returns whether the rule from the given rule context has a allowlist by the given name. * * @param ruleContext The rule context to check - * @param whitelistName The name of the whitelist to check for. - * @return True if the given rule context has the given whitelist. + * @param allowlistName The name of the allowlist to check for. + * @return True if the given rule context has the given allowlist. */ - public static boolean hasWhitelist(RuleContext ruleContext, String whitelistName) { - String attributeName = getAttributeNameFromWhitelistName(whitelistName); + public static boolean hasAllowlist(RuleContext ruleContext, String allowlistName) { + String attributeName = getAttributeNameFromAllowlistName(allowlistName); return ruleContext.isAttrDefined(attributeName, LABEL); } - private static String getAttributeNameFromWhitelistName(String whitelistName) { - return String.format("$whitelist_%s", whitelistName); + private static String getAttributeNameFromAllowlistName(String allowlistName) { + return String.format("$whitelist_%s", allowlistName); } }
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/BUILD b/src/main/java/com/google/devtools/build/lib/analysis/BUILD index 463a645..559b481 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/BUILD +++ b/src/main/java/com/google/devtools/build/lib/analysis/BUILD
@@ -166,6 +166,7 @@ name = "analysis_cluster", srcs = [ "AliasProvider.java", + "Allowlist.java", "AnalysisEnvironment.java", "AnalysisFailureEvent.java", "AnalysisResult.java", @@ -217,7 +218,6 @@ "TargetContext.java", "TopLevelArtifactHelper.java", "Util.java", - "Whitelist.java", "WindowsBatchCommandConstructor.java", "WindowsPowershellCommandConstructor.java", "actions/ActionConstructionContext.java",
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/CommonPrerequisiteValidator.java b/src/main/java/com/google/devtools/build/lib/analysis/CommonPrerequisiteValidator.java index eeb7b5c..61e88d0 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/CommonPrerequisiteValidator.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/CommonPrerequisiteValidator.java
@@ -18,7 +18,7 @@ import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.PackageIdentifier; import com.google.devtools.build.lib.packages.Attribute; -import com.google.devtools.build.lib.packages.FunctionSplitTransitionWhitelist; +import com.google.devtools.build.lib.packages.FunctionSplitTransitionAllowlist; import com.google.devtools.build.lib.packages.InputFile; import com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper; import com.google.devtools.build.lib.packages.OutputFile; @@ -118,7 +118,7 @@ .contains("PackageSpecificationProvider"); // TODO(plf): Add the PackageSpecificationProvider to the 'visibility' attribute. if (!attrName.equals("visibility") - && !attrName.equals(FunctionSplitTransitionWhitelist.WHITELIST_ATTRIBUTE_NAME) + && !attrName.equals(FunctionSplitTransitionAllowlist.ATTRIBUTE_NAME) && !containsPackageSpecificationProvider) { context.attributeError( attrName,
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/StarlarkRuleClassFunctions.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/StarlarkRuleClassFunctions.java index 71dd187..e9a3b8e 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/StarlarkRuleClassFunctions.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/StarlarkRuleClassFunctions.java
@@ -56,7 +56,7 @@ import com.google.devtools.build.lib.packages.BuildSetting; import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.ExecGroup; -import com.google.devtools.build.lib.packages.FunctionSplitTransitionWhitelist; +import com.google.devtools.build.lib.packages.FunctionSplitTransitionAllowlist; import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.StarlarkImplicitOutputsFunctionWithCallback; import com.google.devtools.build.lib.packages.ImplicitOutputsFunction.StarlarkImplicitOutputsFunctionWithMap; import com.google.devtools.build.lib.packages.Package.NameConflictException; @@ -703,7 +703,7 @@ // Thus far, we only know if we have a rule transition. While iterating through attributes, // check if we have an attribute transition. boolean hasStarlarkDefinedTransition = builder.hasStarlarkRuleTransition(); - boolean hasFunctionTransitionWhitelist = false; + boolean hasFunctionTransitionAllowlist = false; for (Pair<String, StarlarkAttrModule.Descriptor> attribute : attributes) { String name = attribute.getFirst(); StarlarkAttrModule.Descriptor descriptor = attribute.getSecond(); @@ -720,56 +720,54 @@ } builder.setHasAnalysisTestTransition(); } - // Check for existence of the function transition whitelist attribute. - // TODO(b/121385274): remove when we stop whitelisting starlark transitions - if (name.equals(FunctionSplitTransitionWhitelist.WHITELIST_ATTRIBUTE_NAME)) { + // Check for existence of the function transition allowlist attribute. + // TODO(b/121385274): remove when we stop allowlisting starlark transitions + if (name.equals(FunctionSplitTransitionAllowlist.ATTRIBUTE_NAME)) { if (!BuildType.isLabelType(attr.getType())) { throw new EvalException( - getLocation(), "_whitelist_function_transition attribute must be a label type"); + getLocation(), "_allowlist_function_transition attribute must be a label type"); } if (attr.getDefaultValueUnchecked() == null) { throw new EvalException( getLocation(), - "_whitelist_function_transition attribute must have a default value"); + "_allowlist_function_transition attribute must have a default value"); } Label defaultLabel = (Label) attr.getDefaultValueUnchecked(); // Check the label value for package and target name, to make sure this works properly // in Bazel where it is expected to be found under @bazel_tools. if (!defaultLabel .getPackageName() - .equals(FunctionSplitTransitionWhitelist.WHITELIST_LABEL.getPackageName()) - || !defaultLabel - .getName() - .equals(FunctionSplitTransitionWhitelist.WHITELIST_LABEL.getName())) { + .equals(FunctionSplitTransitionAllowlist.LABEL.getPackageName()) + || !defaultLabel.getName().equals(FunctionSplitTransitionAllowlist.LABEL.getName())) { throw new EvalException( getLocation(), - "_whitelist_function_transition attribute (" + "_allowlist_function_transition attribute (" + defaultLabel + ") does not have the expected value " - + FunctionSplitTransitionWhitelist.WHITELIST_LABEL); + + FunctionSplitTransitionAllowlist.LABEL); } - hasFunctionTransitionWhitelist = true; - builder.setHasFunctionTransitionWhitelist(); + hasFunctionTransitionAllowlist = true; + builder.setHasFunctionTransitionAllowlist(); } addAttribute(builder, attr); } - // TODO(b/121385274): remove when we stop whitelisting starlark transitions + // TODO(b/121385274): remove when we stop allowlisting starlark transitions if (hasStarlarkDefinedTransition) { - if (!hasFunctionTransitionWhitelist) { + if (!hasFunctionTransitionAllowlist) { throw new EvalException( getLocation(), String.format( - "Use of Starlark transition without whitelist attribute" - + " '_whitelist_function_transition'. See Starlark transitions documentation" + "Use of Starlark transition without allowlist attribute" + + " '_allowlist_function_transition'. See Starlark transitions documentation" + " for details and usage: %s %s", builder.getRuleDefinitionEnvironmentLabel(), builder.getType())); } } else { - if (hasFunctionTransitionWhitelist) { + if (hasFunctionTransitionAllowlist) { throw new EvalException( getLocation(), String.format( - "Unused function-based split transition whitelist: %s %s", + "Unused function-based split transition allowlist: %s %s", builder.getRuleDefinitionEnvironmentLabel(), builder.getType())); } }
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/StarlarkRuleConfiguredTargetUtil.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/StarlarkRuleConfiguredTargetUtil.java index 7fff89b..d8830e5 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/StarlarkRuleConfiguredTargetUtil.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/StarlarkRuleConfiguredTargetUtil.java
@@ -20,6 +20,7 @@ import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException; import com.google.devtools.build.lib.analysis.ActionsProvider; +import com.google.devtools.build.lib.analysis.Allowlist; import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.analysis.DefaultInfo; import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; @@ -28,7 +29,6 @@ import com.google.devtools.build.lib.analysis.RunfilesProvider; import com.google.devtools.build.lib.analysis.RunfilesSupport; import com.google.devtools.build.lib.analysis.StarlarkProviderValidationUtil; -import com.google.devtools.build.lib.analysis.Whitelist; import com.google.devtools.build.lib.analysis.test.CoverageCommon; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesInfo; import com.google.devtools.build.lib.collect.nestedset.Depset; @@ -38,7 +38,7 @@ import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.packages.AdvertisedProviderSet; import com.google.devtools.build.lib.packages.BazelStarlarkContext; -import com.google.devtools.build.lib.packages.FunctionSplitTransitionWhitelist; +import com.google.devtools.build.lib.packages.FunctionSplitTransitionAllowlist; import com.google.devtools.build.lib.packages.Info; import com.google.devtools.build.lib.packages.NativeProvider; import com.google.devtools.build.lib.packages.NativeProvider.WithLegacyStarlarkName; @@ -120,11 +120,11 @@ + " should have been specified by the requesting rule."); return null; } - if (ruleClass.hasFunctionTransitionWhitelist() - && !Whitelist.isAvailableBasedOnRuleLocation( - ruleContext, FunctionSplitTransitionWhitelist.WHITELIST_NAME)) { - if (!Whitelist.isAvailable(ruleContext, FunctionSplitTransitionWhitelist.WHITELIST_NAME)) { - ruleContext.ruleError("Non-whitelisted use of Starlark transition"); + if (ruleClass.hasFunctionTransitionAllowlist() + && !Allowlist.isAvailableBasedOnRuleLocation( + ruleContext, FunctionSplitTransitionAllowlist.NAME)) { + if (!Allowlist.isAvailable(ruleContext, FunctionSplitTransitionAllowlist.NAME)) { + ruleContext.ruleError("Non-allowlisted use of Starlark transition"); } }