From c89e1f3d662f78ec995209a8c3fd83dc26630f79 Mon Sep 17 00:00:00 2001 From: mjhalupka Date: Thu, 8 Feb 2018 09:29:14 -0800 Subject: Remove another getTarget() call from PrintActionCommand. PiperOrigin-RevId: 185006324 --- .../lib/runtime/commands/PrintActionCommand.java | 41 ++++++++++++++-------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'src/main/java/com') 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() { @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 files) @@ -230,7 +230,7 @@ public final class PrintActionCommand implements BlazeCommand { Set 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 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