Skip to content

Conversation

@bazel-io
Copy link
Member

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 #27890.

PiperOrigin-RevId: 845156030
Change-Id: Ic5d777645bf6a5ca67fa6cb577f426c96beda894

Commit 7ca1159

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
@bazel-io bazel-io requested a review from a team as a code owner December 16, 2025 11:10
@bazel-io bazel-io added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. awaiting-review PR is awaiting review from an assigned reviewer labels Dec 16, 2025
@bazel-io bazel-io requested a review from Wyverald December 16, 2025 11:10
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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);
}

Choose a reason for hiding this comment

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

high

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);
    }

@iancha1992 iancha1992 enabled auto-merge December 16, 2025 19:24
@iancha1992 iancha1992 added this pull request to the merge queue Dec 17, 2025
Merged via the queue into bazelbuild:release-9.0.0 with commit 8330f7d Dec 17, 2025
46 checks passed
@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Dec 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants