Refactor Package.Builder#fromOrFail variants
This is a cleanup that attempts to rationalize the various ways of validating that the current Starlark context is a BUILD thread, or a WORKSPACE thread, or a symbolic macro thread, or some combination of the above. It increases the total lines of code, but it avoids the awkward idiom of calling two different fromOrFail* methods to assert "not this context AND not that context either".
The semantics of some callables are slightly modified to prohibit usage in places where they probably wouldn't/couldn't be called anyway, e.g. vardef now disallows WORKSPACE usage, although it wasn't a top-level symbol in WORKSPACE anyway.
This is a follow-up to reviewer discussion from unknown commit.
PiperOrigin-RevId: 649080769
Change-Id: I3742b44f1d13d5cf81ef2e256d2a430dfa124813
diff --git a/src/main/java/com/google/devtools/build/lib/packages/PackageCallable.java b/src/main/java/com/google/devtools/build/lib/packages/PackageCallable.java
index d72b0c0..0a9efa7 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/PackageCallable.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/PackageCallable.java
@@ -38,8 +38,7 @@
useStarlarkThread = true)
public Object packageCallable(Map<String, Object> kwargs, StarlarkThread thread)
throws EvalException {
- Package.Builder pkgBuilder =
- Package.Builder.fromOrFailDisallowingSymbolicMacros(thread, "package()");
+ Package.Builder pkgBuilder = Package.Builder.fromOrFailAllowBuildOnly(thread, "package()");
if (pkgBuilder.isPackageFunctionUsed()) {
throw new EvalException("'package' can only be used once per BUILD file");
}