Support repository name mappings in extension_metadata#27891
Support repository name mappings in extension_metadata#27891malt3 wants to merge 1 commit intobazelbuild:masterfrom
Conversation
Summary of ChangesHello @malt3, 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 significantly enhances Bazel's Bzlmod system by introducing support for flexible repository name mappings within module extension metadata. It allows module extensions to define how their exported repositories are named when imported by the root module, enabling custom local names for dependencies. This change improves 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 adds support for repository name mappings in extension_metadata, allowing root_module_direct_deps and root_module_direct_dev_deps to accept dictionaries. The changes look good and cover the new functionality well, including updates to documentation and comprehensive tests. I have two main points of feedback: one critical issue regarding a potential crash due to duplicate imports, and one medium-severity suggestion to optimize a loop for better performance.
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/LockfileModuleExtensionMetadata.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionMetadata.java
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/LockfileModuleExtensionMetadata.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/LockfileModuleExtensionMetadata.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/LockfileModuleExtensionMetadata.java
Outdated
Show resolved
Hide resolved
1e0cdd0 to
2c36ffe
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds support for repository name mappings in extension_metadata, allowing root_module_direct_deps and root_module_direct_dev_deps to accept dictionaries. This is a great feature that enhances flexibility. The implementation is solid, with good validation and test coverage. I've found one area in LockfileModuleExtensionMetadata.java where code can be refactored to improve efficiency and reduce duplication by processing proxies in a single pass.
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/LockfileModuleExtensionMetadata.java
Show resolved
Hide resolved
2c36ffe to
dde8300
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for repository name mappings in extension_metadata by allowing root_module_direct_deps and root_module_direct_dev_deps to accept dictionaries. This is a valuable enhancement for module authors, providing more flexibility in naming repositories.
The implementation is well-structured, with clear separation of concerns. The changes to the Starlark API and documentation are thorough. The validation logic for the new dictionary format is robust, covering various edge cases such as duplicate names and invalid entries. The accompanying tests are also comprehensive.
I've found one critical bug in the generateFixup logic that would cause bazel mod tidy to behave incorrectly for dev dependencies. The fix is straightforward. After addressing this, the PR should be in great shape.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds support for repository name mappings in extension_metadata, allowing modules to import repositories under different names. The implementation is thorough, covering changes to metadata handling, fixup generation, and Starlark API documentation. The new logic correctly handles both list-style and dictionary-style dependencies, including validation and error reporting for various edge cases. The accompanying tests are comprehensive and cover the new functionality well. I have a few minor suggestions for optimization, but overall, this is a solid contribution.
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/LockfileModuleExtensionMetadata.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/LockfileModuleExtensionMetadata.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/ModuleExtensionMetadata.java
Outdated
Show resolved
Hide resolved
dde8300 to
1426a7d
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds support for repository name mappings in extension_metadata by allowing root_module_direct_deps and root_module_direct_dev_deps to be specified as dictionaries. This is a valuable feature that increases the flexibility of module extensions.
The implementation is well-executed across the affected files. The logic for parsing, validation, and generating bazel mod tidy fixups has been updated thoughtfully to handle the new mapping capabilities. The Starlark API changes are clear, and the new tests provide good coverage for the new functionality and edge cases.
Overall, this is a high-quality change. I have one minor suggestion to remove a bit of dead code to improve maintainability.
src/main/java/com/google/devtools/build/lib/bazel/bzlmod/LockfileModuleExtensionMetadata.java
Outdated
Show resolved
Hide resolved
Allow root_module_direct_deps and root_module_direct_dev_deps to accept
dicts mapping module-local names to extension-exported names, in addition
to the existing list format. This enables modules to import repositories
under different names than those created by the extension.
When specified as a dict (e.g., {"my_foo": "ext_foo"}), bazel mod tidy
will generate use_repo commands with the mapping syntax (my_foo = "ext_foo").
1426a7d to
6591c9a
Compare
|
@Wyverald and @meteorcloudy if we all agree that this is a good idea, could we get some help to get the buildozer PR merged and released so that this can still make it in time for Bazel 9? As @fmeum mentioned, this can help solve many of the reasons why people would want isolated extensions (and subsequently could potentially allow us to get rid of true isolated extensions). |
|
@bazel-io fork 9.0.0 |
Allow root_module_direct_deps and root_module_direct_dev_deps to accept dicts mapping module-local names to extension-exported names, in addition to the existing list format. This enables modules to import repositories under different names than those created by the extension.
When specified as a dict (e.g., {"my_foo": "ext_foo"}), bazel mod tidy will generate use_repo commands with the mapping syntax (my_foo = "ext_foo").
Context: https://bazelbuild.slack.com/archives/C09E58X3AQ7/p1764934858912079
Stacked on bazelbuild/buildtools#1427. I'll add some more tests in
mod_command_test.pyonce the buildozer change is merged and available forbazel mod tidy.RELNOTES:
module_ctx.extension_metadatanow accepts dictionary mappings in theroot_module_direct_depsandroot_module_direct_dev_depsparameters. Keys are the module‑local repository names and values are the names exported by the extension. When such a mapping is provided,bazel mod tidygeneratesuse_repocalls with the mapping syntax (e.g.,my_foo = "ext_foo"), letting modules import an extension’s repositories under custom local names.