Skip to content

Commit 4c4c028

Browse files
authored
[clang-tidy][bazel][NFC] enable custom checks in bazel build (#160548)
1 parent 65363e6 commit 4c4c028

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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("@rules_cc//cc:defs.bzl", "cc_library")
6+
7+
package(
8+
default_visibility = ["//visibility:public"],
9+
features = ["layering_check"],
10+
)
11+
12+
licenses(["notice"])
13+
14+
cc_library(
15+
name = "lib",
16+
srcs = glob(["*.cpp"]),
17+
hdrs = glob(["*.h"]),
18+
deps = [
19+
"//clang:ast",
20+
"//clang:ast_matchers",
21+
"//clang:ast_matchers_dynamic",
22+
"//clang:basic",
23+
"//clang:frontend",
24+
"//clang:serialization",
25+
"//llvm:LineEditor",
26+
"//llvm:Support",
27+
],
28+
)

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,37 @@ bool_flag(
2323
build_setting_default = True,
2424
)
2525

26+
bool_flag(
27+
name = "enable_custom_checks",
28+
build_setting_default = True,
29+
)
30+
2631
config_setting(
2732
name = "static_analyzer_enabled",
2833
flag_values = {
2934
":enable_static_analyzer": "true",
3035
},
3136
)
3237

38+
config_setting(
39+
name = "custom_checks_enabled",
40+
flag_values = {
41+
":enable_custom_checks": "true",
42+
},
43+
)
44+
3345
expand_template(
3446
name = "config",
3547
out = "clang-tidy-config.h",
3648
substitutions =
37-
{
38-
"#cmakedefine01 CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS": "#define CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS 0",
39-
} | select({
49+
select({
50+
":custom_checks_enabled": {
51+
"#cmakedefine01 CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS": "#define CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS 1",
52+
},
53+
"//conditions:default": {
54+
"#cmakedefine01 CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS": "#define CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS 0",
55+
},
56+
}) | select({
4057
":static_analyzer_enabled": {
4158
"#cmakedefine01 CLANG_TIDY_ENABLE_STATIC_ANALYZER": "#define CLANG_TIDY_ENABLE_STATIC_ANALYZER 1",
4259
},
@@ -208,6 +225,15 @@ clang_tidy_library(
208225
],
209226
)
210227

228+
clang_tidy_library(
229+
name = "custom",
230+
deps = [
231+
":lib",
232+
"//clang:ast_matchers_dynamic",
233+
"//clang-tools-extra/clang-query:lib",
234+
],
235+
)
236+
211237
clang_tidy_library(
212238
name = "concurrency",
213239
deps = [":lib"],
@@ -365,6 +391,9 @@ CHECKS = [
365391
] + select({
366392
":static_analyzer_enabled": [":mpi"],
367393
"//conditions:default": [],
394+
}) + select({
395+
":custom_checks_enabled": [":custom"],
396+
"//conditions:default": [],
368397
})
369398

370399
cc_library(

0 commit comments

Comments
 (0)