-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a repository_ctx
field to accommodate default repo target names
#24467
Comments
BTW, just found out this other clever method of parsing out the SEPARATOR = Label("@local").workspace_name.removesuffix("local")[-1] target = rctx.attr.target or rctx.attr.name.rsplit(SEPARATOR, 1)[1] |
Reassigning to team-OSS. |
This new attribute contains the original value of the `name` attribute at the instantiation site of the repo rule (e.g., `rctx.original_name` would be `foo` if `rctx.name` is `+ext+foo`). Fixes bazelbuild#24467 Closes bazelbuild#25121. RELNOTES: Added `repository_ctx.original_name`, which contains the original value of the `name` attribute as specified at the repo rule call site. PiperOrigin-RevId: 722731393 Change-Id: I2f7dada0c44b6bd4c0d2622fa1e97223382a8547 (cherry picked from commit 8bcfb06)
This new attribute contains the original value of the `name` attribute at the instantiation site of the repo rule (e.g., `rctx.original_name` would be `foo` if `rctx.name` is `+ext+foo`). Fixes bazelbuild#24467 Closes bazelbuild#25121. RELNOTES: Added `repository_ctx.original_name`, which contains the original value of the `name` attribute as specified at the repo rule call site. PiperOrigin-RevId: 722731393 Change-Id: I2f7dada0c44b6bd4c0d2622fa1e97223382a8547 (cherry picked from commit 8bcfb06)
This new attribute contains the original value of the `name` attribute at the instantiation site of the repo rule (e.g., `rctx.original_name` would be `foo` if `rctx.name` is `+ext+foo`). Fixes bazelbuild#24467 Closes bazelbuild#25121. RELNOTES: Added `repository_ctx.original_name`, which contains the original value of the `name` attribute as specified at the repo rule call site. PiperOrigin-RevId: 722731393 Change-Id: I2f7dada0c44b6bd4c0d2622fa1e97223382a8547 (cherry picked from commit 8bcfb06)
This new attribute contains the original value of the `name` attribute at the instantiation site of the repo rule (e.g., `rctx.original_name` would be `foo` if `rctx.name` is `+ext+foo`). Fixes #24467 Closes #25121. RELNOTES: Added `repository_ctx.original_name`, which contains the original value of the `name` attribute as specified at the repo rule call site. PiperOrigin-RevId: 722731393 Change-Id: I2f7dada0c44b6bd4c0d2622fa1e97223382a8547 (cherry picked from commit 8bcfb06) Fixes #25147
A fix for this issue has been included in Bazel 8.1.0 RC2. Please test out the release candidate and report any issues as soon as possible. |
Took |
Prepares for `repository_ctx.original_name` support in Bazel 8.1.0 per bazelbuild/bazel#24467 and bumps Go to 1.23.6. Part of bazelbuild#1482 and bazelbuild#1652. The underlying repo rules will now use `repository_ctx.original_name` if it's available. I've confirmed that these changes use `repository_ctx.original_name` under Bazel 8.1.0rc2 after commenting out the wrappers and restoring the original repo rule symbols. --- This change ensures compatibility with future Bazel releases. New comments indicate where to simplify code after dropping support for Bazel versions that don't have `repository_ctx.original_name`. The Go 1.23.6 bump is a convenience update that isn't essential to the rest of the change. Under Bzlmod, `repository_ctx.name` contains the canonical repository name. This broke the `_alias_repository` and `jvm_import_external` repository rules, which used `repository_ctx.name` to generate default top level target names for their repos. bazelbuild#1650 added wrapper macros passing the original name as an extra attribute to the underlying repo rules as a portable workaround. The Bazel maintainers eventually recognized this as a common use case and added `repository_ctx.original_name` to eliminate the need for such wrappers (eventually). - https://bazel.build/rules/lib/builtins/repository_ctx#name - https://bazel.build/rules/lib/builtins/repository_ctx#original_name
Prepares for `repository_ctx.original_name` support in Bazel 8.1.0 per bazelbuild/bazel#24467 and bumps Go to 1.23.6. Part of bazelbuild#1482 and bazelbuild#1652. The underlying repo rules will now use `repository_ctx.original_name` if it's available. I've confirmed that these changes use `repository_ctx.original_name` under Bazel 8.1.0rc2 after commenting out the wrappers and restoring the original repo rule symbols. --- This change ensures compatibility with future Bazel releases. New comments indicate where to simplify code after dropping support for Bazel versions that don't have `repository_ctx.original_name`. The Go 1.23.6 bump is a convenience update that isn't essential to the rest of the change. Under Bzlmod, `repository_ctx.name` contains the canonical repository name. This broke the `_alias_repository` and `jvm_import_external` repository rules, which used `repository_ctx.name` to generate default top level target names for their repos. bazelbuild#1650 added wrapper macros passing the original name as an extra attribute to the underlying repo rules as a portable workaround. The Bazel maintainers eventually recognized this as a common use case and added `repository_ctx.original_name` to eliminate the need for such wrappers (eventually). - https://bazel.build/rules/lib/builtins/repository_ctx#name - https://bazel.build/rules/lib/builtins/repository_ctx#original_name
Prepares for `repository_ctx.original_name` support in Bazel 8.1.0 per bazelbuild/bazel#24467 and bumps Go to 1.23.6. Part of #1482 and #1652. The underlying repo rules will now use `repository_ctx.original_name` if it's available. I've confirmed that these changes use `repository_ctx.original_name` under Bazel 8.1.0rc2 after commenting out the wrappers and restoring the original repo rule symbols. --- This change ensures compatibility with future Bazel releases. New comments indicate where to simplify code after dropping support for Bazel versions that don't have `repository_ctx.original_name`. The Go 1.23.6 bump is a convenience update that isn't essential to the rest of the change. Under Bzlmod, `repository_ctx.name` contains the canonical repository name. This broke the `_alias_repository` and `jvm_import_external` repository rules, which used `repository_ctx.name` to generate default top level target names for their repos. #1650 added wrapper macros passing the original name as an extra attribute to the underlying repo rules as a portable workaround. The Bazel maintainers eventually recognized this as a common use case and added `repository_ctx.original_name` to eliminate the need for such wrappers (eventually). - https://bazel.build/rules/lib/builtins/repository_ctx#name - https://bazel.build/rules/lib/builtins/repository_ctx#original_name
Works around breakages when building under `WORKSPACE` with Bazel 8.1.0, as described in bazelbuild/bazel#25286. Part of bazelbuild#1652. PR bazelbuild#1694 added support for `rctx.original_name` after the implementation of bazelbuild/bazel#24467 landed in 8.1.0rc2. However, I hadn't tested `WORKSPACE` builds with 8.1.0rc2 before 8.1.0 came out. This resolves the breakage, but should only be necessary if a Bazel 8 release containing a fix for bazelbuild/bazel#25286 isn't yet available.
Works around breakages when building under `WORKSPACE` with Bazel 8.1.0, as described in bazelbuild/bazel#25286. Part of bazelbuild#1652. PR bazelbuild#1694 added support for `rctx.original_name` after the implementation of bazelbuild/bazel#24467 landed in 8.1.0rc2. However, I hadn't tested `WORKSPACE` builds with 8.1.0rc2 before 8.1.0 came out. This resolves the breakage until a Bazel 8 release containing a fix for bazelbuild/bazel#25286 becomes available (possibly Bazel 8.2.0).
Works around breakages when building under `WORKSPACE` with Bazel 8.1.0, as described in bazelbuild/bazel#25286. Part of bazelbuild#1652. PR bazelbuild#1694 added support for `rctx.original_name` after the implementation of bazelbuild/bazel#24467 landed in 8.1.0rc2. However, I hadn't tested `WORKSPACE` builds with 8.1.0rc2 before 8.1.0 came out. This resolves the breakage until a Bazel 8 release containing a fix for bazelbuild/bazel#25286 becomes available (possibly Bazel 8.2.0).
Works around breakages when building under `WORKSPACE` with Bazel 8.1.0, as described in bazelbuild/bazel#25286. Part of bazelbuild#1652. PR bazelbuild#1694 added support for `rctx.original_name` after the implementation of bazelbuild/bazel#24467 landed in 8.1.0rc2. However, I hadn't tested `WORKSPACE` builds with 8.1.0rc2 before 8.1.0 came out. This resolves the breakage until a Bazel 8 release containing a fix for bazelbuild/bazel#25286 becomes available (possibly Bazel 8.2.0).
Works around breakages when building under `WORKSPACE` with Bazel 8.1.0, as described in bazelbuild/bazel#25286. Part of bazelbuild#1652. PR bazelbuild#1694 added support for `rctx.original_name` after the implementation of bazelbuild/bazel#24467 landed in 8.1.0rc2. However, I hadn't tested `WORKSPACE` builds with 8.1.0rc2 before 8.1.0 came out. This resolves the breakage until a Bazel 8 release containing a fix for bazelbuild/bazel#25286 becomes available (possibly Bazel 8.2.0).
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: