Freeze mutability right after evaluating the rule's implementation function
This makes the postprocessing safer. That the providers (and the data within them) are frozen is needed before we can change their memory layout. That is, for a follow up change that will reduce their memory footprint.
Move the postprocessing part, call to createTarget, from the end of buildRule call, a level higher, to ConfiguredTargetFactory.
Pass only RuleContext to createTarget, because StarlarkRuleContext is closed.
Fish isDefaultExecutableCreated from StarlarkRuleContext and knit it through createTarget to its consumers.
Inline BadRuleImplementation exception.
Move try-finally block in ConfiguredTargetFactory one level deeper, to mak eit possible to close rule context sooner.
Store lookedUpVariables in RuleContext after StarlarkRuleContext is closed - they are needed when constructing configured target.
PiperOrigin-RevId: 510986457
Change-Id: Ic8837b50dd25a15bd30908d3445873d967394ea2
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
index 7fbaadf..eb1261cc6 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
@@ -1207,6 +1207,7 @@
starlarkThread.mutability().freeze();
if (starlarkRuleContext != null) {
starlarkRuleContext.nullify();
+ starlarkRuleContext = null;
}
}
@@ -1305,8 +1306,16 @@
return ruleClassProvider;
}
- /** Returns the configuration fragments this rule uses. */
+ /**
+ * Returns the configuration fragments this rule uses if it should be included for this rule.
+ * Otherwise it returns null.
+ */
+ @Nullable
public RequiredConfigFragmentsProvider getRequiredConfigFragments() {
+ if (requiredConfigFragments == null) {
+ return null;
+ }
+
RequiredConfigFragmentsProvider.Builder merged = null;
// Add variables accessed through ctx.var, if this is a Starlark rule.