Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#6664]: Invoke blaze mod correctly #6729

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,32 @@

public class BlazeModRunnerImpl extends BlazeModRunner {

private static final String DUMP_REPO_MAPPING = "dump_repo_mapping";
private static final String ROOT_WORKSPACE = "";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously it was "workspace", not an empty string

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the context there: #6664 (comment)

Could you summarize that in a code comment?


/**
* {@code bazel mod dump_repo_mapping} takes a canonical repository name and will dump a map
* from repoName -> canonicalName of all the external repositories available to that repository
* The name {@code ""} is special and considered to be <em>the main workspace</em> so in order to dump the main
* repository map we would invoke it like {@code bazel mod dump_repo_mapping ""}.
* <p />
* Additionally the flag {@code --enable_workspace} needs to be off for this to work. The flag is default
* 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this flag supported by Bazel <7.1.0? If not, doesn't it break Bazel 6 and 5?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not get called at all before 7.1.0 since the dump command itself didn't exist before.

* between those versions for the command to work well.
*/
@Override
public ListenableFuture<ExternalWorkspaceData> dumpRepoMapping(
Project project,
BuildSystem.BuildInvoker invoker,
BlazeContext context,
BuildSystemName buildSystemName,
List<String> flags) {

// TODO: when 8.0.0 is released add this only if it's disabled explicitly for the repo
flags.add("--noenable_workspace");

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 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