Skip to content

Commit

Permalink
[#6664]: Invoke blaze mod correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
mtoader committed Sep 5, 2024
1 parent 5f64df8 commit 2c28e4c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@

public class BlazeModRunnerImpl extends BlazeModRunner {

private static final String DUMP_REPO_MAPPING = "dump_repo_mapping";
private static final String ROOT_WORKSPACE = "";

@Override
public ListenableFuture<ExternalWorkspaceData> dumpRepoMapping(
Project project,
Expand All @@ -46,7 +49,7 @@ public ListenableFuture<ExternalWorkspaceData> dumpRepoMapping(
BuildSystemName buildSystemName,
List<String> flags) {
return Futures.transform(
runBlazeModGetBytes(project, invoker, context, ImmutableList.of( "dump_repo_mapping", "workspace"), flags),
runBlazeModGetBytes(project, invoker, context, ImmutableList.of(DUMP_REPO_MAPPING, ROOT_WORKSPACE), flags),
bytes -> {
JsonObject json = JsonParser.parseString(new String(bytes, StandardCharsets.UTF_8).trim()).getAsJsonObject();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public static ExternalWorkspaceDataProvider getInstance(Project project) {
}

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

return blazeVersionData.bazelIsAtLeastVersion(MINIMUM_BLAZE_VERSION);
}

public ListenableFuture<ExternalWorkspaceData> getExternalWorkspaceData(
Expand All @@ -83,6 +83,9 @@ public ListenableFuture<ExternalWorkspaceData> getExternalWorkspaceData(
return Futures.immediateFuture(ExternalWorkspaceData.EMPTY);
}

// TODO: when 8.0.0 is released add this conditionally only when it's disabled inside `starLarkSemantics`
blazeFlags.add("--noenable_workspace");

return BlazeExecutor.getInstance().submit(() -> {
ExternalWorkspaceData mapping = getCachedExternalWorkspaceData(context, blazeFlags);
if (mapping == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private ExternalWorkspaceData getExternalWorkspaceData(
SyncMode syncMode)
throws SyncCanceledException, SyncFailedException {

List<String> syncFlags =
List<String> blazeModFlags =
BlazeFlags.blazeFlags(
project,
projectViewSet,
Expand All @@ -243,7 +243,7 @@ private ExternalWorkspaceData getExternalWorkspaceData(

ListenableFuture<ExternalWorkspaceData> externalWorkspaceDataFuture =
ExternalWorkspaceDataProvider.getInstance(project)
.getExternalWorkspaceData(context, syncFlags, blazeVersionData, blazeInfo);
.getExternalWorkspaceData(context, blazeModFlags, blazeVersionData, blazeInfo);

FutureResult<ExternalWorkspaceData> externalWorkspaceDataResult =
FutureUtil.waitForFuture(context, externalWorkspaceDataFuture)
Expand Down

0 comments on commit 2c28e4c

Please sign in to comment.