Skip to content

Commit 72c729f

Browse files
authored
[bazel] Add support for --incompatible_disallow_empty_glob (#85999)
This bazel flag, that should be flipped in an upcoming release bazelbuild/bazel#15327, fails if globs have no matches. This helps find libraries where you are accidentally not including files because of typos. This change removes the various globs that were not matching anything, and uncovered some targets that were doing nothing because their source files were deleted. There are a few cases where globs were intentionally optional in the case of loops that expanded to different potential options, so those now use `allow_empty = True`. This allows downstream consumers to also flip this flags for their own builds, where previously this would fail in LLVM instead. The downside to this change is that if files are added in these relatively standard locations, manual work will have to be done to add this patterns back. If folks prefer we could instead add `allow_empty = True` to every glob.
1 parent 527a624 commit 72c729f

File tree

9 files changed

+138
-428
lines changed

9 files changed

+138
-428
lines changed

utils/bazel/.bazelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ build --features=layering_check
3535
# See: https://bazel.build/reference/be/functions#exports_files
3636
build --incompatible_no_implicit_file_export
3737

38+
# Enable so downstream users can flip this flag globally, this should
39+
# eventually become the default
40+
common --incompatible_disallow_empty_glob
41+
3842
###############################################################################
3943
# Options to select different strategies for linking potential dependent
4044
# libraries. The default leaves it disabled.

utils/bazel/llvm-project-overlay/bolt/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,6 @@ cc_library(
221221
srcs = glob([
222222
"lib/Target/AArch64/*.cpp",
223223
]),
224-
hdrs = glob([
225-
]),
226224
includes = ["include"],
227225
deps = [
228226
":Core",

utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/defs.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ _common_library_deps = [
1616
]
1717

1818
def clang_tidy_library(name, **kwargs):
19-
kwargs["srcs"] = kwargs.get("srcs", native.glob([paths.join(name, "*.cpp")]))
20-
kwargs["hdrs"] = kwargs.get("hdrs", native.glob([paths.join(name, "*.h")]))
19+
kwargs["srcs"] = kwargs.get("srcs", native.glob([paths.join(name, "*.cpp")], allow_empty = True))
20+
kwargs["hdrs"] = kwargs.get("hdrs", native.glob([paths.join(name, "*.h")], allow_empty=True))
2121
kwargs["deps"] = kwargs.get("deps", []) + _common_library_deps
2222
cc_library(
2323
name = name,

utils/bazel/llvm-project-overlay/clang/BUILD.bazel

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,6 @@ cc_library(
614614
"include/clang/Basic/Version.inc",
615615
] + glob([
616616
"lib/Basic/*.cpp",
617-
"lib/Basic/*.c",
618617
"lib/Basic/*.h",
619618
"lib/Basic/Targets/*.cpp",
620619
"lib/Basic/Targets/*.h",
@@ -1042,7 +1041,6 @@ cc_library(
10421041
"lib/Analysis/FlowSensitive/Models/*.cpp",
10431042
"lib/Analysis/FlowSensitive/*.cpp",
10441043
"lib/Analysis/*.cpp",
1045-
"lib/Analysis/*.h",
10461044
]) + [
10471045
":analysis_htmllogger_gen",
10481046
],
@@ -1180,10 +1178,8 @@ gentbl(
11801178

11811179
cc_library(
11821180
name = "parse",
1183-
srcs = [
1184-
] + glob([
1181+
srcs = glob([
11851182
"lib/Parse/*.cpp",
1186-
"lib/Parse/*.h",
11871183
]),
11881184
hdrs = [
11891185
"include/clang/Parse/AttrParserStringSwitches.inc",
@@ -1207,7 +1203,6 @@ cc_library(
12071203
name = "ast_matchers",
12081204
srcs = glob([
12091205
"lib/ASTMatchers/*.cpp",
1210-
"lib/ASTMatchers/*.h",
12111206
]),
12121207
hdrs = glob(["include/clang/ASTMatchers/*.h"]),
12131208
includes = ["include"],
@@ -1241,7 +1236,6 @@ cc_library(
12411236
name = "rewrite",
12421237
srcs = glob([
12431238
"lib/Rewrite/*.cpp",
1244-
"lib/Rewrite/*.h",
12451239
]),
12461240
hdrs = glob(["include/clang/Rewrite/Core/*.h"]),
12471241
includes = ["include"],
@@ -1275,7 +1269,6 @@ cc_library(
12751269
name = "tooling_core",
12761270
srcs = glob([
12771271
"lib/Tooling/Core/*.cpp",
1278-
"lib/Tooling/Core/*.h",
12791272
]),
12801273
hdrs = glob(["include/clang/Tooling/Core/*.h"]),
12811274
includes = ["include"],
@@ -1340,11 +1333,9 @@ cc_library(
13401333
name = "tooling_refactoring",
13411334
srcs = glob([
13421335
"lib/Tooling/Refactoring/**/*.cpp",
1343-
"lib/Tooling/Refactoring/**/*.h",
13441336
]),
13451337
hdrs = glob([
13461338
"include/clang/Tooling/Refactoring/**/*.h",
1347-
"include/clang/Tooling/Refactoring/**/*.def",
13481339
]),
13491340
deps = [
13501341
":ast",
@@ -1593,9 +1584,6 @@ cc_library(
15931584
srcs = glob(
15941585
[
15951586
"lib/Driver/*.cpp",
1596-
"lib/Driver/*.h",
1597-
"lib/Driver/Arch/*.cpp",
1598-
"lib/Driver/Arch/*.h",
15991587
"lib/Driver/ToolChains/*.cpp",
16001588
"lib/Driver/ToolChains/*.h",
16011589
"lib/Driver/ToolChains/Arch/*.cpp",
@@ -1833,9 +1821,6 @@ cc_library(
18331821
copts = ["$(STACK_FRAME_UNLIMITED)"],
18341822
data = [":builtin_headers_gen"],
18351823
includes = ["include"],
1836-
textual_hdrs = glob([
1837-
"include/clang/Frontend/*.def",
1838-
]),
18391824
deps = [
18401825
":apinotes",
18411826
":ast",
@@ -1872,7 +1857,6 @@ cc_library(
18721857
name = "frontend_rewrite",
18731858
srcs = glob([
18741859
"lib/Frontend/Rewrite/*.cpp",
1875-
"lib/Frontend/Rewrite/*.h",
18761860
]),
18771861
hdrs = glob(["include/clang/Rewrite/Frontend/*.h"]),
18781862
includes = ["include"],
@@ -2116,7 +2100,6 @@ cc_library(
21162100
name = "frontend_tool",
21172101
srcs = glob([
21182102
"lib/FrontendTool/*.cpp",
2119-
"lib/FrontendTool/*.h",
21202103
]),
21212104
hdrs = glob(["include/clang/FrontendTool/*.h"]),
21222105
includes = ["include"],
@@ -2320,7 +2303,6 @@ cc_binary(
23202303
testonly = 1,
23212304
srcs = glob([
23222305
"tools/clang-import-test/*.cpp",
2323-
"tools/clang-import-test/*.h",
23242306
]),
23252307
stamp = 0,
23262308
deps = [
@@ -2350,7 +2332,6 @@ cc_library(
23502332
name = "clang-driver",
23512333
srcs = glob([
23522334
"tools/driver/*.cpp",
2353-
"tools/driver/*.h",
23542335
]) + ["clang-driver.cpp"],
23552336
copts = [
23562337
# Disable stack frame size checks in the driver because
@@ -2668,7 +2649,6 @@ cc_library(
26682649
name = "extract_api",
26692650
srcs = glob([
26702651
"lib/ExtractAPI/**/*.cpp",
2671-
"lib/ExtractAPI/**/*.h",
26722652
]),
26732653
hdrs = glob(["include/clang/ExtractAPI/**/*.h"]),
26742654
includes = ["include"],

utils/bazel/llvm-project-overlay/lld/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ cc_library(
187187
name = "MinGW",
188188
srcs = glob([
189189
"MinGW/*.cpp",
190-
"MinGW/*.h",
191190
]),
192191
includes = ["MinGW"],
193192
deps = [
@@ -296,7 +295,6 @@ cc_binary(
296295
name = "lld",
297296
srcs = glob([
298297
"tools/lld/*.cpp",
299-
"tools/lld/*.h",
300298
]) + ["lld-driver.cpp"],
301299
deps = [
302300
":COFF",

0 commit comments

Comments
 (0)