Add a cquery mode that shows which configuration fragments rules need.
Usage:
$ blaze cquery 'deps(//:mytarget)' --show_config_fragments=direct
$ blaze cquery 'deps(//:mytarget)' --show_config_fragments=transitive
For each <label, config> line in cquery's output, this also prints a list
of all configuration fragments required by a rule. If
--show_config_fragments=direct, this includes fragments directly required
by the rule. If --show_config_fragments=transitive, this includes fragments
required by the rule and its transitive dependencies.
This can be useful for evaluating how much graphs can be trimmed with
transitions.
Notes:
? This includes select().
? This includes toolchain dependencies.
? This properly passes through aliases.
X This doesn't (yet) include Starlark-defined builds settings.
X This doesn't include flags read by Starlark or native transitions.
X This doesn't include feature flags.
- The new provider applies to all configured targets, which means more
memory. So this provider is only created when --show_config_fragments
is set. One consequence of this is that Blaze has to reanalyze the build if
you switch between querying it and actually building it.
PiperOrigin-RevId: 275558937
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 76e799d..96f4ebf 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
@@ -192,6 +192,7 @@
private final RuleErrorConsumer reporter;
@Nullable private final ResolvedToolchainContext toolchainContext;
private final ConstraintSemantics constraintSemantics;
+ private final ImmutableSet<String> requiredConfigFragments;
private ActionOwner actionOwner;
private final SymbolGenerator<ActionLookupValue.ActionLookupKey> actionOwnerSymbolGenerator;
@@ -210,7 +211,8 @@
ActionLookupValue.ActionLookupKey actionLookupKey,
ImmutableMap<String, Attribute> aspectAttributes,
@Nullable ResolvedToolchainContext toolchainContext,
- ConstraintSemantics constraintSemantics) {
+ ConstraintSemantics constraintSemantics,
+ ImmutableSet<String> requiredConfigFragments) {
super(
builder.env,
builder.target.getAssociatedRule(),
@@ -242,6 +244,7 @@
reporter = builder.reporter;
this.toolchainContext = toolchainContext;
this.constraintSemantics = constraintSemantics;
+ this.requiredConfigFragments = requiredConfigFragments;
}
private void getAllFeatures(Set<String> allEnabledFeatures, Set<String> allDisabledFeatures) {
@@ -1219,6 +1222,10 @@
return constraintSemantics;
}
+ public ImmutableSet<String> getRequiredConfigFragments() {
+ return requiredConfigFragments;
+ }
+
public Map<String, String> getTargetExecProperties() {
if (isAttrDefined(RuleClass.EXEC_PROPERTIES, Type.STRING_DICT)) {
return attributes.get(RuleClass.EXEC_PROPERTIES, Type.STRING_DICT);
@@ -1585,6 +1592,7 @@
private ImmutableList<Aspect> aspects;
private ResolvedToolchainContext toolchainContext;
private ConstraintSemantics constraintSemantics;
+ private ImmutableSet<String> requiredConfigFragments = ImmutableSet.of();
@VisibleForTesting
public Builder(
@@ -1636,7 +1644,8 @@
actionOwnerSymbol,
aspectAttributes != null ? aspectAttributes : ImmutableMap.<String, Attribute>of(),
toolchainContext,
- constraintSemantics);
+ constraintSemantics,
+ requiredConfigFragments);
}
private void validateAttributes(AttributeMap attributes) {
@@ -1703,6 +1712,11 @@
return this;
}
+ public Builder setRequiredConfigFragments(ImmutableSet<String> requiredConfigFragments) {
+ this.requiredConfigFragments = requiredConfigFragments;
+ return this;
+ }
+
private boolean validateFilesetEntry(FilesetEntry filesetEntry, ConfiguredTargetAndData src) {
NestedSet<Artifact> filesToBuild =
src.getConfiguredTarget().getProvider(FileProvider.class).getFilesToBuild();