[9.0.0] Support {name} and {version} placeholders in use_repo#28016
Merged
iancha1992 merged 1 commit intobazelbuild:release-9.0.0from Dec 17, 2025
Merged
[9.0.0] Support {name} and {version} placeholders in use_repo#28016iancha1992 merged 1 commit intobazelbuild:release-9.0.0from
{name} and {version} placeholders in use_repo#28016iancha1992 merged 1 commit intobazelbuild:release-9.0.0from
Conversation
This allows module extensions to reliably namespace repos created by individual modules, even in the presence of `multiple_version_override`, without causing additional churn for users during version bumps. In particular, projects with a publishing workflow that patches in the `version` attribute of the `module` function don't need to modify that workflow to e.g. patch a global constant or also search for the old version in `use_repo` call arguments. Context: https://bazelbuild.slack.com/archives/C09E58X3AQ7/p1764934858912079 RELNOTES: The values of keyword arguments passed to `use_repo` can now contain the special substrings `{name}` and `{version}`, which are treated as equivalent to the corresponding attributes of the current module. Closes bazelbuild#27890. PiperOrigin-RevId: 845156030 Change-Id: Ic5d777645bf6a5ca67fa6cb577f426c96beda894
There was a problem hiding this comment.
Code Review
This pull request adds support for {name} and {version} placeholders in use_repo keyword arguments. This is a useful feature for namespacing repositories. The implementation is straightforward and well-tested. I've suggested extending this support to positional arguments for consistency.
Comment on lines
663
to
675
| for (String arg : Sequence.cast(args, String.class, "args")) { | ||
| extensionProxy.addImport(arg, arg, "by a use_repo() call", stack); | ||
| } | ||
| String moduleName = context.getModuleBuilder().getName(); | ||
| String moduleVersion = context.getModuleBuilder().getVersion().normalized(); | ||
| for (Map.Entry<String, String> entry : | ||
| Dict.cast(kwargs, String.class, String.class, "kwargs").entrySet()) { | ||
| extensionProxy.addImport(entry.getKey(), entry.getValue(), "by a use_repo() call", stack); | ||
| extensionProxy.addImport( | ||
| entry.getKey(), | ||
| entry.getValue().replace("{name}", moduleName).replace("{version}", moduleVersion), | ||
| "by a use_repo() call", | ||
| stack); | ||
| } |
There was a problem hiding this comment.
For consistency, the placeholder substitution for {name} and {version} should also be applied to positional arguments in use_repo. Currently, it's only done for keyword arguments. This would make the feature more complete and predictable for users.
If you apply this change, please also consider adding a test case for positional arguments to the useRepo_placeholders test.
String moduleName = context.getModuleBuilder().getName();
String moduleVersion = context.getModuleBuilder().getVersion().normalized();
for (String arg : Sequence.cast(args, String.class, "args")) {
String substitutedArg = arg.replace("{name}", moduleName).replace("{version}", moduleVersion);
extensionProxy.addImport(substitutedArg, substitutedArg, "by a use_repo() call", stack);
}
for (Map.Entry<String, String> entry :
Dict.cast(kwargs, String.class, String.class, "kwargs").entrySet()) {
extensionProxy.addImport(
entry.getKey(),
entry.getValue().replace("{name}", moduleName).replace("{version}", moduleVersion),
"by a use_repo() call",
stack);
}
meteorcloudy
approved these changes
Dec 17, 2025
Merged
via the queue into
bazelbuild:release-9.0.0
with commit Dec 17, 2025
8330f7d
46 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This allows module extensions to reliably namespace repos created by individual modules, even in the presence of
multiple_version_override, without causing additional churn for users during version bumps. In particular, projects with a publishing workflow that patches in theversionattribute of themodulefunction don't need to modify that workflow to e.g. patch a global constant or also search for the old version inuse_repocall arguments.Context: https://bazelbuild.slack.com/archives/C09E58X3AQ7/p1764934858912079
RELNOTES: The values of keyword arguments passed to
use_repocan now contain the special substrings{name}and{version}, which are treated as equivalent to the corresponding attributes of the current module.Closes #27890.
PiperOrigin-RevId: 845156030
Change-Id: Ic5d777645bf6a5ca67fa6cb577f426c96beda894
Commit 7ca1159