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 05bd9f7f942..27b3be9c5e7 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 @@ -36,6 +36,8 @@ public abstract class BlazeInfo implements ProtoWrapper { public static final String MASTER_LOG = "master-log"; public static final String RELEASE = "release"; + public static final String STARLARK_SEMANTICS = "starlark-semantics"; + public static String blazeBinKey(BuildSystemName buildSystemName) { switch (buildSystemName) { case Blaze: 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 4c792c6ce81..682e2fd45c5 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,6 +18,7 @@ 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; @@ -26,6 +27,7 @@ import com.google.idea.blaze.base.scope.BlazeContext; import com.google.idea.blaze.base.settings.BuildSystemName; import com.intellij.openapi.project.Project; + import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.List; @@ -76,16 +78,27 @@ public ListenableFuture runBlazeInfo( BlazeContext context, BuildSystemName buildSystemName, List blazeFlags) { - return Futures.transform( + ListeningExecutorService executor = BlazeExecutor.getInstance().getExecutor(); + + return Futures.transformAsync( runBlazeInfoGetBytes(project, invoker, context, blazeFlags, /* key= */ null), - bytes -> - BlazeInfo.create( - buildSystemName, - parseBlazeInfoResult(new String(bytes, StandardCharsets.UTF_8).trim())), - BlazeExecutor.getInstance().getExecutor()); + 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); } - private static ImmutableMap parseBlazeInfoResult(String blazeInfoString) { - ImmutableMap.Builder blazeInfoMapBuilder = ImmutableMap.builder(); + + private static ImmutableMap.Builder parseBlazeInfoResult(String blazeInfoString) { + ImmutableMap.Builder builder = ImmutableMap.builder(); String[] blazeInfoLines = blazeInfoString.split("\n"); for (String blazeInfoLine : blazeInfoLines) { // Just split on the first ":". @@ -96,8 +109,9 @@ private static ImmutableMap parseBlazeInfoResult(String blazeInf } String key = keyValue[0].trim(); String value = keyValue[1].trim(); - blazeInfoMapBuilder.put(key, value); + builder.put(key, value); } - return blazeInfoMapBuilder.build(); + + return builder; } } 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 039953c105d..98f4f03c3fe 100644 --- a/base/src/com/google/idea/blaze/base/model/ExternalWorkspaceDataProvider.java +++ b/base/src/com/google/idea/blaze/base/model/ExternalWorkspaceDataProvider.java @@ -20,6 +20,7 @@ import com.google.idea.blaze.base.async.executor.BlazeExecutor; import com.google.idea.blaze.base.bazel.BazelVersion; import com.google.idea.blaze.base.bazel.BuildSystem; +import com.google.idea.blaze.base.command.info.BlazeInfo; import com.google.idea.blaze.base.command.mod.BlazeModException; import com.google.idea.blaze.base.command.mod.BlazeModRunner; import com.google.idea.blaze.base.scope.BlazeContext; @@ -67,11 +68,21 @@ static Boolean isEnabled(BlazeVersionData blazeVersionData) { public ListenableFuture getExternalWorkspaceData( BlazeContext context, List blazeFlags, - BlazeVersionData blazeVersionData) { + BlazeVersionData blazeVersionData, + BlazeInfo blazeInfo + ) { + // check minimum bazel version if (!isEnabled(blazeVersionData)) { return Futures.immediateFuture(ExternalWorkspaceData.EMPTY); } + // 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); + if (starLarkSemantics == null || starLarkSemantics.isEmpty() || starLarkSemantics.contains("enable_bzlmod=false")) { + return Futures.immediateFuture(ExternalWorkspaceData.EMPTY); + } + return BlazeExecutor.getInstance().submit(() -> { ExternalWorkspaceData mapping = getCachedExternalWorkspaceData(context, blazeFlags); if (mapping == null) { @@ -114,6 +125,7 @@ public ListenableFuture getExternalWorkspaceData( } public void invalidate(BlazeContext context, SyncMode syncMode) { + logger.info("Invalidating External Repository Mapping info"); context.output(new StatusOutput(String.format("Invalidating External Repository Mapping info (%s)", syncMode))); externalWorkspaceData = null; } @@ -124,7 +136,7 @@ public void onSyncStart( Project project, BlazeContext context, SyncMode syncMode) { - if (syncMode == SyncMode.NO_BUILD || syncMode == SyncMode.FULL) { + if (syncMode == SyncMode.FULL) { ExternalWorkspaceDataProvider provider = ExternalWorkspaceDataProvider.getInstance(project); if (provider != null) { provider.invalidate(context, syncMode); diff --git a/base/src/com/google/idea/blaze/base/sync/ProjectStateSyncTask.java b/base/src/com/google/idea/blaze/base/sync/ProjectStateSyncTask.java index cc49b7f8f2a..8bbdcb1a480 100644 --- a/base/src/com/google/idea/blaze/base/sync/ProjectStateSyncTask.java +++ b/base/src/com/google/idea/blaze/base/sync/ProjectStateSyncTask.java @@ -161,7 +161,7 @@ private SyncProjectState getProjectState(BlazeContext context, BlazeSyncParams p } ExternalWorkspaceData externalWorkspaceData = - getExternalWorkspaceData(context, projectViewSet, blazeVersionData, params.syncMode()); + getExternalWorkspaceData(context, projectViewSet, blazeVersionData, blazeInfo, params.syncMode()); WorkspacePathResolver workspacePathResolver = workspacePathResolverAndProjectView.workspacePathResolver; @@ -229,6 +229,7 @@ private ExternalWorkspaceData getExternalWorkspaceData( BlazeContext context, ProjectViewSet projectViewSet, BlazeVersionData blazeVersionData, + BlazeInfo blazeInfo, SyncMode syncMode) throws SyncCanceledException, SyncFailedException { @@ -242,7 +243,7 @@ private ExternalWorkspaceData getExternalWorkspaceData( ListenableFuture externalWorkspaceDataFuture = ExternalWorkspaceDataProvider.getInstance(project) - .getExternalWorkspaceData(context, syncFlags, blazeVersionData); + .getExternalWorkspaceData(context, syncFlags, blazeVersionData, blazeInfo); FutureResult externalWorkspaceDataResult = FutureUtil.waitForFuture(context, externalWorkspaceDataFuture)