From e2da68c07acdb06ec9a5652f237ed64faefaf460 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Tue, 20 Aug 2024 14:53:08 +0200 Subject: [PATCH] Remove module extension repo name hack 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). --- internal/bzlmod/go_deps.bzl | 4 +--- internal/go_repository.bzl | 11 +++-------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/internal/bzlmod/go_deps.bzl b/internal/bzlmod/go_deps.bzl index dcd0db37c..49ec8af38 100644 --- a/internal/bzlmod/go_deps.bzl +++ b/internal/bzlmod/go_deps.bzl @@ -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), diff --git a/internal/go_repository.bzl b/internal/go_repository.bzl index 01b66d573..56aba3e0f 100644 --- a/internal/go_repository.bzl +++ b/internal/go_repository.bzl @@ -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 @@ -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 = [ @@ -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."""