Expose aspect actions from Skylark.
Like with providers, consumers get a merged view of all actions from the merged configured target (all other aspects + the base target).
I had to rejig the aspect value / configured aspect to be symmetric with rule configured targets.
I do not expect significant memory bloat from this. All lists / maps already existed, only extra fields have been added.
RELNOTES: Expose aspect actions provider to Skylark.
PiperOrigin-RevId: 201697923
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAspect.java b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAspect.java
index a33e6fe..e99d134 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAspect.java
@@ -18,10 +18,14 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.actions.ActionAnalysisMetadata;
+import com.google.devtools.build.lib.actions.Actions;
+import com.google.devtools.build.lib.actions.Actions.GeneratingActions;
import com.google.devtools.build.lib.actions.Artifact;
+import com.google.devtools.build.lib.actions.MutableActionGraph.ActionConflictException;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
@@ -57,12 +61,20 @@
@Immutable
@AutoCodec
public final class ConfiguredAspect {
- private final TransitiveInfoProviderMap providers;
private final AspectDescriptor descriptor;
+ private final ImmutableList<ActionAnalysisMetadata> actions;
+ private final ImmutableMap<Artifact, Integer> generatingActionIndex;
+ private final TransitiveInfoProviderMap providers;
@AutoCodec.VisibleForSerialization
- ConfiguredAspect(AspectDescriptor descriptor, TransitiveInfoProviderMap providers) {
+ ConfiguredAspect(
+ AspectDescriptor descriptor,
+ ImmutableList<ActionAnalysisMetadata> actions,
+ ImmutableMap<Artifact, Integer> generatingActionIndex,
+ TransitiveInfoProviderMap providers) {
this.descriptor = descriptor;
+ this.actions = actions;
+ this.generatingActionIndex = generatingActionIndex;
this.providers = providers;
}
@@ -80,6 +92,18 @@
return descriptor;
}
+ public ImmutableList<ActionAnalysisMetadata> getActions() {
+ return actions;
+ }
+
+ /**
+ * Returns a map where keys are artifacts that are action outputs of this rule, and values are the
+ * index of the action that generates that artifact.
+ */
+ public ImmutableMap<Artifact, Integer> getGeneratingActionIndex() {
+ return generatingActionIndex;
+ }
+
/** Returns the providers created by the aspect. */
public TransitiveInfoProviderMap getProviders() {
return providers;
@@ -112,11 +136,16 @@
}
public static ConfiguredAspect forAlias(ConfiguredAspect real) {
- return new ConfiguredAspect(real.descriptor, real.getProviders());
+ return new ConfiguredAspect(
+ real.descriptor, real.getActions(), real.getGeneratingActionIndex(), real.getProviders());
}
public static ConfiguredAspect forNonapplicableTarget(AspectDescriptor descriptor) {
- return new ConfiguredAspect(descriptor, new TransitiveInfoProviderMapBuilder().add().build());
+ return new ConfiguredAspect(
+ descriptor,
+ ImmutableList.of(),
+ ImmutableMap.of(),
+ new TransitiveInfoProviderMapBuilder().add().build());
}
public static Builder builder(
@@ -230,8 +259,7 @@
return this;
}
-
- public ConfiguredAspect build() {
+ public ConfiguredAspect build() throws ActionConflictException {
if (!outputGroupBuilders.isEmpty()) {
ImmutableMap.Builder<String, NestedSet<Artifact>> outputGroups = ImmutableMap.builder();
for (Map.Entry<String, NestedSetBuilder<Artifact>> entry : outputGroupBuilders.entrySet()) {
@@ -250,7 +278,17 @@
/* actionsWithoutExtraAction= */ ImmutableSet.<ActionAnalysisMetadata>of(),
ruleContext));
- return new ConfiguredAspect(descriptor, providers.build());
+ AnalysisEnvironment analysisEnvironment = ruleContext.getAnalysisEnvironment();
+ GeneratingActions generatingActions =
+ Actions.filterSharedActionsAndThrowActionConflict(
+ analysisEnvironment.getActionKeyContext(),
+ analysisEnvironment.getRegisteredActions());
+
+ return new ConfiguredAspect(
+ descriptor,
+ generatingActions.getActions(),
+ generatingActions.getGeneratingActionIndex(),
+ providers.build());
}
}
}