Add a repository_ctx
field to accommodate default repo target names
#24467
Labels
team-Rules-API
API for writing rules/aspects: providers, runfiles, actions, artifacts
type: feature request
untriaged
Description of the feature request:
A
repository_ctx
parameter holding the original, user-providedname
value, facilitating the creation of default repo target names without workaroundsWhich 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 previousrepository_rule
implementations that used this value to construct a default target name underWORKSPACE
. One can work around this issue by adding a separateattr
to duplicate thename
parameter of a givenrepository
rule, but this degrades the interface somewhat and is potentially error prone.I've implemented a pattern in bazelbuild/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 fromrepository_ctx.name
, from bazelbuild/rules_scala#1621 and the withdrawn bazelbuild/bazel-skylib#548. Both flavors of workaround, however, reflect extra effort to grab information already passed as thename
parameter of arepository_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
returnsdevelopment 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
?Have you found anything relevant by searching the web?
N/A
Any other information, logs, or outputs that you want to share?
N/A
The text was updated successfully, but these errors were encountered: