From 79a0262547b05a3493555361c11f0c2f374e6e68 Mon Sep 17 00:00:00 2001 From: Daniel Brauner Date: Wed, 22 Jan 2025 10:51:11 +0100 Subject: [PATCH] Tiny optimization when handling errors (#7243) Do not parse build output twice. Bug: n/a Test: n/a Change-Id: I1a002a69cd6e3f2fbbbe445c7e1d4833449c2b9f AOSP: a63da90df16ee9a14c116045b95dcb60c0992b27 Co-authored-by: Googler --- .../BlazeApkDeployInfoProtoHelper.java | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/aswb/src/com/google/idea/blaze/android/run/deployinfo/BlazeApkDeployInfoProtoHelper.java b/aswb/src/com/google/idea/blaze/android/run/deployinfo/BlazeApkDeployInfoProtoHelper.java index b662533caf9..da8e08529dc 100644 --- a/aswb/src/com/google/idea/blaze/android/run/deployinfo/BlazeApkDeployInfoProtoHelper.java +++ b/aswb/src/com/google/idea/blaze/android/run/deployinfo/BlazeApkDeployInfoProtoHelper.java @@ -48,35 +48,31 @@ public AndroidDeployInfo readDeployInfoProtoForTarget( Label target, BuildResultHelper buildResultHelper, Predicate pathFilter) throws GetDeployInfoException { ImmutableList outputArtifacts; + ParsedBepOutput bepOutput; try { - outputArtifacts = - buildResultHelper.getBuildOutput(Optional.empty(), Interners.STRING).getDirectArtifactsForTarget(target, pathFilter).asList(); + bepOutput = buildResultHelper.getBuildOutput(Optional.empty(), Interners.STRING); + outputArtifacts = bepOutput.getDirectArtifactsForTarget(target, pathFilter).asList(); } catch (GetArtifactsException e) { throw new GetDeployInfoException(e.getMessage()); } if (outputArtifacts.isEmpty()) { Logger log = Logger.getInstance(BlazeApkDeployInfoProtoHelper.class.getName()); - try { - ParsedBepOutput bepOutput = buildResultHelper.getBuildOutput(Optional.empty(), Interners.STRING); - log.warn("Local execroot: " + bepOutput.getLocalExecRoot()); - log.warn("All output artifacts:"); - for (OutputArtifact outputArtifact : bepOutput.getAllOutputArtifacts(path -> true)) { - log.warn(outputArtifact.getBazelOutRelativePath() + " -> " + outputArtifact.getBazelOutRelativePath()); - } - log.warn("All local artifacts for " + target + ":"); - List allBuildArtifacts = - buildResultHelper.getBuildOutput(Optional.empty(), Interners.STRING).getDirectArtifactsForTarget(target, path1 -> true).asList(); - List allLocalFiles = LocalFileArtifact.getLocalFiles(allBuildArtifacts); - for (File file : allLocalFiles) { - String path = file.getPath(); - log.warn(path); - if (pathFilter.test(path)) { - log.warn("Note: " + path + " passes pathFilter but was not recognized!"); - } + log.warn("Local execroot: " + bepOutput.getLocalExecRoot()); + log.warn("All output artifacts:"); + for (OutputArtifact outputArtifact : bepOutput.getAllOutputArtifacts(path -> true)) { + log.warn(outputArtifact.getBazelOutRelativePath() + " -> " + outputArtifact.getBazelOutRelativePath()); + } + log.warn("All local artifacts for " + target + ":"); + List allBuildArtifacts = + bepOutput.getDirectArtifactsForTarget(target, path1 -> true).asList(); + List allLocalFiles = LocalFileArtifact.getLocalFiles(allBuildArtifacts); + for (File file : allLocalFiles) { + String path = file.getPath(); + log.warn(path); + if (pathFilter.test(path)) { + log.warn("Note: " + path + " passes pathFilter but was not recognized!"); } - } catch (GetArtifactsException e) { - log.warn("Error occured when gathering logs:", e); } throw new GetDeployInfoException( "No deploy info proto artifact found. Was android_deploy_info in the output groups?");