Skip to content

Commit 0a06492

Browse files
authored
Use rctx.original_name if available, Go 1.23.6 (#1694)
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
1 parent 21f70db commit 0a06492

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

WORKSPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ load(
9696

9797
go_rules_dependencies()
9898

99-
go_register_toolchains(version = "1.23.5")
99+
go_register_toolchains(version = "1.23.6")
100100

101101
http_archive(
102102
name = "bazelci_rules",

scala/scala_maven_import_external.bzl

+5-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ def _jvm_import_external_impl(repository_ctx):
6868
if (repository_ctx.attr.generated_linkable_rule_name and
6969
not repository_ctx.attr.neverlink):
7070
fail("Only use generated_linkable_rule_name if neverlink is set")
71-
repo_name = repository_ctx.name
71+
72+
# Replace with rctx.original_name once all supported Bazels have it
73+
repo_name = getattr(repository_ctx, "original_name", repository_ctx.name)
7274
name = repository_ctx.attr.generated_rule_name or repo_name
7375
urls = repository_ctx.attr.jar_urls
7476
if repository_ctx.attr.jar_sha256:
@@ -257,6 +259,8 @@ _jvm_import_external = repository_rule(
257259
environ = [_FETCH_SOURCES_ENV_VAR_NAME],
258260
)
259261

262+
# Remove this macro and restore `_jvm_import_external` to `jvm_import_external`
263+
# once all supported Bazel versions support `repository_ctx.original_name`.
260264
def jvm_import_external(**kwargs):
261265
"""Wraps `_jvm_import_external` to pass `name` as `generated_target_name`.
262266

third_party/repositories/repositories.bzl

+5-2
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ def repositories(
140140

141141
def _alias_repository_impl(rctx):
142142
""" Builds a repository containing just two aliases to the Scala Maven artifacts in the `target` repository. """
143-
144143
format_kwargs = {
145-
"name": rctx.attr.default_target_name,
144+
# Replace with rctx.original_name once all supported Bazels have it
145+
"name": getattr(rctx, "original_name", rctx.attr.default_target_name),
146146
"target": rctx.attr.target,
147147
}
148148
rctx.file("BUILD", """alias(
@@ -161,11 +161,14 @@ def _alias_repository_impl(rctx):
161161
_alias_repository = repository_rule(
162162
implementation = _alias_repository_impl,
163163
attrs = {
164+
# Remove once all supported Bazels have repository_ctx.original_name
164165
"default_target_name": attr.string(mandatory = True),
165166
"target": attr.string(mandatory = True),
166167
},
167168
)
168169

170+
# Remove this macro and use `_alias_repository` directly once all supported
171+
# Bazel versions support `repository_ctx.original_name`.
169172
def _alias_repository_wrapper(**kwargs):
170173
"""Wraps `_alias_repository` to pass `name` as `default_target_name`."""
171174
default_target_name = kwargs.pop("default_target_name", kwargs.get("name"))

0 commit comments

Comments
 (0)