Skip to content

Commit 20913e2

Browse files
authored
Add gazelle for bzl_library generation (#612)
1 parent bbbacf4 commit 20913e2

12 files changed

Lines changed: 77 additions & 59 deletions

File tree

.bazelci/presubmit.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,12 @@ tasks:
172172
bazel: latest
173173
<<: *windows_common_toolchain_off
174174

175+
gazelle_check:
176+
name: "Gazelle up-to-date"
177+
platform: ubuntu2204
178+
bazel: latest
179+
shell_commands:
180+
- "bazel run //doc:gazelle"
181+
- "git diff --exit-code || { echo '::error::Gazelle-generated BUILD files are out of date. Run: bazel run //doc:gazelle'; exit 1; }"
182+
175183
buildifier: 8.5.1

BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ licenses(["notice"])
44

55
exports_files(["LICENSE"])
66

7+
# gazelle:exclude test
8+
# gazelle:exclude tools/http_dmg/private/tests
9+
# gazelle:exclude crosstool
10+
# gazelle:exclude toolchain
11+
712
# An umbrella bzl_library for anything that needs it (like to then use stardoc),
813
# but odds are using the specific sub bzl_library to with the public bzl files
914
# are a better choice to get the proper subset of dependencies.

MODULE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ register_toolchains("@local_config_apple_cc_toolchains//:all")
1919
xcode_configure = use_extension("//xcode:xcode_configure.bzl", "xcode_configure_extension")
2020
use_repo(xcode_configure, "local_config_xcode")
2121

22+
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.5.0", dev_dependency = True)
23+
bazel_dep(name = "gazelle", version = "0.46.0", dev_dependency = True)
24+
bazel_dep(name = "rules_go", version = "0.59.0", dev_dependency = True) # TODO: Remove when transitives update past this version
2225
bazel_dep(name = "rules_shell", version = "0.3.0", dev_dependency = True)
2326
bazel_dep(name = "stardoc", version = "0.8.0", dev_dependency = True)
2427

build_settings/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package(
88
licenses(["notice"])
99

1010
bzl_library(
11-
name = "build_settings_bzl",
11+
name = "build_settings",
1212
srcs = ["build_settings.bzl"],
1313
deps = ["@bazel_skylib//rules:common_settings"],
1414
)

configs/BUILD

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ selects.config_setting_group(
1010
cpu
1111
for cpu in APPLE_PLATFORMS_CONSTRAINTS.keys()
1212
] + [
13-
"@apple_support//constraints:apple",
13+
"//constraints:apple",
1414
],
1515
)
1616

@@ -35,5 +35,4 @@ selects.config_setting_group(
3535
bzl_library(
3636
name = "platforms",
3737
srcs = ["platforms.bzl"],
38-
visibility = ["//visibility:public"],
3938
)

doc/BUILD

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
22
load("@bazel_skylib//rules:write_file.bzl", "write_file")
3+
load("@gazelle//:def.bzl", "gazelle", "gazelle_binary")
34
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
45
load("@stardoc//stardoc:stardoc.bzl", "stardoc")
56

@@ -64,7 +65,7 @@ _DOC_SRCS = {
6465
symbol_names = symbols,
6566
tags = ["no-sandbox"], # https://github.com/bazelbuild/stardoc/issues/112
6667
deps = [
67-
"//rules",
68+
"//rules:rules.doc",
6869
"//xcode:providers",
6970
],
7071
)
@@ -113,3 +114,17 @@ sh_binary(
113114
srcs = ["update.sh"],
114115
data = [file + ".md_" for file in _DOC_SRCS.keys()],
115116
)
117+
118+
gazelle(
119+
name = "gazelle",
120+
gazelle = ":gazelle_bin",
121+
visibility = ["//visibility:private"],
122+
)
123+
124+
gazelle_binary(
125+
name = "gazelle_bin",
126+
languages = [
127+
"@bazel_skylib_gazelle_plugin//bzl",
128+
],
129+
visibility = ["//visibility:private"],
130+
)

lib/BUILD

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ bzl_library(
4949
],
5050
)
5151

52-
bzl_library(
53-
name = "missing_platform_fallback_users",
54-
srcs = ["missing_platform_fallback_users.bzl"],
55-
)
56-
5752
bzl_library(
5853
name = "lipo",
5954
srcs = ["lipo.bzl"],
@@ -63,14 +58,18 @@ bzl_library(
6358
],
6459
)
6560

66-
bzl_library(
67-
name = "transitions",
68-
srcs = ["transitions.bzl"],
69-
)
70-
71-
# Public bzl_library for anything that needs to depend on xcode_support.bzl.
7261
bzl_library(
7362
name = "xcode_support",
7463
srcs = ["xcode_support.bzl"],
7564
deps = ["//xcode:providers"],
7665
)
66+
67+
bzl_library(
68+
name = "missing_platform_fallback_users",
69+
srcs = ["missing_platform_fallback_users.bzl"],
70+
)
71+
72+
bzl_library(
73+
name = "transitions",
74+
srcs = ["transitions.bzl"],
75+
)

lib/private/BUILD

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
22

33
licenses(["notice"])
44

5-
package(
6-
default_visibility = ["//lib:__subpackages__"],
7-
)
5+
package(default_visibility = ["//:__subpackages__"])
86

97
bzl_library(
108
name = "providers",
119
srcs = ["providers.bzl"],
12-
visibility = [
13-
"//lib:__subpackages__",
14-
"//test:__pkg__",
15-
],
1610
)

rules/BUILD

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ bzl_library(
1717
],
1818
)
1919

20-
bzl_library(
21-
name = "toolchain_substitution",
22-
srcs = ["toolchain_substitution.bzl"],
23-
)
24-
2520
bzl_library(
2621
name = "universal_binary",
2722
srcs = ["universal_binary.bzl"],
@@ -33,11 +28,16 @@ bzl_library(
3328
)
3429

3530
bzl_library(
36-
name = "rules",
31+
name = "rules.doc",
3732
srcs = ["rules.doc.bzl"],
3833
deps = [
3934
":toolchain_substitution",
4035
":universal_binary",
4136
"//rules/private:apple_genrule",
4237
],
4338
)
39+
40+
bzl_library(
41+
name = "toolchain_substitution",
42+
srcs = ["toolchain_substitution.bzl"],
43+
)

tools/http_dmg/BUILD.bazel

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
22

3-
bzl_library(
4-
name = "bazel_tools_bzl",
5-
srcs = ["@bazel_tools//tools:bzl_srcs"],
6-
)
7-
83
bzl_library(
94
name = "http_dmg",
105
srcs = ["http_dmg.bzl"],
116
visibility = ["//visibility:public"],
127
deps = [
13-
":bazel_tools_bzl",
8+
"@bazel_tools//tools/build_defs/repo:utils.bzl",
149
],
1510
)

0 commit comments

Comments
 (0)