Skip to content

Commit

Permalink
Remove module extension repo name hack
Browse files Browse the repository at this point in the history
This hack is not necessary as the name of the referenced repo is static and thus can be `use_repo`ed (in fact, it is already visible).
  • Loading branch information
fmeum committed Aug 20, 2024
1 parent d0a54d3 commit e2da68c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
4 changes: 1 addition & 3 deletions internal/bzlmod/go_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,7 @@ def _go_deps_impl(module_ctx):
continue
go_repository_args = {
"name": module.repo_name,
# Compared to the name attribute, the content of this attribute does not go through repo
# mapping.
"internal_only_do_not_use_apparent_name": module.repo_name,
"internal_only_do_not_use_is_extension_repo": True,
"importpath": path,
"build_directives": _get_directives(path, gazelle_overrides, gazelle_default_attributes),
"build_file_generation": _get_build_file_generation(path, gazelle_overrides, gazelle_default_attributes),
Expand Down
11 changes: 3 additions & 8 deletions internal/go_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _go_repository_impl(ctx):
fetch_repo_args = None
gazelle_path = None

is_module_extension_repo = bool(ctx.attr.internal_only_do_not_use_apparent_name)
is_module_extension_repo = ctx.attr.internal_only_do_not_use_is_extension_repo

# Declare Label dependencies at the top of function to avoid unnecessary fetching:
# https://docs.bazel.build/versions/main/skylark/repository_rules.html#when-is-the-implementation-function-executed
Expand Down Expand Up @@ -311,12 +311,7 @@ def _go_repository_impl(ctx):
gazelle_path = ctx.path(Label(_gazelle))

if is_module_extension_repo:
# This repository is generated by the 'go_deps' extension. Since as of Bazel 7.2.0 there
# is no API that constructs a label referencing a sibling repo from within a repo rule,
# we rely on the assumption that the apparent name of the extension-generated repos is
# the last component of their canonical names.
extension_repo_prefix = ctx.attr.name[:-len(ctx.attr.internal_only_do_not_use_apparent_name)]
repo_config = ctx.path(Label("@@" + extension_repo_prefix + "bazel_gazelle_go_repository_config//:WORKSPACE"))
repo_config = ctx.path(Label("@bazel_gazelle_go_repository_config//:WORKSPACE"))
else:
repo_config = ctx.path(ctx.attr.build_config)
cmd = [
Expand Down Expand Up @@ -640,7 +635,7 @@ go_repository = repository_rule(
unexpected behavior for the given rule.
""",
),
"internal_only_do_not_use_apparent_name": attr.string(doc = "Internal usage only"),
"internal_only_do_not_use_is_extension_repo": attr.bool(doc = "Internal usage only"),
},
)
"""See repository.md#go-repository for full documentation."""

0 comments on commit e2da68c

Please sign in to comment.