xref: /aosp_15_r20/external/bazelbuild-rules_go/go/tools/gopackagesdriver/BUILD.bazel (revision 9bb1b549b6a84214c53be0924760be030e66b93a)
1load("//go:def.bzl", "go_binary", "go_library")
2load(":aspect.bzl", "bazel_supports_canonical_label_literals")
3
4go_library(
5    name = "gopackagesdriver_lib",
6    srcs = [
7        "bazel.go",
8        "bazel_json_builder.go",
9        "build_context.go",
10        "driver_request.go",
11        "flatpackage.go",
12        "json_packages_driver.go",
13        "main.go",
14        "packageregistry.go",
15        "utils.go",
16    ],
17    importpath = "github.com/bazelbuild/rules_go/go/tools/gopackagesdriver",
18    visibility = ["//visibility:private"],
19)
20
21go_binary(
22    name = "gopackagesdriver",
23    embed = [":gopackagesdriver_lib"],
24    x_defs = {
25        # Determine the name of the rules_go repository as we need to specify it when invoking the
26        # aspect.
27        # If canonical label literals are supported, we can use a canonical label literal (starting
28        # with @@) to pass the repository_name() through repo mapping unchanged.
29        # If canonical label literals are not supported, then bzlmod is certainly not enabled and
30        # we can assume that the repository name is not affected by repo mappings.
31        # If run in the rules_go repo itself, repository_name() returns "@", which is equivalent to
32        # "@io_bazel_rules_go" since Bazel 6:
33        # https://github.com/bazelbuild/bazel/commit/7694cf75e6366b92e3905c2ad60234cda57627ee
34        # TODO: Once we drop support for Bazel 5, we can remove the feature detection logic and
35        #       use "@" + repository_name().
36        "rulesGoRepositoryName": "@" + repository_name() if bazel_supports_canonical_label_literals() else repository_name(),
37    },
38    visibility = ["//visibility:public"],
39)
40