Remove another getTarget() call from PrintActionCommand.
PiperOrigin-RevId: 185006324
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/PrintActionCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/PrintActionCommand.java
index 6b4b266..8e4bc43 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/commands/PrintActionCommand.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/PrintActionCommand.java
@@ -130,8 +130,7 @@
this.options = options;
this.outErr = outErr;
this.requestedTargets = requestedTargets;
- KeepGoingOption keepGoingOption = options.getOptions(KeepGoingOption.class);
- keepGoing = keepGoingOption.keepGoing;
+ keepGoing = options.getOptions(KeepGoingOption.class).keepGoing;
summaryBuilder = ExtraActionSummary.newBuilder();
actionMnemonicMatcher = new Predicate<ActionAnalysisMetadata>() {
@Override
@@ -186,6 +185,7 @@
if (compileOneDependency) {
gatherActionsForFiles(
configuredTarget,
+ env,
actionGraph,
env.getSkyframeExecutor().getActionKeyContext(),
targets);
@@ -196,8 +196,7 @@
env.getPackageManager()
.getTarget(env.getReporter(), configuredTarget.getLabel());
} catch (NoSuchTargetException | NoSuchPackageException | InterruptedException e) {
- env.getReporter()
- .handle(Event.error(null, "Failed to find successful target in package"));
+ env.getReporter().handle(Event.error("Failed to find target to gather actions."));
return null;
}
gatherActionsForTarget(
@@ -223,6 +222,7 @@
private BuildResult gatherActionsForFiles(
ConfiguredTarget configuredTarget,
+ CommandEnvironment env,
ActionGraph actionGraph,
ActionKeyContext actionKeyContext,
List<String> files)
@@ -230,7 +230,7 @@
Set<String> filesDesired = new LinkedHashSet<>(files);
ActionFilter filter = new DefaultActionFilter(filesDesired, actionMnemonicMatcher);
- gatherActionsForFile(configuredTarget, filter, actionGraph, actionKeyContext);
+ gatherActionsForFile(configuredTarget, filter, env, actionGraph, actionKeyContext);
return null;
}
@@ -270,6 +270,7 @@
private void gatherActionsForFile(
ConfiguredTarget configuredTarget,
ActionFilter filter,
+ CommandEnvironment env,
ActionGraph actionGraph,
ActionKeyContext actionKeyContext)
throws CommandLineExpansionException {
@@ -282,7 +283,7 @@
for (Artifact artifact : artifacts) {
ActionAnalysisMetadata action = actionGraph.getGeneratingAction(artifact);
- if (filter.shouldOutput(action, configuredTarget, actionGraph)) {
+ if (filter.shouldOutput(action, configuredTarget, env)) {
if (action instanceof Action) {
DetailedExtraActionInfo.Builder detail = DetailedExtraActionInfo.newBuilder();
detail.setAction(((Action) action).getExtraActionInfo(actionKeyContext));
@@ -299,11 +300,9 @@
/** Filter for extra actions. */
private interface ActionFilter {
- /**
- * Returns true if the given action is not null and should be printed.
- */
- boolean shouldOutput(ActionAnalysisMetadata action, ConfiguredTarget configuredTarget,
- ActionGraph actionGraph);
+ /** Returns true if the given action is not null and should be printed. */
+ boolean shouldOutput(
+ ActionAnalysisMetadata action, ConfiguredTarget configuredTarget, CommandEnvironment env);
}
/**
@@ -361,14 +360,17 @@
}
@Override
- public boolean shouldOutput(ActionAnalysisMetadata action, ConfiguredTarget configuredTarget,
- ActionGraph actionGraph) {
+ public boolean shouldOutput(
+ ActionAnalysisMetadata action, ConfiguredTarget configuredTarget, CommandEnvironment env) {
if (action == null) {
return false;
}
// Check all the inputs for the configured target against the file we want argv for.
Set<Artifact> expandedArtifacts = Sets.newHashSet();
- expandRecursive(actionGraph, action.getInputs(), expandedArtifacts);
+ expandRecursive(
+ env.getSkyframeExecutor().getActionGraph(env.getReporter()),
+ action.getInputs(),
+ expandedArtifacts);
for (Artifact input : expandedArtifacts) {
if (filesDesired.remove(input.getRootRelativePath().getSafePathString())) {
return actionMnemonicMatcher.apply(action);
@@ -378,7 +380,16 @@
// C++ header files show up in the dependency on the Target, but not the ConfiguredTarget, so
// we also check the target's header files there.
RuleConfiguredTarget ruleConfiguredTarget = (RuleConfiguredTarget) configuredTarget;
- if (!ruleConfiguredTarget.getTarget().isAttrDefined("hdrs", BuildType.LABEL_LIST)) {
+ Rule rule;
+ try {
+ rule =
+ (Rule)
+ env.getPackageManager().getTarget(env.getReporter(), configuredTarget.getLabel());
+ } catch (NoSuchTargetException | NoSuchPackageException | InterruptedException e) {
+ env.getReporter().handle(Event.error("Failed to find target to determine output."));
+ return false;
+ }
+ if (!rule.isAttrDefined("hdrs", BuildType.LABEL_LIST)) {
return false;
}
List<Label> hdrs = ruleConfiguredTarget.getAttributeMapper()