Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 721772866
Change-Id: I79e71eb1a7f24d3d1f3c40145115d5acee70f360
  • Loading branch information
susinmotion authored and copybara-github committed Jan 31, 2025
1 parent 3d96b45 commit 7fe187e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public final class FlagSetFunction implements SkyFunction {

private static final String DEFAULT_CONFIG = "default_config";
private static final String ENFORCEMENT_POLICY = "enforcement_policy";
private static final String ALWAYS_ALLOWED_CONFIGS = "always_allowed_configs";

private enum EnforcementPolicy {
WARN("warn"), // Default, enforced in getSclConfig().
Expand Down Expand Up @@ -213,8 +214,14 @@ sclConfigName, supportedConfigsDesc(projectFile, configs))),
return ImmutableSet.of();
}

Collection<String> alwaysAllowedConfigs =
!sclContent.getProject().containsKey(ALWAYS_ALLOWED_CONFIGS)
? ImmutableList.of()
: (Collection<String>) sclContent.getProject().get(ALWAYS_ALLOWED_CONFIGS);

validateNoExtraFlagsSet(
enforcementPolicy,
alwaysAllowedConfigs,
buildOptionsAsStrings,
key.getUserOptions(),
optionsToApply,
Expand Down Expand Up @@ -362,9 +369,13 @@ private static ImmutableList<String> expandConfigFlags(
*
* <p>Conflicting output-affecting options may be set in global RC files (including the {@code
* InvocationPolicy}). Flags that do not affect outputs are always allowed.
*
* @param userOptions the user options set in the command line or user bazelrc as a map from
* option.getCanonicalForm()to option.getExpandedFrom(), {"--define=foo=bar": "--config=foo"}.
*/
private static void validateNoExtraFlagsSet(
EnforcementPolicy enforcementPolicy,
Collection<String> alwaysAllowedConfigs,
ImmutableList<String> buildOptionsAsStrings,
ImmutableMap<String, String> userOptions,
ImmutableSet<String> flagsFromSelectedConfig,
Expand All @@ -383,6 +394,12 @@ private static void validateNoExtraFlagsSet(
.replace("'", "")))
.filter(option -> !option.startsWith("--scl_config"))
.filter(option -> !flagsFromSelectedConfig.contains(option))
// Remove options that are expanded from always-allowed configs either defined in the
// project file...
.filter(option -> !alwaysAllowedConfigs.contains(userOptions.get(option)))
// ... or globally
.filter(
option -> !GlobalRcUtils.ALLOWED_GLOBAL_CONFIGS.contains(userOptions.get(option)))
.map(
option ->
userOptions.get(option).isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public final class GlobalRcUtils {

private GlobalRcUtils() {}

/* No global RC files in Bazel, so no global configs. */
public static final ImmutableList<String> ALLOWED_GLOBAL_CONFIGS = ImmutableList.of();

private static final ImmutableList<String> GLOBAL_RC_FILES =
ImmutableList.of(
// LINT.IfChange
Expand Down

0 comments on commit 7fe187e

Please sign in to comment.