-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Description of the feature request:
A repository_ctx parameter holding the original, user-provided name value, facilitating the creation of default repo target names without workarounds
Which category does this issue belong to?
Rules API
What underlying problem are you trying to solve with this feature?
Label supports default target names based on repo names. For example, @repo expands to @repo//:repo.
Under Bzlmod, repository_ctx.name is now the canonical repo name, invalidating previous repository_rule implementations that used this value to construct a default target name under WORKSPACE. One can work around this issue by adding a separate attr to duplicate the name parameter of a given repository rule, but this degrades the interface somewhat and is potentially error prone.
I've implemented a pattern in bazel-contrib/rules_scala#1650 to wrap a repository_rule in a macro to handle this duplication on behalf of the user, keeping the ergonomics of the original rule, but with trade-offs. This came after my first workaround, parsing the original name from repository_ctx.name, from bazel-contrib/rules_scala#1621 and the withdrawn bazelbuild/bazel-skylib#548. Both flavors of workaround, however, reflect extra effort to grab information already passed as the name parameter of a repository_rule.
As originally discussed with @Wyverald and @fmeum in a #bzlmod channel thread in the Bazel Slack Workspace, a dedicated repository_ctx field would eliminate the need for such workarounds in the future. I'd imagine it could be backported to Bazel 7, and even to Bazel 6, to remove friction from Bzlmod migrations.
Which operating system are you running Bazel on?
N/A
What is the output of bazel info release?
N/A
If bazel info release returns development version or (@non-git), tell us how you built Bazel.
N/A
What's the output of git remote get-url origin; git rev-parse HEAD ?
N/A
Have you found anything relevant by searching the web?
N/A
Any other information, logs, or outputs that you want to share?
N/A