xref: /aosp_15_r20/external/bazel-skylib/gazelle/bzl/BUILD (revision bcb5dc7965af6ee42bf2f21341a2ec00233a8c8a)
1*bcb5dc79SHONG Yifanload("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
2*bcb5dc79SHONG Yifanload("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
3*bcb5dc79SHONG Yifan
4*bcb5dc79SHONG Yifanpackage(default_applicable_licenses = ["//:license"])
5*bcb5dc79SHONG Yifan
6*bcb5dc79SHONG Yifan# gazelle:exclude testdata
7*bcb5dc79SHONG Yifan
8*bcb5dc79SHONG Yifango_library(
9*bcb5dc79SHONG Yifan    name = "bzl",
10*bcb5dc79SHONG Yifan    srcs = ["gazelle.go"],
11*bcb5dc79SHONG Yifan    importpath = "github.com/bazelbuild/bazel-skylib/gazelle",
12*bcb5dc79SHONG Yifan    visibility = ["//visibility:public"],
13*bcb5dc79SHONG Yifan    deps = [
14*bcb5dc79SHONG Yifan        "@bazel_gazelle//config:go_default_library",
15*bcb5dc79SHONG Yifan        "@bazel_gazelle//label:go_default_library",
16*bcb5dc79SHONG Yifan        "@bazel_gazelle//language:go_default_library",
17*bcb5dc79SHONG Yifan        "@bazel_gazelle//pathtools:go_default_library",
18*bcb5dc79SHONG Yifan        "@bazel_gazelle//repo:go_default_library",
19*bcb5dc79SHONG Yifan        "@bazel_gazelle//resolve:go_default_library",
20*bcb5dc79SHONG Yifan        "@bazel_gazelle//rule:go_default_library",
21*bcb5dc79SHONG Yifan        "@com_github_bazelbuild_buildtools//build:go_default_library",
22*bcb5dc79SHONG Yifan    ],
23*bcb5dc79SHONG Yifan)
24*bcb5dc79SHONG Yifan
25*bcb5dc79SHONG Yifango_test(
26*bcb5dc79SHONG Yifan    name = "bzl_test",
27*bcb5dc79SHONG Yifan    srcs = ["gazelle_test.go"],
28*bcb5dc79SHONG Yifan    data = [
29*bcb5dc79SHONG Yifan        ":gazelle-skylib",
30*bcb5dc79SHONG Yifan    ] + glob(
31*bcb5dc79SHONG Yifan        [
32*bcb5dc79SHONG Yifan            "testdata/**",
33*bcb5dc79SHONG Yifan        ],
34*bcb5dc79SHONG Yifan        allow_empty = True,
35*bcb5dc79SHONG Yifan    ),
36*bcb5dc79SHONG Yifan    embed = [":bzl"],
37*bcb5dc79SHONG Yifan    deps = [
38*bcb5dc79SHONG Yifan        "@bazel_gazelle//testtools:go_default_library",
39*bcb5dc79SHONG Yifan        "@io_bazel_rules_go//go/tools/bazel:go_default_library",
40*bcb5dc79SHONG Yifan    ],
41*bcb5dc79SHONG Yifan)
42*bcb5dc79SHONG Yifan
43*bcb5dc79SHONG Yifan# This gazelle binary is used exclusively for testing the gazelle language
44*bcb5dc79SHONG Yifan# extension and thus only has the skylib language installed.
45*bcb5dc79SHONG Yifangazelle_binary(
46*bcb5dc79SHONG Yifan    name = "gazelle-skylib",
47*bcb5dc79SHONG Yifan    languages = [":bzl"],
48*bcb5dc79SHONG Yifan    visibility = [
49*bcb5dc79SHONG Yifan        # Also make the binary available in the root of the repo for use, but
50*bcb5dc79SHONG Yifan        # not externally.
51*bcb5dc79SHONG Yifan        "//:__pkg__",
52*bcb5dc79SHONG Yifan    ],
53*bcb5dc79SHONG Yifan)
54*bcb5dc79SHONG Yifan
55*bcb5dc79SHONG Yifangazelle(
56*bcb5dc79SHONG Yifan    name = "gazelle",
57*bcb5dc79SHONG Yifan    gazelle = ":gazelle-skylib",
58*bcb5dc79SHONG Yifan)
59*bcb5dc79SHONG Yifan
60*bcb5dc79SHONG Yifan# TODO(arostovtsev): exclude everything below from distro tarball
61*bcb5dc79SHONG Yifan
62*bcb5dc79SHONG Yifan# The files needed for distribution
63*bcb5dc79SHONG Yifan# A fake testdata directory is created so that
64*bcb5dc79SHONG Yifan# the build file has nothing missing, but we
65*bcb5dc79SHONG Yifan# do not bloat the distribution tarball
66*bcb5dc79SHONG Yifanfilegroup(
67*bcb5dc79SHONG Yifan    name = "distribution",
68*bcb5dc79SHONG Yifan    srcs = glob(["*.go"]) + [
69*bcb5dc79SHONG Yifan        "BUILD",
70*bcb5dc79SHONG Yifan        ":fake-testdata",
71*bcb5dc79SHONG Yifan    ],
72*bcb5dc79SHONG Yifan    visibility = ["//visibility:public"],
73*bcb5dc79SHONG Yifan)
74*bcb5dc79SHONG Yifan
75*bcb5dc79SHONG Yifangenrule(
76*bcb5dc79SHONG Yifan    name = "fake-testdata",
77*bcb5dc79SHONG Yifan    outs = ["testdata"],
78*bcb5dc79SHONG Yifan    cmd = "touch $@",
79*bcb5dc79SHONG Yifan)
80