Skip to content

Commit 23e08ae

Browse files
committed
[bazelbuild#6664]: Invoke blaze mod correctly
1 parent 78fa3ee commit 23e08ae

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

base/src/com/google/idea/blaze/base/command/mod/BlazeModRunnerImpl.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,32 @@
3838

3939
public class BlazeModRunnerImpl extends BlazeModRunner {
4040

41+
private static final String DUMP_REPO_MAPPING = "dump_repo_mapping";
42+
private static final String ROOT_WORKSPACE = "";
43+
44+
/**
45+
* {@code bazel mod dump_repo_mapping} takes a canonical repository name and will dump a map
46+
* from repoName -> canonicalName of all the external repositories available to that repository
47+
* The name {@code ""} is special and considered to be <em>the main workspace</em> so in order to dump the main
48+
* repository map we would invoke it like {@code bazel mod dump_repo_mapping ""}.
49+
* <p />
50+
* Additionally the flag {@code --enable_workspace} needs to be off for this to work. The flag is default
51+
* off in bazel 8.0.0 but it is on between 7.1.0 and 8.0.0. So we need to also pass this along in
52+
* between those versions for the command to work well.
53+
*/
4154
@Override
4255
public ListenableFuture<ExternalWorkspaceData> dumpRepoMapping(
4356
Project project,
4457
BuildSystem.BuildInvoker invoker,
4558
BlazeContext context,
4659
BuildSystemName buildSystemName,
4760
List<String> flags) {
61+
62+
// TODO: when 8.0.0 is released add this only if it's disabled explicitly for the repo
63+
flags.add("--noenable_workspace");
64+
4865
return Futures.transform(
49-
runBlazeModGetBytes(project, invoker, context, ImmutableList.of( "dump_repo_mapping", "workspace"), flags),
66+
runBlazeModGetBytes(project, invoker, context, ImmutableList.of(DUMP_REPO_MAPPING, ROOT_WORKSPACE), flags),
5067
bytes -> {
5168
JsonObject json = JsonParser.parseString(new String(bytes, StandardCharsets.UTF_8).trim()).getAsJsonObject();
5269

base/src/com/google/idea/blaze/base/model/ExternalWorkspaceDataProvider.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ public static ExternalWorkspaceDataProvider getInstance(Project project) {
5757
}
5858

5959
static Boolean isEnabled(BlazeVersionData blazeVersionData) {
60-
// disable this until a more reliable opt-in mechanism is chosen.
61-
//
62-
// bg: some blaze workspaces with blaze > MINIMUM_BLAZE_VERSION
63-
// have explicitly disabled this bzlmod support and this causes
64-
// `blaze mod` to fail.
65-
return blazeVersionData.bazelIsAtLeastVersion(MINIMUM_BLAZE_VERSION) && Registry.is("bazel.read.external.workspace.data");
60+
if (!Registry.is("bazel.read.external.workspace.data")) {
61+
logger.info("disabled by registry");
62+
return false;
63+
}
64+
65+
return blazeVersionData.bazelIsAtLeastVersion(MINIMUM_BLAZE_VERSION);
6666
}
6767

6868
public ListenableFuture<ExternalWorkspaceData> getExternalWorkspaceData(

base/src/com/google/idea/blaze/base/sync/ProjectStateSyncTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ private ExternalWorkspaceData getExternalWorkspaceData(
233233
SyncMode syncMode)
234234
throws SyncCanceledException, SyncFailedException {
235235

236-
List<String> syncFlags =
236+
List<String> blazeModFlags =
237237
BlazeFlags.blazeFlags(
238238
project,
239239
projectViewSet,
@@ -243,7 +243,7 @@ private ExternalWorkspaceData getExternalWorkspaceData(
243243

244244
ListenableFuture<ExternalWorkspaceData> externalWorkspaceDataFuture =
245245
ExternalWorkspaceDataProvider.getInstance(project)
246-
.getExternalWorkspaceData(context, syncFlags, blazeVersionData, blazeInfo);
246+
.getExternalWorkspaceData(context, blazeModFlags, blazeVersionData, blazeInfo);
247247

248248
FutureResult<ExternalWorkspaceData> externalWorkspaceDataResult =
249249
FutureUtil.waitForFuture(context, externalWorkspaceDataFuture)

0 commit comments

Comments
 (0)