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 aa369a0861b..0c1f1f91555 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 @@ -26,6 +26,7 @@ import com.google.idea.blaze.base.command.buildresult.LocalFileArtifact; import com.google.idea.blaze.base.command.buildresult.ParsedBepOutput; import com.google.idea.blaze.base.model.primitives.Label; +import com.google.idea.blaze.common.Interners; import com.google.idea.blaze.common.artifact.OutputArtifact; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; @@ -33,6 +34,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.List; +import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -55,7 +57,7 @@ public AndroidDeployInfo readDeployInfoProtoForTarget( if (outputArtifacts.isEmpty()) { Logger log = Logger.getInstance(BlazeApkDeployInfoProtoHelper.class.getName()); try { - ParsedBepOutput bepOutput = buildResultHelper.getBuildOutput(); + 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)) { diff --git a/base/BUILD b/base/BUILD index 75f35502827..897cd27d922 100644 --- a/base/BUILD +++ b/base/BUILD @@ -485,6 +485,7 @@ java_library( ":base", "//shared:artifact", "//shared:exception", + "//shared/java/com/google/idea/blaze/common", "//testing:lib", "//third_party/bazel/src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream_java_proto", "//third_party/java/auto_value", @@ -544,6 +545,7 @@ intellij_unit_test_suite( "//querysync/javatests/com/google/idea/blaze/qsync/testdata", "//shared", "//shared:artifact", + "//shared/java/com/google/idea/blaze/common", "//shared/javatests/com/google/idea/blaze/common:test_utils", "//shared/javatests/com/google/idea/blaze/common/artifact:test_utils", "//testing:lib", diff --git a/base/src/com/google/idea/blaze/base/buildview/BazelExecService.kt b/base/src/com/google/idea/blaze/base/buildview/BazelExecService.kt index 6a4e0e4ad88..221378b3184 100644 --- a/base/src/com/google/idea/blaze/base/buildview/BazelExecService.kt +++ b/base/src/com/google/idea/blaze/base/buildview/BazelExecService.kt @@ -9,6 +9,7 @@ import com.google.idea.blaze.base.model.primitives.WorkspaceRoot import com.google.idea.blaze.base.scope.BlazeContext import com.google.idea.blaze.base.sync.aspects.BlazeBuildOutputs import com.google.idea.blaze.base.sync.aspects.BuildResult +import com.google.idea.blaze.common.Interners import com.google.idea.blaze.common.PrintOutput import com.google.protobuf.CodedInputStream import com.intellij.execution.configurations.PtyCommandLine @@ -27,6 +28,7 @@ import com.intellij.util.ui.EDT import kotlinx.coroutines.* import java.io.BufferedInputStream import java.io.FileInputStream +import java.util.Optional import kotlin.io.path.pathString private val LOG: Logger = Logger.getInstance(BazelExecService::class.java) @@ -185,7 +187,10 @@ class BazelExecService(private val project: Project) : Disposable { if (result.status == BuildResult.Status.FATAL_ERROR) { BlazeBuildOutputs.noOutputs(result) } else { - BlazeBuildOutputs.fromParsedBepOutput(result, provider.getBuildOutput()) + BlazeBuildOutputs.fromParsedBepOutput( + result, + provider.getBuildOutput(Optional.empty(), Interners.STRING), + ) } } } diff --git a/base/src/com/google/idea/blaze/base/command/CommandLineBlazeCommandRunner.java b/base/src/com/google/idea/blaze/base/command/CommandLineBlazeCommandRunner.java index b67aa41e892..d9eabc3538a 100644 --- a/base/src/com/google/idea/blaze/base/command/CommandLineBlazeCommandRunner.java +++ b/base/src/com/google/idea/blaze/base/command/CommandLineBlazeCommandRunner.java @@ -94,7 +94,7 @@ public BlazeBuildOutputs run( Optional.ofNullable(context.getScope(SharedStringPoolScope.class)) .map(SharedStringPoolScope::getStringInterner) .orElse(null); - ParsedBepOutput buildOutput = buildResultHelper.getBuildOutput(stringInterner); + ParsedBepOutput buildOutput = buildResultHelper.getBuildOutput(Optional.empty(), stringInterner); context.output(PrintOutput.log("BEP outputs retrieved (%s).", StringUtilRt.formatFileSize(buildOutput.getBepBytesConsumed()))); return BlazeBuildOutputs.fromParsedBepOutput(buildResult, buildOutput); } catch (GetArtifactsException e) { diff --git a/base/src/com/google/idea/blaze/base/command/buildresult/BuildResultHelper.java b/base/src/com/google/idea/blaze/base/command/buildresult/BuildResultHelper.java index 8e7a6cc95ee..04821996260 100644 --- a/base/src/com/google/idea/blaze/base/command/buildresult/BuildResultHelper.java +++ b/base/src/com/google/idea/blaze/base/command/buildresult/BuildResultHelper.java @@ -20,6 +20,7 @@ import com.google.idea.blaze.base.model.primitives.Label; import com.google.idea.blaze.base.run.testlogs.BlazeTestResults; import com.google.idea.blaze.base.scope.BlazeContext; +import com.google.idea.blaze.common.Interners; import com.google.idea.blaze.common.artifact.OutputArtifact; import com.google.idea.blaze.exception.BuildException; import java.io.InputStream; @@ -46,46 +47,9 @@ public interface BuildResultHelper extends AutoCloseable { * getBuildOutput may restrict parallelism for cases in which many builds are executed in parallel * (e.g. remote builds). */ - default ParsedBepOutput getBuildOutput() throws GetArtifactsException { - return getBuildOutput(Optional.empty()); - } - - /** - * Parses the BEP output data and returns the corresponding {@link ParsedBepOutput}. May only be - * called once, after the build is complete. - * - *

As BEP retrieval can be memory-intensive for large projects, implementations of - * getBuildOutput may restrict parallelism for cases in which many builds are executed in parallel - * (e.g. remote builds). - */ - default ParsedBepOutput getBuildOutput(Interner stringInterner) - throws GetArtifactsException { - return getBuildOutput(Optional.empty(), stringInterner); - } - - /** - * Parses the BEP output data and returns the corresponding {@link ParsedBepOutput}. May only be - * called once, after the build is complete. - * - *

As BEP retrieval can be memory-intensive for large projects, implementations of - * getBuildOutput may restrict parallelism for cases in which many builds are executed in parallel - * (e.g. remote builds). - */ - default ParsedBepOutput getBuildOutput( + ParsedBepOutput getBuildOutput( Optional completionBuildId, Interner stringInterner) - throws GetArtifactsException { - return getBuildOutput(completionBuildId); - } - - /** - * Retrieves BEP build events according to given id, parses them and returns the corresponding - * {@link ParsedBepOutput}. May only be called once, after the build is complete. - * - *

As BEP retrieval can be memory-intensive for large projects, implementations of - * getBuildOutput may restrict parallelism for cases in which many builds are executed in parallel - * (e.g. remote builds). - */ - ParsedBepOutput getBuildOutput(Optional completedBuildId) throws GetArtifactsException; + throws GetArtifactsException; /** * Retrieves test results, parses them and returns the corresponding {@link BlazeTestResults}. May @@ -146,7 +110,7 @@ default BuildFlags getBlazeFlags() throws GetFlagsException { */ default ImmutableList getAllOutputArtifacts(Predicate pathFilter) throws GetArtifactsException { - return getBuildOutput().getAllOutputArtifacts(pathFilter).asList(); + return getBuildOutput(Optional.empty(), Interners.STRING).getAllOutputArtifacts(pathFilter).asList(); } /** @@ -157,7 +121,7 @@ default ImmutableList getAllOutputArtifacts(Predicate pa */ default ImmutableList getBuildArtifactsForTarget( Label target, Predicate pathFilter) throws GetArtifactsException { - return getBuildOutput().getDirectArtifactsForTarget(target, pathFilter).asList(); + return getBuildOutput(Optional.empty(), Interners.STRING).getDirectArtifactsForTarget(target, pathFilter).asList(); } /** @@ -166,7 +130,7 @@ default ImmutableList getBuildArtifactsForTarget( */ default ImmutableList getArtifactsForOutputGroup( String outputGroup, Predicate pathFilter) throws GetArtifactsException { - return getBuildOutput().getOutputGroupArtifacts(outputGroup, pathFilter); + return getBuildOutput(Optional.empty(), Interners.STRING).getOutputGroupArtifacts(outputGroup, pathFilter); } @Override diff --git a/base/src/com/google/idea/blaze/base/command/buildresult/BuildResultHelperBep.java b/base/src/com/google/idea/blaze/base/command/buildresult/BuildResultHelperBep.java index bfb24bda2f9..3796670d6c0 100644 --- a/base/src/com/google/idea/blaze/base/command/buildresult/BuildResultHelperBep.java +++ b/base/src/com/google/idea/blaze/base/command/buildresult/BuildResultHelperBep.java @@ -15,6 +15,7 @@ */ package com.google.idea.blaze.base.command.buildresult; +import com.google.common.collect.Interner; import com.google.idea.blaze.base.command.buildresult.BuildEventStreamProvider.BuildEventStreamException; import com.google.idea.blaze.base.io.InputStreamProvider; import com.google.idea.blaze.base.run.testlogs.BlazeTestResults; @@ -55,7 +56,7 @@ public List getBuildFlags() { } @Override - public ParsedBepOutput getBuildOutput(Optional completedBuildId) + public ParsedBepOutput getBuildOutput(Optional completedBuildId, Interner stringInterner) throws GetArtifactsException { try (InputStream inputStream = new BufferedInputStream(new FileInputStream(outputFile))) { return ParsedBepOutput.parseBepArtifacts(inputStream); diff --git a/base/tests/utils/unit/com/google/idea/blaze/base/bazel/FakeBlazeCommandRunner.java b/base/tests/utils/unit/com/google/idea/blaze/base/bazel/FakeBlazeCommandRunner.java index 41157d0fb2f..8693265016b 100644 --- a/base/tests/utils/unit/com/google/idea/blaze/base/bazel/FakeBlazeCommandRunner.java +++ b/base/tests/utils/unit/com/google/idea/blaze/base/bazel/FakeBlazeCommandRunner.java @@ -28,11 +28,13 @@ import com.google.idea.blaze.base.scope.BlazeContext; import com.google.idea.blaze.base.sync.aspects.BlazeBuildOutputs; import com.google.idea.blaze.base.sync.aspects.BuildResult; +import com.google.idea.blaze.common.Interners; import com.google.idea.blaze.exception.BuildException; import com.intellij.openapi.project.Project; import java.io.InputStream; import java.util.Map; +import java.util.Optional; /** * A fake for {@link BlazeCommandRunner} that doesn't execute the build, but returns results from @@ -52,7 +54,7 @@ public FakeBlazeCommandRunner() { this( buildResultHelper -> BlazeBuildOutputs.fromParsedBepOutput( - BuildResult.SUCCESS, buildResultHelper.getBuildOutput())); + BuildResult.SUCCESS, buildResultHelper.getBuildOutput(Optional.empty(), Interners.STRING))); } public FakeBlazeCommandRunner(BuildFunction buildFunction) { diff --git a/base/tests/utils/unit/com/google/idea/blaze/base/bazel/FakeBuildResultHelperBep.java b/base/tests/utils/unit/com/google/idea/blaze/base/bazel/FakeBuildResultHelperBep.java index bbc4dae0d70..8aa9bfb1408 100644 --- a/base/tests/utils/unit/com/google/idea/blaze/base/bazel/FakeBuildResultHelperBep.java +++ b/base/tests/utils/unit/com/google/idea/blaze/base/bazel/FakeBuildResultHelperBep.java @@ -16,6 +16,7 @@ package com.google.idea.blaze.base.bazel; import com.google.common.collect.ImmutableList; +import com.google.common.collect.Interner; import com.google.idea.blaze.base.command.buildresult.BuildFlags; import com.google.idea.blaze.base.command.buildresult.BuildResultHelper; import com.google.idea.blaze.base.command.buildresult.ParsedBepOutput; @@ -49,7 +50,7 @@ public List getBuildFlags() { } @Override - public ParsedBepOutput getBuildOutput(Optional completedBuildId) + public ParsedBepOutput getBuildOutput(Optional completedBuildId, Interner stringInterner) throws GetArtifactsException { if (parsedBepOutput == null) { throw new GetArtifactsException("Could not get artifacts from null bep"); diff --git a/python/BUILD b/python/BUILD index 4a4772774d7..c7e88fb487b 100644 --- a/python/BUILD +++ b/python/BUILD @@ -32,6 +32,7 @@ java_library( "//intellij_platform_sdk:plugin_api", "//intellij_platform_sdk:jsr305", "//shared", + "//shared/java/com/google/idea/blaze/common", "//third_party/python", ], ) diff --git a/shared/java/com/google/idea/blaze/common/BUILD b/shared/java/com/google/idea/blaze/common/BUILD index a3dd606a943..f54c1813ca6 100644 --- a/shared/java/com/google/idea/blaze/common/BUILD +++ b/shared/java/com/google/idea/blaze/common/BUILD @@ -6,8 +6,7 @@ java_library( name = "common", srcs = glob(["*.java"]), visibility = [ - "//querysync/javatests/com/google/idea/blaze/qsync:__subpackages__", - "//shared:__subpackages__", + "//visibility:public", ], deps = [ "@jsr305_annotations//jar",