xref: /aosp_15_r20/external/bazelbuild-rules_python/gazelle/python/BUILD.bazel (revision 60517a1edbc8ecf509223e9af94a7adec7d736b8)
1*60517a1eSAndroid Build Coastguard Workerload("@bazel_gazelle//:def.bzl", "gazelle_binary")
2*60517a1eSAndroid Build Coastguard Workerload("@bazel_skylib//rules:copy_file.bzl", "copy_file")
3*60517a1eSAndroid Build Coastguard Workerload("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
4*60517a1eSAndroid Build Coastguard Workerload(":gazelle_test.bzl", "gazelle_test")
5*60517a1eSAndroid Build Coastguard Worker
6*60517a1eSAndroid Build Coastguard Workergo_library(
7*60517a1eSAndroid Build Coastguard Worker    name = "python",
8*60517a1eSAndroid Build Coastguard Worker    srcs = [
9*60517a1eSAndroid Build Coastguard Worker        "configure.go",
10*60517a1eSAndroid Build Coastguard Worker        "file_parser.go",
11*60517a1eSAndroid Build Coastguard Worker        "fix.go",
12*60517a1eSAndroid Build Coastguard Worker        "generate.go",
13*60517a1eSAndroid Build Coastguard Worker        "kinds.go",
14*60517a1eSAndroid Build Coastguard Worker        "language.go",
15*60517a1eSAndroid Build Coastguard Worker        "parser.go",
16*60517a1eSAndroid Build Coastguard Worker        "resolve.go",
17*60517a1eSAndroid Build Coastguard Worker        "std_modules.go",
18*60517a1eSAndroid Build Coastguard Worker        "target.go",
19*60517a1eSAndroid Build Coastguard Worker    ],
20*60517a1eSAndroid Build Coastguard Worker    # NOTE @aignas 2023-12-03: currently gazelle does not support embedding
21*60517a1eSAndroid Build Coastguard Worker    # generated files, but 3.11.txt is generated by a build rule.
22*60517a1eSAndroid Build Coastguard Worker    #
23*60517a1eSAndroid Build Coastguard Worker    # You will get a benign error like when running gazelle locally:
24*60517a1eSAndroid Build Coastguard Worker    # > 8 gazelle: .../rules_python/gazelle/python/std_modules.go:24:3: pattern 3.11.txt: matched no files
25*60517a1eSAndroid Build Coastguard Worker    #
26*60517a1eSAndroid Build Coastguard Worker    # See following for more info:
27*60517a1eSAndroid Build Coastguard Worker    # https://github.com/bazelbuild/bazel-gazelle/issues/1513
28*60517a1eSAndroid Build Coastguard Worker    embedsrcs = ["stdlib_list.txt"],  # keep # TODO: use user-defined version?
29*60517a1eSAndroid Build Coastguard Worker    importpath = "github.com/bazelbuild/rules_python/gazelle/python",
30*60517a1eSAndroid Build Coastguard Worker    visibility = ["//visibility:public"],
31*60517a1eSAndroid Build Coastguard Worker    deps = [
32*60517a1eSAndroid Build Coastguard Worker        "//manifest",
33*60517a1eSAndroid Build Coastguard Worker        "//pythonconfig",
34*60517a1eSAndroid Build Coastguard Worker        "@bazel_gazelle//config:go_default_library",
35*60517a1eSAndroid Build Coastguard Worker        "@bazel_gazelle//label:go_default_library",
36*60517a1eSAndroid Build Coastguard Worker        "@bazel_gazelle//language:go_default_library",
37*60517a1eSAndroid Build Coastguard Worker        "@bazel_gazelle//repo:go_default_library",
38*60517a1eSAndroid Build Coastguard Worker        "@bazel_gazelle//resolve:go_default_library",
39*60517a1eSAndroid Build Coastguard Worker        "@bazel_gazelle//rule:go_default_library",
40*60517a1eSAndroid Build Coastguard Worker        "@com_github_bazelbuild_buildtools//build:go_default_library",
41*60517a1eSAndroid Build Coastguard Worker        "@com_github_bmatcuk_doublestar_v4//:doublestar",
42*60517a1eSAndroid Build Coastguard Worker        "@com_github_emirpasic_gods//lists/singlylinkedlist",
43*60517a1eSAndroid Build Coastguard Worker        "@com_github_emirpasic_gods//sets/treeset",
44*60517a1eSAndroid Build Coastguard Worker        "@com_github_emirpasic_gods//utils",
45*60517a1eSAndroid Build Coastguard Worker        "@com_github_smacker_go_tree_sitter//:go-tree-sitter",
46*60517a1eSAndroid Build Coastguard Worker        "@com_github_smacker_go_tree_sitter//python",
47*60517a1eSAndroid Build Coastguard Worker        "@org_golang_x_sync//errgroup",
48*60517a1eSAndroid Build Coastguard Worker    ],
49*60517a1eSAndroid Build Coastguard Worker)
50*60517a1eSAndroid Build Coastguard Worker
51*60517a1eSAndroid Build Coastguard Workercopy_file(
52*60517a1eSAndroid Build Coastguard Worker    name = "stdlib_list",
53*60517a1eSAndroid Build Coastguard Worker    src = select(
54*60517a1eSAndroid Build Coastguard Worker        {
55*60517a1eSAndroid Build Coastguard Worker            "@rules_python//python/config_settings:is_python_3.10": "@python_stdlib_list//:stdlib_list/lists/3.10.txt",
56*60517a1eSAndroid Build Coastguard Worker            "@rules_python//python/config_settings:is_python_3.11": "@python_stdlib_list//:stdlib_list/lists/3.11.txt",
57*60517a1eSAndroid Build Coastguard Worker            "@rules_python//python/config_settings:is_python_3.12": "@python_stdlib_list//:stdlib_list/lists/3.12.txt",
58*60517a1eSAndroid Build Coastguard Worker            "@rules_python//python/config_settings:is_python_3.8": "@python_stdlib_list//:stdlib_list/lists/3.8.txt",
59*60517a1eSAndroid Build Coastguard Worker            "@rules_python//python/config_settings:is_python_3.9": "@python_stdlib_list//:stdlib_list/lists/3.9.txt",
60*60517a1eSAndroid Build Coastguard Worker            # This is the same behaviour as previously
61*60517a1eSAndroid Build Coastguard Worker            "//conditions:default": "@python_stdlib_list//:stdlib_list/lists/3.11.txt",
62*60517a1eSAndroid Build Coastguard Worker        },
63*60517a1eSAndroid Build Coastguard Worker    ),
64*60517a1eSAndroid Build Coastguard Worker    out = "stdlib_list.txt",
65*60517a1eSAndroid Build Coastguard Worker    allow_symlink = True,
66*60517a1eSAndroid Build Coastguard Worker)
67*60517a1eSAndroid Build Coastguard Worker
68*60517a1eSAndroid Build Coastguard Worker# gazelle:exclude testdata/
69*60517a1eSAndroid Build Coastguard Worker
70*60517a1eSAndroid Build Coastguard Workergazelle_test(
71*60517a1eSAndroid Build Coastguard Worker    name = "python_test",
72*60517a1eSAndroid Build Coastguard Worker    srcs = ["python_test.go"],
73*60517a1eSAndroid Build Coastguard Worker    data = [
74*60517a1eSAndroid Build Coastguard Worker        ":gazelle_binary",
75*60517a1eSAndroid Build Coastguard Worker    ],
76*60517a1eSAndroid Build Coastguard Worker    test_dirs = glob(
77*60517a1eSAndroid Build Coastguard Worker        # Use this so that we don't need to manually maintain the list.
78*60517a1eSAndroid Build Coastguard Worker        ["testdata/*"],
79*60517a1eSAndroid Build Coastguard Worker        exclude = ["testdata/*.md"],
80*60517a1eSAndroid Build Coastguard Worker        # The directories aren't inputs themselves; we just want their
81*60517a1eSAndroid Build Coastguard Worker        # names.
82*60517a1eSAndroid Build Coastguard Worker        exclude_directories = 0,
83*60517a1eSAndroid Build Coastguard Worker    ),
84*60517a1eSAndroid Build Coastguard Worker    deps = [
85*60517a1eSAndroid Build Coastguard Worker        "@bazel_gazelle//testtools:go_default_library",
86*60517a1eSAndroid Build Coastguard Worker        "@com_github_ghodss_yaml//:yaml",
87*60517a1eSAndroid Build Coastguard Worker        "@io_bazel_rules_go//go/runfiles:go_default_library",
88*60517a1eSAndroid Build Coastguard Worker        "@io_bazel_rules_go//go/tools/bazel:go_default_library",
89*60517a1eSAndroid Build Coastguard Worker    ],
90*60517a1eSAndroid Build Coastguard Worker)
91*60517a1eSAndroid Build Coastguard Worker
92*60517a1eSAndroid Build Coastguard Workergazelle_binary(
93*60517a1eSAndroid Build Coastguard Worker    name = "gazelle_binary",
94*60517a1eSAndroid Build Coastguard Worker    languages = [":python"],
95*60517a1eSAndroid Build Coastguard Worker    visibility = ["//visibility:public"],
96*60517a1eSAndroid Build Coastguard Worker)
97*60517a1eSAndroid Build Coastguard Worker
98*60517a1eSAndroid Build Coastguard Workerfilegroup(
99*60517a1eSAndroid Build Coastguard Worker    name = "distribution",
100*60517a1eSAndroid Build Coastguard Worker    srcs = glob(["**"]),
101*60517a1eSAndroid Build Coastguard Worker    visibility = ["//:__pkg__"],
102*60517a1eSAndroid Build Coastguard Worker)
103*60517a1eSAndroid Build Coastguard Worker
104*60517a1eSAndroid Build Coastguard Workergo_test(
105*60517a1eSAndroid Build Coastguard Worker    name = "default_test",
106*60517a1eSAndroid Build Coastguard Worker    srcs = [
107*60517a1eSAndroid Build Coastguard Worker        "file_parser_test.go",
108*60517a1eSAndroid Build Coastguard Worker        "std_modules_test.go",
109*60517a1eSAndroid Build Coastguard Worker    ],
110*60517a1eSAndroid Build Coastguard Worker    embed = [":python"],
111*60517a1eSAndroid Build Coastguard Worker    deps = [
112*60517a1eSAndroid Build Coastguard Worker        "@com_github_stretchr_testify//assert",
113*60517a1eSAndroid Build Coastguard Worker    ],
114*60517a1eSAndroid Build Coastguard Worker)
115