Skip to content

Commit 02c6c1c

Browse files
authored
Add gazelle for bzl_library generation (#1132)
This makes it easier to keep these up to date. Also if we have conflicts with upstream we can just ignore those changes and re-run this afterwards
1 parent 5ad296f commit 02c6c1c

File tree

12 files changed

+156
-93
lines changed

12 files changed

+156
-93
lines changed

MODULE.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ apple_cc_configure = use_extension("@build_bazel_apple_support//crosstool:setup.
3232
use_repo(apple_cc_configure, "local_config_apple_cc")
3333

3434
# Dev dependencies
35+
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.5.0", dev_dependency = True)
36+
bazel_dep(name = "gazelle", version = "0.33.0", dev_dependency = True, repo_name = "bazel_gazelle")
3537
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")

WORKSPACE

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,20 @@ stardoc_external_deps()
5858
load("@stardoc_maven//:defs.bzl", stardoc_pinned_maven_install = "pinned_maven_install")
5959

6060
stardoc_pinned_maven_install()
61+
62+
http_archive(
63+
name = "bazel_skylib_gazelle_plugin",
64+
sha256 = "747addf3f508186234f6232674dd7786743efb8c68619aece5fb0cac97b8f415",
65+
urls = [
66+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-gazelle-plugin-1.5.0.tar.gz",
67+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-gazelle-plugin-1.5.0.tar.gz",
68+
],
69+
)
70+
71+
load("@bazel_skylib_gazelle_plugin//:workspace.bzl", "bazel_skylib_gazelle_plugin_workspace")
72+
73+
bazel_skylib_gazelle_plugin_workspace()
74+
75+
load("@bazel_skylib_gazelle_plugin//:setup.bzl", "bazel_skylib_gazelle_plugin_setup")
76+
77+
bazel_skylib_gazelle_plugin_setup()

doc/BUILD.bazel

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
load("@bazel_skylib//rules:write_file.bzl", "write_file")
1+
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
2+
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
23
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
4+
load("@bazel_skylib//rules:write_file.bzl", "write_file")
35
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
46

57
_DOC_SRCS = {
@@ -157,3 +159,25 @@ sh_binary(
157159
srcs = ["update.sh"],
158160
data = [file + ".md_" for file in _DOC_SRCS.keys() + ["setup"]],
159161
)
162+
163+
gazelle(
164+
name = "gazelle",
165+
gazelle = ":gazelle_bin",
166+
visibility = ["//visibility:private"],
167+
)
168+
169+
gazelle_binary(
170+
name = "gazelle_bin",
171+
languages = [
172+
"@bazel_skylib_gazelle_plugin//bzl",
173+
],
174+
visibility = ["//visibility:private"],
175+
)
176+
177+
# Have to keep since bazel doesn't propagate a bzl_library for these files
178+
# gazelle:ignore
179+
bzl_library(
180+
name = "bazel_tools_bzl",
181+
srcs = ["@bazel_tools//tools:bzl_srcs"],
182+
visibility = ["//swift:__pkg__"],
183+
)

examples/xplatform/swift_import/BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
12
load("//swift:swift.bzl", "swift_binary", "swift_import", "swift_library")
23
load(":get_swiftmodule.bzl", "get_swiftmodule")
34

@@ -31,3 +32,10 @@ swift_library(
3132
srcs = ["dep.swift"],
3233
module_name = "dep",
3334
)
35+
36+
bzl_library(
37+
name = "get_swiftmodule",
38+
srcs = ["get_swiftmodule.bzl"],
39+
visibility = ["//visibility:public"],
40+
deps = ["//swift"],
41+
)

swift/BUILD

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,11 @@ package(default_visibility = ["//visibility:public"])
1010

1111
licenses(["notice"])
1212

13-
bzl_library(
14-
name = "bazel_tools_bzl",
15-
srcs = ["@bazel_tools//tools:bzl_srcs"],
16-
)
17-
1813
bzl_library(
1914
name = "repositories",
2015
srcs = ["repositories.bzl"],
2116
deps = [
22-
":bazel_tools_bzl",
17+
"//doc:bazel_tools_bzl",
2318
"//swift/internal:swift_autoconfiguration",
2419
],
2520
)
@@ -55,7 +50,7 @@ bzl_library(
5550
deps = [
5651
":swift_compiler_plugin",
5752
"//swift/internal:providers",
58-
"//swift/internal:swift_binary_test",
53+
"//swift/internal:swift_binary_test_rules",
5954
"//swift/internal:swift_c_module",
6055
"//swift/internal:swift_common",
6156
"//swift/internal:swift_feature_allowlist",
@@ -152,3 +147,18 @@ filegroup(
152147
name = "empty",
153148
visibility = ["//visibility:private"],
154149
)
150+
151+
bzl_library(
152+
name = "extensions",
153+
srcs = ["extensions.bzl"],
154+
deps = [":repositories"],
155+
)
156+
157+
bzl_library(
158+
name = "extras",
159+
srcs = ["extras.bzl"],
160+
deps = [
161+
"@build_bazel_apple_support//lib:repositories",
162+
"@rules_proto//proto:repositories",
163+
],
164+
)

swift/internal/BUILD

Lines changed: 66 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,6 @@ bzl_library(
8787
deps = ["@bazel_skylib//lib:paths"],
8888
)
8989

90-
bzl_library(
91-
name = "env_expansion",
92-
srcs = ["env_expansion.bzl"],
93-
visibility = ["//swift:__subpackages__"],
94-
)
95-
9690
bzl_library(
9791
name = "features",
9892
srcs = ["features.bzl"],
@@ -124,11 +118,6 @@ bzl_library(
124118
deps = ["@bazel_skylib//lib:paths"],
125119
)
126120

127-
bzl_library(
128-
name = "package_specs",
129-
srcs = ["package_specs.bzl"],
130-
)
131-
132121
bzl_library(
133122
name = "proto_gen_utils",
134123
srcs = ["proto_gen_utils.bzl"],
@@ -175,24 +164,6 @@ bzl_library(
175164
],
176165
)
177166

178-
bzl_library(
179-
name = "swift_binary_test",
180-
srcs = ["swift_binary_test.bzl"],
181-
visibility = ["//swift:__subpackages__"],
182-
deps = [
183-
":compiling",
184-
":derived_files",
185-
":env_expansion",
186-
":feature_names",
187-
":linking",
188-
":providers",
189-
":swift_common",
190-
":utils",
191-
"@bazel_skylib//lib:dicts",
192-
"@bazel_skylib//lib:partial",
193-
],
194-
)
195-
196167
bzl_library(
197168
name = "swift_clang_module_aspect",
198169
srcs = ["swift_clang_module_aspect.bzl"],
@@ -369,12 +340,6 @@ bzl_library(
369340
],
370341
)
371342

372-
bzl_library(
373-
name = "transitions",
374-
srcs = ["transitions.bzl"],
375-
visibility = ["//swift:__subpackages__"],
376-
)
377-
378343
bzl_library(
379344
name = "utils",
380345
srcs = ["utils.bzl"],
@@ -404,29 +369,6 @@ bzl_library(
404369
],
405370
)
406371

407-
bzl_library(
408-
name = "explicit_module_map_file",
409-
srcs = ["explicit_module_map_file.bzl"],
410-
)
411-
412-
bzl_library(
413-
name = "feature_names",
414-
srcs = ["feature_names.bzl"],
415-
visibility = ["//swift:__subpackages__"],
416-
)
417-
418-
bzl_library(
419-
name = "vfsoverlay",
420-
srcs = ["vfsoverlay.bzl"],
421-
visibility = ["//swift:__subpackages__"],
422-
)
423-
424-
bzl_library(
425-
name = "build_settings",
426-
srcs = ["build_settings.bzl"],
427-
deps = ["@bazel_skylib//rules:common_settings"],
428-
)
429-
430372
# Indirection needed to prevent using `objc_library` outside of macOS
431373
alias(
432374
name = "swizzle_absolute_xcttestsourcelocation",
@@ -457,3 +399,69 @@ filegroup(
457399
"//swift:__pkg__",
458400
],
459401
)
402+
403+
bzl_library(
404+
name = "swift_binary_test_rules",
405+
srcs = ["swift_binary_test_rules.bzl"],
406+
visibility = ["//swift:__subpackages__"],
407+
deps = [
408+
":compiling",
409+
":derived_files",
410+
":env_expansion",
411+
":feature_names",
412+
":linking",
413+
":providers",
414+
":swift_common",
415+
":utils",
416+
"@bazel_skylib//lib:dicts",
417+
],
418+
)
419+
420+
bzl_library(
421+
name = "build_settings",
422+
srcs = ["build_settings.bzl"],
423+
visibility = ["//swift:__subpackages__"],
424+
deps = ["@bazel_skylib//rules:common_settings"],
425+
)
426+
427+
bzl_library(
428+
name = "env_expansion",
429+
srcs = ["env_expansion.bzl"],
430+
visibility = ["//swift:__subpackages__"],
431+
)
432+
433+
bzl_library(
434+
name = "explicit_module_map_file",
435+
srcs = ["explicit_module_map_file.bzl"],
436+
visibility = ["//swift:__subpackages__"],
437+
)
438+
439+
bzl_library(
440+
name = "feature_names",
441+
srcs = ["feature_names.bzl"],
442+
visibility = ["//swift:__subpackages__"],
443+
)
444+
445+
bzl_library(
446+
name = "package_specs",
447+
srcs = ["package_specs.bzl"],
448+
visibility = ["//swift:__subpackages__"],
449+
)
450+
451+
bzl_library(
452+
name = "target_triples",
453+
srcs = ["target_triples.bzl"],
454+
visibility = ["//swift:__subpackages__"],
455+
)
456+
457+
bzl_library(
458+
name = "transitions",
459+
srcs = ["transitions.bzl"],
460+
visibility = ["//swift:__subpackages__"],
461+
)
462+
463+
bzl_library(
464+
name = "vfsoverlay",
465+
srcs = ["vfsoverlay.bzl"],
466+
visibility = ["//swift:__subpackages__"],
467+
)

swift/swift.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ load(
3636
_SwiftUsageInfo = "SwiftUsageInfo",
3737
)
3838
load(
39-
"@build_bazel_rules_swift//swift/internal:swift_binary_test.bzl",
39+
"@build_bazel_rules_swift//swift/internal:swift_binary_test_rules.bzl",
4040
_swift_binary = "swift_binary",
4141
_swift_test = "swift_test",
4242
)

test/BUILD

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,15 @@ test_suite(
5858
name = "all_tests",
5959
)
6060

61-
bzl_library(
62-
name = "starlark_tests_bzls",
63-
srcs = glob(["*.bzl"]),
64-
deps = [
65-
"//test/fixtures:starlark_tests_bzls",
66-
"//test/rules:starlark_tests_bzls",
67-
],
68-
)
69-
7061
bzl_test(
7162
name = "swift_bzl_test",
7263
src = "swift_bzl_macro.bzl",
7364
deps = ["//swift"],
7465
)
66+
67+
bzl_library(
68+
name = "swift_bzl_macro",
69+
srcs = ["swift_bzl_macro.bzl"],
70+
visibility = ["//visibility:private"],
71+
deps = ["//swift"],
72+
)

test/fixtures/BUILD

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

3-
bzl_library(
4-
name = "starlark_tests_bzls",
5-
srcs = glob(["*.bzl"]),
6-
visibility = ["//test:__pkg__"],
7-
)
3+
package(default_visibility = ["//test:__subpackages__"])
84

95
bzl_library(
106
name = "common",
117
srcs = ["common.bzl"],
12-
visibility = ["//test:__pkg__"],
138
)

test/fixtures/linking/BUILD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
12
load("//swift:swift.bzl", "swift_binary", "swift_library")
23
load("//test/fixtures:common.bzl", "FIXTURE_TAGS")
34
load(":fake_framework.bzl", "fake_framework")
@@ -30,3 +31,9 @@ cc_binary(
3031
tags = FIXTURE_TAGS,
3132
deps = [":lib"],
3233
)
34+
35+
bzl_library(
36+
name = "fake_framework",
37+
srcs = ["fake_framework.bzl"],
38+
deps = ["@bazel_tools//tools/cpp:toolchain_utils.bzl"],
39+
)

test/rules/BUILD

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
22

3+
package(default_visibility = ["//test:__subpackages__"])
4+
35
bzl_library(
4-
name = "starlark_tests_bzls",
5-
srcs = glob(["*.bzl"]),
6-
visibility = [
7-
"//test:__pkg__",
8-
],
9-
deps = [
10-
"//swift",
11-
"@bazel_skylib//lib:collections",
12-
"@bazel_skylib//lib:types",
13-
"@bazel_skylib//lib:unittest",
14-
],
6+
name = "swift_library_artifact_collector",
7+
srcs = ["swift_library_artifact_collector.bzl"],
8+
deps = ["@build_bazel_rules_swift//swift"],
159
)
1610

1711
exports_files(["swift_shell_runner.sh.template"])

0 commit comments

Comments
 (0)