aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar mjhalupka <mjhalupka@google.com>2018-02-08 09:29:14 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-08 09:31:14 -0800
commitc89e1f3d662f78ec995209a8c3fd83dc26630f79 (patch)
treecb17e1bf6aaa50d99b602f4b79be8d07fd25084b /src/main/java/com/google/devtools/build
parent0589fdfd42657e4b452538fa40d1a9e5d31a30fd (diff)
Remove another getTarget() call from PrintActionCommand.
PiperOrigin-RevId: 185006324
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/commands/PrintActionCommand.java41
1 files changed, 26 insertions, 15 deletions
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 6b4b266076..8e4bc43c6f 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 @@ public final class PrintActionCommand implements BlazeCommand {
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 @@ public final class PrintActionCommand implements BlazeCommand {
if (compileOneDependency) {
gatherActionsForFiles(
configuredTarget,
+ env,
actionGraph,
env.getSkyframeExecutor().getActionKeyContext(),
targets);
@@ -196,8 +196,7 @@ public final class PrintActionCommand implements BlazeCommand {
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 @@ public final class PrintActionCommand implements BlazeCommand {
private BuildResult gatherActionsForFiles(
ConfiguredTarget configuredTarget,
+ CommandEnvironment env,
ActionGraph actionGraph,
ActionKeyContext actionKeyContext,
List<String> files)
@@ -230,7 +230,7 @@ public final class PrintActionCommand implements BlazeCommand {
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 @@ public final class PrintActionCommand implements BlazeCommand {
private void gatherActionsForFile(
ConfiguredTarget configuredTarget,
ActionFilter filter,
+ CommandEnvironment env,
ActionGraph actionGraph,
ActionKeyContext actionKeyContext)
throws CommandLineExpansionException {
@@ -282,7 +283,7 @@ public final class PrintActionCommand implements BlazeCommand {
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 @@ public final class PrintActionCommand implements BlazeCommand {
/** 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 @@ public final class PrintActionCommand implements BlazeCommand {
}
@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 @@ public final class PrintActionCommand implements BlazeCommand {
// 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()