diff --git a/base/src/com/google/idea/blaze/base/bazel/BazelVersion.java b/base/src/com/google/idea/blaze/base/bazel/BazelVersion.java index e9f6b62cfb6..71a3d91f160 100644 --- a/base/src/com/google/idea/blaze/base/bazel/BazelVersion.java +++ b/base/src/com/google/idea/blaze/base/bazel/BazelVersion.java @@ -102,7 +102,7 @@ private static BazelVersion parseVersion(String[] numbers) { } static BazelVersion parseVersion(BlazeInfo blazeInfo) { - return parseVersion(blazeInfo.get(BlazeInfo.RELEASE)); + return parseVersion(blazeInfo.getRelease()); } @Override diff --git a/base/src/com/google/idea/blaze/base/command/info/BlazeInfo.java b/base/src/com/google/idea/blaze/base/command/info/BlazeInfo.java index 27b3be9c5e7..1f49a07fa26 100644 --- a/base/src/com/google/idea/blaze/base/command/info/BlazeInfo.java +++ b/base/src/com/google/idea/blaze/base/command/info/BlazeInfo.java @@ -18,6 +18,7 @@ import com.google.auto.value.AutoValue; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.devtools.intellij.model.ProjectData; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.idea.blaze.base.ideinfo.ProtoWrapper; @@ -33,7 +34,6 @@ public abstract class BlazeInfo implements ProtoWrapper { public static final String BUILD_LANGUAGE = "build-language"; public static final String OUTPUT_BASE_KEY = "output_base"; public static final String OUTPUT_PATH_KEY = "output_path"; - public static final String MASTER_LOG = "master-log"; public static final String RELEASE = "release"; public static final String STARLARK_SEMANTICS = "starlark-semantics"; @@ -114,7 +114,7 @@ private static String getOrThrow(ImmutableMap map, String key) { abstract ImmutableMap getBlazeInfoMap(); - public String get(String key) { + protected String get(String key) { return getBlazeInfoMap().get(key); } @@ -140,6 +140,14 @@ public File getBlazeTestlogsDirectory() { public abstract File getOutputBase(); + public String getStarlarkSemantics() { + return getBlazeInfoMap().get(STARLARK_SEMANTICS); + } + + public String getRelease() { + return getBlazeInfoMap().get(RELEASE); + } + /** Creates a mock blaze info with the minimum information required for syncing. */ @VisibleForTesting public static BlazeInfo createMockBlazeInfo( diff --git a/base/src/com/google/idea/blaze/base/command/info/BlazeInfoRunner.java b/base/src/com/google/idea/blaze/base/command/info/BlazeInfoRunner.java index 9fcf9dcf432..1f0b6336af9 100644 --- a/base/src/com/google/idea/blaze/base/command/info/BlazeInfoRunner.java +++ b/base/src/com/google/idea/blaze/base/command/info/BlazeInfoRunner.java @@ -19,6 +19,7 @@ import com.google.idea.blaze.base.bazel.BuildSystem.BuildInvoker; import com.google.idea.blaze.base.scope.BlazeContext; import com.google.idea.blaze.base.settings.BuildSystemName; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.project.Project; import java.util.List; @@ -27,12 +28,12 @@ public abstract class BlazeInfoRunner { public static BlazeInfoRunner getInstance() { - return ServiceManager.getService(BlazeInfoRunner.class); + return ApplicationManager.getApplication().getService(BlazeInfoRunner.class); } /** * @param blazeFlags The blaze flags that will be passed to Blaze. - * @param key The key passed to blaze info + * @param keys The key passed to blaze info * @return The blaze info value associated with the specified key */ public abstract ListenableFuture runBlazeInfo( @@ -40,11 +41,11 @@ public abstract ListenableFuture runBlazeInfo( BuildInvoker invoker, BlazeContext context, List blazeFlags, - String key); + String ...keys); /** * @param blazeFlags The blaze flags that will be passed to Blaze. - * @param key The key passed to blaze info + * @param keys The keys passed to blaze info * @return The blaze info value associated with the specified key */ public abstract ListenableFuture runBlazeInfoGetBytes( @@ -52,7 +53,7 @@ public abstract ListenableFuture runBlazeInfoGetBytes( BuildInvoker invoker, BlazeContext context, List blazeFlags, - String key); + String ...keys); /** * This calls blaze info without any specific key so blaze info will return all keys and values diff --git a/base/src/com/google/idea/blaze/base/command/info/BlazeInfoRunnerImpl.java b/base/src/com/google/idea/blaze/base/command/info/BlazeInfoRunnerImpl.java index 682e2fd45c5..1b1d7b4b7ed 100644 --- a/base/src/com/google/idea/blaze/base/command/info/BlazeInfoRunnerImpl.java +++ b/base/src/com/google/idea/blaze/base/command/info/BlazeInfoRunnerImpl.java @@ -18,7 +18,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; import com.google.idea.blaze.base.async.executor.BlazeExecutor; import com.google.idea.blaze.base.bazel.BuildSystem.BuildInvoker; import com.google.idea.blaze.base.command.BlazeCommand; @@ -39,23 +38,23 @@ public ListenableFuture runBlazeInfoGetBytes( BuildInvoker invoker, BlazeContext context, List blazeFlags, - String key) { + String... keys) { return BlazeExecutor.getInstance() - .submit( - () -> { - BlazeCommand.Builder builder = BlazeCommand.builder(invoker, BlazeCommandName.INFO); - builder.addBlazeFlags(blazeFlags); - if (key != null) { - builder.addBlazeFlags(key); - } - try (BuildResultHelper buildResultHelper = invoker.createBuildResultHelper(); - InputStream blazeInfoStream = - invoker - .getCommandRunner() - .runBlazeInfo(project, builder, buildResultHelper, context)) { - return blazeInfoStream.readAllBytes(); - } - }); + .submit( + () -> { + BlazeCommand.Builder builder = BlazeCommand.builder(invoker, BlazeCommandName.INFO); + builder.addBlazeFlags(blazeFlags); + if (keys != null) { + builder.addBlazeFlags(keys); + } + try (BuildResultHelper buildResultHelper = invoker.createBuildResultHelper(); + InputStream blazeInfoStream = + invoker + .getCommandRunner() + .runBlazeInfo(project, builder, buildResultHelper, context)) { + return blazeInfoStream.readAllBytes(); + } + }); } @Override @@ -64,9 +63,9 @@ public ListenableFuture runBlazeInfo( BuildInvoker invoker, BlazeContext context, List blazeFlags, - String key) { + String... keys) { return Futures.transform( - runBlazeInfoGetBytes(project, invoker, context, blazeFlags, key), + runBlazeInfoGetBytes(project, invoker, context, blazeFlags, keys), bytes -> new String(bytes, StandardCharsets.UTF_8).trim(), BlazeExecutor.getInstance().getExecutor()); } @@ -78,23 +77,20 @@ public ListenableFuture runBlazeInfo( BlazeContext context, BuildSystemName buildSystemName, List blazeFlags) { - ListeningExecutorService executor = BlazeExecutor.getInstance().getExecutor(); - return Futures.transformAsync( - runBlazeInfoGetBytes(project, invoker, context, blazeFlags, /* key= */ null), - bytes -> { - ImmutableMap.Builder builder = parseBlazeInfoResult(new String(bytes, StandardCharsets.UTF_8).trim()); - - return Futures.transform( - runBlazeInfo(project, invoker, context, blazeFlags, BlazeInfo.STARLARK_SEMANTICS), - - starLarkSemantics -> { - builder.put(BlazeInfo.STARLARK_SEMANTICS, starLarkSemantics); - - return BlazeInfo.create(buildSystemName, builder.build()); - }, executor); - }, - executor); + return Futures.transform( + runBlazeInfoGetBytes(project, invoker, context, blazeFlags, + BlazeInfo.blazeBinKey(buildSystemName), + BlazeInfo.blazeGenfilesKey(buildSystemName), + BlazeInfo.blazeTestlogsKey(buildSystemName), + BlazeInfo.EXECUTION_ROOT_KEY, + BlazeInfo.PACKAGE_PATH_KEY, + BlazeInfo.OUTPUT_PATH_KEY, + BlazeInfo.OUTPUT_BASE_KEY, + BlazeInfo.RELEASE, + BlazeInfo.STARLARK_SEMANTICS), + bytes -> BlazeInfo.create(buildSystemName, parseBlazeInfoResult(new String(bytes, StandardCharsets.UTF_8).trim()).build()), + BlazeExecutor.getInstance().getExecutor()); } private static ImmutableMap.Builder parseBlazeInfoResult(String blazeInfoString) { diff --git a/base/src/com/google/idea/blaze/base/model/ExternalWorkspaceDataProvider.java b/base/src/com/google/idea/blaze/base/model/ExternalWorkspaceDataProvider.java index 98f4f03c3fe..21ebefc744b 100644 --- a/base/src/com/google/idea/blaze/base/model/ExternalWorkspaceDataProvider.java +++ b/base/src/com/google/idea/blaze/base/model/ExternalWorkspaceDataProvider.java @@ -78,7 +78,7 @@ public ListenableFuture getExternalWorkspaceData( // validate that bzlmod is enabled (technically this validates that the --enable_bzlmod is not // changed from the default `true` aka set to false) - String starLarkSemantics = blazeInfo.get(BlazeInfo.STARLARK_SEMANTICS); + String starLarkSemantics = blazeInfo.getStarlarkSemantics(); if (starLarkSemantics == null || starLarkSemantics.isEmpty() || starLarkSemantics.contains("enable_bzlmod=false")) { return Futures.immediateFuture(ExternalWorkspaceData.EMPTY); } diff --git a/base/src/com/google/idea/blaze/base/run/coverage/CoverageUtils.java b/base/src/com/google/idea/blaze/base/run/coverage/CoverageUtils.java index f8a2d8b97f2..495a58a143f 100644 --- a/base/src/com/google/idea/blaze/base/run/coverage/CoverageUtils.java +++ b/base/src/com/google/idea/blaze/base/run/coverage/CoverageUtils.java @@ -66,7 +66,7 @@ public static ImmutableList getBlazeFlags() { } public static File getOutputFile(BlazeInfo blazeInfo) { - File coverageRoot = new File(blazeInfo.get(BlazeInfo.OUTPUT_PATH_KEY), "_coverage"); + File coverageRoot = new File(blazeInfo.getOutputBase(), "_coverage"); return new File(coverageRoot, "_coverage_report.dat"); } } diff --git a/base/tests/utils/integration/com/google/idea/blaze/base/sync/BlazeSyncIntegrationTestCase.java b/base/tests/utils/integration/com/google/idea/blaze/base/sync/BlazeSyncIntegrationTestCase.java index 4a791df1978..acb377e0a4c 100644 --- a/base/tests/utils/integration/com/google/idea/blaze/base/sync/BlazeSyncIntegrationTestCase.java +++ b/base/tests/utils/integration/com/google/idea/blaze/base/sync/BlazeSyncIntegrationTestCase.java @@ -287,7 +287,7 @@ public ListenableFuture runBlazeInfo( BuildInvoker invoker, BlazeContext context, List blazeFlags, - String key) { + String ...key) { return Futures.immediateFuture(results.get(key)); } @@ -308,7 +308,7 @@ public ListenableFuture runBlazeInfoGetBytes( BuildInvoker invoker, BlazeContext context, List blazeFlags, - String key) { + String ...key) { return Futures.immediateFuture(null); }