C++: Changes check for flag_enabled() whitelist
Changes it to the location instead of repo name.
RELNOTES:none
PiperOrigin-RevId: 299863834
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java
index 6f52329..0311248 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/skylark/SkylarkRepositoryContext.java
@@ -92,6 +92,10 @@
implements SkylarkRepositoryContextApi<RepositoryFunctionException> {
private static final ImmutableList<String> WHITELISTED_REPOS_FOR_FLAG_ENABLED =
ImmutableList.of("@rules_cc", "@bazel_tools");
+ private static final ImmutableList<String> WHITELISTED_PATHS_FOR_FLAG_ENABLED =
+ ImmutableList.of(
+ "rules_cc/cc/private/toolchain/unix_cc_configure.bzl",
+ "bazel_tools/tools/cpp/unix_cc_configure.bzl");
private final Rule rule;
private final PathPackageLocator packageLocator;
@@ -842,14 +846,10 @@
}
@Override
- public boolean flagEnabled(String flag) throws EvalException {
+ public boolean flagEnabled(String flag, StarlarkThread starlarkThread) throws EvalException {
try {
- if (!WHITELISTED_REPOS_FOR_FLAG_ENABLED.contains(
- rule.getRuleClassObject()
- .getRuleDefinitionEnvironmentLabel()
- .getPackageIdentifier()
- .getRepository()
- .getName())) {
+ if (WHITELISTED_PATHS_FOR_FLAG_ENABLED.stream()
+ .noneMatch(x -> !starlarkThread.getCallerLocation().toString().endsWith(x))) {
throw Starlark.errorf(
"flag_enabled() is restricted to: '%s'.",
Joiner.on(", ").join(WHITELISTED_REPOS_FOR_FLAG_ENABLED));
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/repository/SkylarkRepositoryContextApi.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/repository/SkylarkRepositoryContextApi.java
index d073435..e0e1091 100644
--- a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/repository/SkylarkRepositoryContextApi.java
+++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/repository/SkylarkRepositoryContextApi.java
@@ -588,8 +588,9 @@
doc =
"This method is present temporarily for a migration. It can be used only by a few "
+ "whitelisted bzl files embedded in Bazel.",
+ useStarlarkThread = true,
parameters = {
@Param(name = "flag", type = String.class, doc = "Flag to get the value for."),
})
- boolean flagEnabled(String flag) throws EvalException;
+ boolean flagEnabled(String flag, StarlarkThread starlarkThread) throws EvalException;
}