diff --git a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleClassFunctions.java b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleClassFunctions.java index 115f500ad42a21..92712dddf9f082 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleClassFunctions.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkRuleClassFunctions.java @@ -933,6 +933,12 @@ public boolean isImmutable() { @Override public Label label(String labelString, StarlarkThread thread) throws EvalException { + // The label string is interpeted with respect to the .bzl module containing the call to + // `Label()`. An alternative to this approach that avoids stack inspection is to have each .bzl + // module define its own copy of the `Label()` builtin embedding the module's own name. This + // would lead to peculiarities like foo.bzl being able to call bar.bzl's `Label()` symbol to + // resolve strings as if it were bar.bzl. It also would prevent sharing the same builtins + // environment across .bzl files. Hence, we opt for stack inspection. BazelModuleContext moduleContext = BazelModuleContext.of(Module.ofInnermostEnclosingStarlarkFunction(thread)); try {