Skip to content

Commit 20d9ca9

Browse files
committed
[clang-tidy][bazel] Include builtin headers with clang-tidy
1 parent 0f339e6 commit 20d9ca9

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
load("//:vars.bzl", "LLVM_VERSION_MAJOR")
6+
load("//clang:defs.bzl", "BUILTIN_HEADERS_GEN_DIR")
7+
load("defs.bzl", "symlink")
8+
9+
package(
10+
default_visibility = ["//visibility:public"],
11+
features = ["layering_check"],
12+
)
13+
14+
licenses(["notice"])
15+
16+
symlink(
17+
name = "builtin_headers",
18+
srcs = ["//clang:builtin_headers_gen"],
19+
destination = "lib/clang/{0}/include".format(LLVM_VERSION_MAJOR),
20+
partition = BUILTIN_HEADERS_GEN_DIR,
21+
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ cc_library(
370370
cc_binary(
371371
name = "clang-tidy",
372372
srcs = ["tool/ClangTidyToolMain.cpp"],
373+
data = ["//clang-tools-extra:builtin_headers"],
373374
stamp = 0,
374375
deps = [":tool"],
375376
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
load("@bazel_skylib//lib:paths.bzl", "paths")
6+
7+
def _symlink_impl(ctx):
8+
copied_files = []
9+
for input_file in ctx.files.srcs:
10+
(_, _, relative_filename) = input_file.path.rpartition(ctx.attr.partition)
11+
output_file = ctx.actions.declare_file(paths.join(ctx.attr.destination, relative_filename))
12+
ctx.actions.symlink(
13+
target_file = input_file,
14+
output = output_file,
15+
)
16+
copied_files.append(output_file)
17+
return DefaultInfo(files = depset(copied_files))
18+
19+
symlink = rule(
20+
implementation = _symlink_impl,
21+
attrs = {
22+
"destination": attr.string(mandatory = True),
23+
"partition": attr.string(mandatory = True),
24+
"srcs": attr.label_list(allow_files = True),
25+
},
26+
)

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ load(
1414
"LLVM_VERSION_MINOR",
1515
"LLVM_VERSION_PATCH",
1616
)
17+
load("defs.bzl", "BUILTIN_HEADERS_GEN_DIR")
1718

1819
package(
1920
default_visibility = ["//visibility:public"],
@@ -1696,14 +1697,17 @@ builtin_headers = glob(
16961697
genrule(
16971698
name = "builtin_headers_gen",
16981699
srcs = builtin_headers,
1699-
outs = [hdr.replace("lib/Headers/", "staging/include/") for hdr in builtin_headers],
1700+
outs = [
1701+
header.replace("lib/Headers/", BUILTIN_HEADERS_GEN_DIR)
1702+
for header in builtin_headers
1703+
],
17001704
cmd = """
17011705
for src in $(SRCS); do
1702-
relsrc=$${src#*"$(WORKSPACE_ROOT)"/clang/lib/Headers}
1703-
target=$(@D)/staging/include/$$relsrc
1706+
relsrc=$${{src#*"$(WORKSPACE_ROOT)"/clang/lib/Headers}}
1707+
target=$(@D)/{resource_dir}$$relsrc
17041708
mkdir -p $$(dirname $$target)
17051709
cp $$src $$target
1706-
done""",
1710+
done""".format(resource_dir = BUILTIN_HEADERS_GEN_DIR),
17071711
output_to_bindir = 1,
17081712
toolchains = [
17091713
":workspace_root",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
BUILTIN_HEADERS_GEN_DIR = "staging/include/"

0 commit comments

Comments
 (0)