More validation on @_builtins loads
- Can only load from other builtins bzls
- No subpackages in builtins bzls
Also add more test cases, move test cases around.
StarlarkBuiltinsFunctionTest:
- Add assertion helper, factor removal of failFastHandler
- Add test of digest of StarlarkBuiltinsValue
- Move tests involving loads of builtins helpers to BuiltinsInjectionTest
BuiltinsInjectionTest:
- Replace build-without-asserting helper with build-and-assert-failure helper, factor removal of failFastHandler
- Test loading builtins helpers via relative label syntax
- Move tests of what symbols are accessible to StarlarkBuiltinsFunctionTest
Work toward #11437.
PiperOrigin-RevId: 339157512
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadFunction.java
index b4d3065..f35d3f3 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadFunction.java
@@ -531,13 +531,17 @@
private BzlCompileValue.Key validatePackageAndGetCompileKey(
BzlLoadValue.Key key, Environment env, StarlarkSemantics starlarkSemantics)
throws BzlLoadFailedException, InterruptedException {
+ Label label = key.getLabel();
+
// Bypass package lookup entirely if builtins.
if (key.isBuiltins()) {
+ if (!label.getPackageName().isEmpty()) {
+ throw BzlLoadFailedException.noBuildFile(label, "@_builtins cannot have subpackages");
+ }
return key.getCompileKey(getBuiltinsRoot(starlarkSemantics));
}
// Do package lookup.
- Label label = key.getLabel();
PathFragment dir = Label.getContainingDirectory(label);
PackageIdentifier dirId = PackageIdentifier.create(label.getRepository(), dir);
ContainingPackageLookupValue packageLookup;
@@ -777,6 +781,11 @@
throw new LabelSyntaxException(
"Starlark files may not be loaded from the //external package");
}
+ if (StarlarkBuiltinsValue.isBuiltinsRepo(base.getRepository())
+ && !StarlarkBuiltinsValue.isBuiltinsRepo(label.getRepository())) {
+ throw new LabelSyntaxException(
+ ".bzl files in @_builtins cannot load from outside of @_builtins");
+ }
loads.add(Pair.of(module, label));
} catch (LabelSyntaxException ex) {
handler.handle(