[8.5.0] Inject repositories after root module file processed#27904
[8.5.0] Inject repositories after root module file processed#27904iancha1992 merged 4 commits intobazelbuild:release-8.5.0from
Conversation
This fixes an issue where repositories injected with `--inject_repository` can invalidate `MODULE.bazel.lock` by changing the order innate `use_repo_rule` extensions are registered.
For example;
```starlark
# //:MODULE.bazel
local_repository = use_repo_rule("@//:defs.bzl", "local_repository")
local_repository(name = "repo")
```
```shell
bazel mod dump_repo_mapping '' --inject_repository=my_repo=%workspace%/other_repo
# Bazel 9+
# {"my_repo":"+local_repository+my_repo","repo":"+local_repository2+repo",...}
# Bazel 8
# {"my_repo":"+_repo_rules+my_repo","repo":"+_repo_rules2+repo",...}
```
Handling repository injections later changes how collisions with apparent repository names from innate extensions (`use_repo_rule(...)(...)`) and module extensions (`use_extension(...).__(...)`) are reported. To permit debugging (and improve collision investigation in general) the error message now refers to the incoming and existing repo name definition.
For example;
```diff
-Error in use_repo: The repo name 'my_repo' is already being used by --inject_repository at <builtin>
+ERROR: The repo name 'my_repo' cannot be defined by --inject_repository at <builtin> as it is already defined by a use_repo() call at /___/MODULE.bazel:2:9
```
Closes bazelbuild#27795.
PiperOrigin-RevId: 841889374
Change-Id: I01a4500ae5580338f96d593323c1d680fdbb7672
Summary of ChangesHello @bazel-io, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical issue where the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses an issue where injected repositories could invalidate MODULE.bazel.lock by altering the registration order of use_repo_rule extensions. The fix correctly defers the injection of repositories until after the root module file has been processed, ensuring a stable registration order. Additionally, the error message for repository name collisions has been significantly improved to provide more context, which will aid in debugging. The changes are well-tested, including a new test case that validates the fix for the lock file invalidation side effect. The implementation is clean and effective. I have one minor suggestion to remove a stray comment in a test file.
| ) | ||
|
|
||
| # --inject_repository _must not_ affect `use_repo_rule` generated repo names | ||
| #. |
Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
|
Thanks for the fixes @fmeum! |
This fixes an issue where repositories injected with
--inject_repositorycan invalidateMODULE.bazel.lockby changing the order innateuse_repo_ruleextensions are registered.For example;
Handling repository injections later changes how collisions with apparent repository names from innate extensions (
use_repo_rule(...)(...)) and module extensions (use_extension(...).__(...)) are reported. To permit debugging (and improve collision investigation in general) the error message now refers to the incoming and existing repo name definition.For example;
Closes #27795.
PiperOrigin-RevId: 841889374
Change-Id: I01a4500ae5580338f96d593323c1d680fdbb7672
Commit d564fc9