Skip to content

Commit

Permalink
[bazel] Add support for --incompatible_disallow_empty_glob (llvm#85999)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
keith authored and chencha3 committed Mar 22, 2024
1 parent c4d5141 commit 35d6851
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 428 deletions.
4 changes: 4 additions & 0 deletions utils/bazel/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ build --features=layering_check
# See: https://bazel.build/reference/be/functions#exports_files
build --incompatible_no_implicit_file_export

# Enable so downstream users can flip this flag globally, this should
# eventually become the default
common --incompatible_disallow_empty_glob

###############################################################################
# Options to select different strategies for linking potential dependent
# libraries. The default leaves it disabled.
Expand Down
2 changes: 0 additions & 2 deletions utils/bazel/llvm-project-overlay/bolt/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,6 @@ cc_library(
srcs = glob([
"lib/Target/AArch64/*.cpp",
]),
hdrs = glob([
]),
includes = ["include"],
deps = [
":Core",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ _common_library_deps = [
]

def clang_tidy_library(name, **kwargs):
kwargs["srcs"] = kwargs.get("srcs", native.glob([paths.join(name, "*.cpp")]))
kwargs["hdrs"] = kwargs.get("hdrs", native.glob([paths.join(name, "*.h")]))
kwargs["srcs"] = kwargs.get("srcs", native.glob([paths.join(name, "*.cpp")], allow_empty = True))
kwargs["hdrs"] = kwargs.get("hdrs", native.glob([paths.join(name, "*.h")], allow_empty=True))
kwargs["deps"] = kwargs.get("deps", []) + _common_library_deps
cc_library(
name = name,
Expand Down
22 changes: 1 addition & 21 deletions utils/bazel/llvm-project-overlay/clang/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,6 @@ cc_library(
"include/clang/Basic/Version.inc",
] + glob([
"lib/Basic/*.cpp",
"lib/Basic/*.c",
"lib/Basic/*.h",
"lib/Basic/Targets/*.cpp",
"lib/Basic/Targets/*.h",
Expand Down Expand Up @@ -1042,7 +1041,6 @@ cc_library(
"lib/Analysis/FlowSensitive/Models/*.cpp",
"lib/Analysis/FlowSensitive/*.cpp",
"lib/Analysis/*.cpp",
"lib/Analysis/*.h",
]) + [
":analysis_htmllogger_gen",
],
Expand Down Expand Up @@ -1180,10 +1178,8 @@ gentbl(

cc_library(
name = "parse",
srcs = [
] + glob([
srcs = glob([
"lib/Parse/*.cpp",
"lib/Parse/*.h",
]),
hdrs = [
"include/clang/Parse/AttrParserStringSwitches.inc",
Expand All @@ -1207,7 +1203,6 @@ cc_library(
name = "ast_matchers",
srcs = glob([
"lib/ASTMatchers/*.cpp",
"lib/ASTMatchers/*.h",
]),
hdrs = glob(["include/clang/ASTMatchers/*.h"]),
includes = ["include"],
Expand Down Expand Up @@ -1241,7 +1236,6 @@ cc_library(
name = "rewrite",
srcs = glob([
"lib/Rewrite/*.cpp",
"lib/Rewrite/*.h",
]),
hdrs = glob(["include/clang/Rewrite/Core/*.h"]),
includes = ["include"],
Expand Down Expand Up @@ -1275,7 +1269,6 @@ cc_library(
name = "tooling_core",
srcs = glob([
"lib/Tooling/Core/*.cpp",
"lib/Tooling/Core/*.h",
]),
hdrs = glob(["include/clang/Tooling/Core/*.h"]),
includes = ["include"],
Expand Down Expand Up @@ -1340,11 +1333,9 @@ cc_library(
name = "tooling_refactoring",
srcs = glob([
"lib/Tooling/Refactoring/**/*.cpp",
"lib/Tooling/Refactoring/**/*.h",
]),
hdrs = glob([
"include/clang/Tooling/Refactoring/**/*.h",
"include/clang/Tooling/Refactoring/**/*.def",
]),
deps = [
":ast",
Expand Down Expand Up @@ -1593,9 +1584,6 @@ cc_library(
srcs = glob(
[
"lib/Driver/*.cpp",
"lib/Driver/*.h",
"lib/Driver/Arch/*.cpp",
"lib/Driver/Arch/*.h",
"lib/Driver/ToolChains/*.cpp",
"lib/Driver/ToolChains/*.h",
"lib/Driver/ToolChains/Arch/*.cpp",
Expand Down Expand Up @@ -1833,9 +1821,6 @@ cc_library(
copts = ["$(STACK_FRAME_UNLIMITED)"],
data = [":builtin_headers_gen"],
includes = ["include"],
textual_hdrs = glob([
"include/clang/Frontend/*.def",
]),
deps = [
":apinotes",
":ast",
Expand Down Expand Up @@ -1872,7 +1857,6 @@ cc_library(
name = "frontend_rewrite",
srcs = glob([
"lib/Frontend/Rewrite/*.cpp",
"lib/Frontend/Rewrite/*.h",
]),
hdrs = glob(["include/clang/Rewrite/Frontend/*.h"]),
includes = ["include"],
Expand Down Expand Up @@ -2116,7 +2100,6 @@ cc_library(
name = "frontend_tool",
srcs = glob([
"lib/FrontendTool/*.cpp",
"lib/FrontendTool/*.h",
]),
hdrs = glob(["include/clang/FrontendTool/*.h"]),
includes = ["include"],
Expand Down Expand Up @@ -2320,7 +2303,6 @@ cc_binary(
testonly = 1,
srcs = glob([
"tools/clang-import-test/*.cpp",
"tools/clang-import-test/*.h",
]),
stamp = 0,
deps = [
Expand Down Expand Up @@ -2350,7 +2332,6 @@ cc_library(
name = "clang-driver",
srcs = glob([
"tools/driver/*.cpp",
"tools/driver/*.h",
]) + ["clang-driver.cpp"],
copts = [
# Disable stack frame size checks in the driver because
Expand Down Expand Up @@ -2668,7 +2649,6 @@ cc_library(
name = "extract_api",
srcs = glob([
"lib/ExtractAPI/**/*.cpp",
"lib/ExtractAPI/**/*.h",
]),
hdrs = glob(["include/clang/ExtractAPI/**/*.h"]),
includes = ["include"],
Expand Down
2 changes: 0 additions & 2 deletions utils/bazel/llvm-project-overlay/lld/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ cc_library(
name = "MinGW",
srcs = glob([
"MinGW/*.cpp",
"MinGW/*.h",
]),
includes = ["MinGW"],
deps = [
Expand Down Expand Up @@ -296,7 +295,6 @@ cc_binary(
name = "lld",
srcs = glob([
"tools/lld/*.cpp",
"tools/lld/*.h",
]) + ["lld-driver.cpp"],
deps = [
":COFF",
Expand Down
Loading

0 comments on commit 35d6851

Please sign in to comment.