bazel packages: add --record_rule_instantiation_callstack flag
This flag (default: false) causes each rule to record the Starlark
call stack at the moment of its instantiation.
The stacks are displayed by blaze query --output=build.
Example output:
# /workspace/x/BUILD:2:1
cc_library(
name = "a",
...
)
# Instantiation stack:
# /workspace/x/inc.bzl:4:3 called from g
# /workspace/x/inc.bzl:2:3 called from f
# /workspace/x/BUILD:2:1 called from <toplevel>
By combining two optimizations, prefix sharing using a linked tree,
and element compression using packed integers, this feature
imposes an additional retained heap space cost of only 1.5%
for deps(//X) where X is Google's web server.
PiperOrigin-RevId: 300408104
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
index 9b5504b..89b9edb 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
@@ -60,6 +60,7 @@
import com.google.devtools.build.lib.syntax.Sequence;
import com.google.devtools.build.lib.syntax.Starlark;
import com.google.devtools.build.lib.syntax.StarlarkFunction;
+import com.google.devtools.build.lib.syntax.StarlarkThread;
import com.google.devtools.build.lib.util.FileTypeSet;
import com.google.devtools.build.lib.util.StringUtil;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -1833,10 +1834,11 @@
AttributeValues<T> attributeValues,
EventHandler eventHandler,
Location location,
+ List<StarlarkThread.CallStackEntry> callstack,
AttributeContainer attributeContainer,
boolean checkThirdPartyRulesHaveLicenses)
throws LabelSyntaxException, InterruptedException, CannotPrecomputeDefaultsException {
- Rule rule = pkgBuilder.createRule(ruleLabel, this, location, attributeContainer);
+ Rule rule = pkgBuilder.createRule(ruleLabel, this, location, callstack, attributeContainer);
populateRuleAttributeValues(rule, pkgBuilder, attributeValues, eventHandler);
checkAspectAllowedValues(rule, eventHandler);
rule.populateOutputFiles(eventHandler, pkgBuilder);
@@ -1870,15 +1872,13 @@
Label ruleLabel,
AttributeValues<T> attributeValues,
Location location,
+ List<StarlarkThread.CallStackEntry> callstack,
AttributeContainer attributeContainer,
ImplicitOutputsFunction implicitOutputsFunction)
throws InterruptedException, CannotPrecomputeDefaultsException {
- Rule rule = pkgBuilder.createRule(
- ruleLabel,
- this,
- location,
- attributeContainer,
- implicitOutputsFunction);
+ Rule rule =
+ pkgBuilder.createRule(
+ ruleLabel, this, location, callstack, attributeContainer, implicitOutputsFunction);
populateRuleAttributeValues(rule, pkgBuilder, attributeValues, NullEventHandler.INSTANCE);
rule.populateOutputFilesUnchecked(NullEventHandler.INSTANCE, pkgBuilder);
return rule;