Skip to content

Reparse options with repo mapping for bazel info#29018

Draft
fmeum wants to merge 2 commits intobazelbuild:masterfrom
fmeum:worktree-fix-28954
Draft

Reparse options with repo mapping for bazel info#29018
fmeum wants to merge 2 commits intobazelbuild:masterfrom
fmeum:worktree-fix-28954

Conversation

@fmeum
Copy link
Copy Markdown
Collaborator

@fmeum fmeum commented Mar 17, 2026

Description

bazel info --host_platform=@mod1//:host_platform failed with "Repository '@@mod1' is not defined" when mod1 was a local_path_override dependency.

Root cause: info has buildPhase = NONE, so BlazeCommandDispatcher skipped the repo mapping computation and option reparsing. Label-typed options were parsed via Label.parseCanonical() without the repo mapping, producing incorrect canonical names (e.g., @@mod1 instead of the actual Bzlmod canonical name).

Fix: include info in the dispatcher's sync + repo mapping + reparsing path, the same path used by build/test/etc.

Motivation

Fixes #28954

Build API Changes

No

Checklist

  • I have added tests for the new use cases (if any).
  • I have updated the documentation (if applicable).

Release Notes

RELNOTES: bazel info now correctly resolves label-typed options (e.g. --host_platform) that reference external repositories.

@github-actions github-actions Bot added the awaiting-review PR is awaiting review from an assigned reviewer label Mar 17, 2026
@google-cla
Copy link
Copy Markdown

google-cla Bot commented Mar 17, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@fmeum fmeum force-pushed the worktree-fix-28954 branch from 61f4bcb to 589b7c7 Compare March 17, 2026 10:14
@fmeum fmeum changed the title Fix bazel info failing to resolve label-typed options referencing external repos Reparse options with repo mapping for bazel info Mar 17, 2026
…ernal repos

bazel info --host_platform=@mod1//:host_platform failed with
"Repository '@@mod1' is not defined" when mod1 was a local_path_override
dependency. This happened because info has buildPhase = NONE, so
BlazeCommandDispatcher skipped the repo mapping computation and option
reparsing. Label-typed options were parsed via Label.parseCanonical()
without the repo mapping, producing incorrect canonical names.

Fix by lazily reparsing options with the main repo mapping inside
InfoCommand's configuration supplier, preserving the lazy loading
behavior for simple info queries that don't need configuration.

Fixes bazelbuild#28954
@fmeum fmeum force-pushed the worktree-fix-28954 branch from 589b7c7 to 043dab5 Compare March 17, 2026 10:46
@iancha1992 iancha1992 added the team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. label Mar 17, 2026
@iancha1992
Copy link
Copy Markdown
Member

@fmeum Could you please take a look at the failing checks? Thanks!

return optionsParsingResult;
}

OptionsParser oldParser = (OptionsParser) optionsParsingResult;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we do an instanceof check first? This cast doesn't look completely safe.

@iancha1992
Copy link
Copy Markdown
Member

@fmeum Can you please fix the failures and push the changes? We need to ship 9.0.2 soon and hope this fix is included in it.

Use getCanonicalForm() instead of getCommandLineForm() when replaying
options in reparseWithRepoMapping. getCommandLineForm() preserves the
original space-separated format (e.g. "--logging 6"), which fails when
passed as a single element to OptionsParser.parse(). getCanonicalForm()
always uses "=" syntax (e.g. "--logging=6"), which works as a single arg.

Also add an instanceof check before the OptionsParser cast as suggested
in review.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@fmeum
Copy link
Copy Markdown
Collaborator Author

fmeum commented Mar 27, 2026

I went over this again and think that it's too brittle. There is too much subtle logic in BlazeCommandDispatcher that this doesn't reproduce faithfully (e.g. --flag_alias handling and Starlark options). I would like to try to properly extract that logic, but this will likely take me longer than the 9.0.2 timeframe allows.

@fmeum fmeum marked this pull request as draft March 27, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR is awaiting review from an assigned reviewer team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bazel info --host_platform=@my-mod//:host_platform fails on bazel 9.x with local path override

3 participants