Debian Codegraph @

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

raw
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//rules:common_settings.bzl", "bool_flag")
6 load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
7 load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
8 load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
9 load("defs.bzl", "clang_tidy_library")
10
11 package(
12 default_visibility = ["//visibility:public"],
13 features = ["layering_check"],
14 )
15
16 licenses(["notice"])
17
18 # Include static analyzer checks in clang-tidy. Usage:
19 # $ bazel build --@llvm-project//clang-tools-extra/clang-tidy:enable_static_analyzer=true //...
20 # $ bazel build --@llvm-project//clang-tools-extra/clang-tidy:enable_static_analyzer=false //...
21 bool_flag(
22 name = "enable_static_analyzer",
23 build_setting_default = True,
24 )
25
26 bool_flag(
27 name = "enable_custom_checks",
28 build_setting_default = True,
29 )
30
31 config_setting(
32 name = "static_analyzer_enabled",
33 flag_values = {
34 ":enable_static_analyzer": "true",
35 },
36 )
37
38 config_setting(
39 name = "custom_checks_enabled",
40 flag_values = {
41 ":enable_custom_checks": "true",
42 },
43 )
44
45 expand_template(
46 name = "config",
47 out = "clang-tidy-config.h",
48 substitutions =
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({
57 ":static_analyzer_enabled": {
58 "#cmakedefine01 CLANG_TIDY_ENABLE_STATIC_ANALYZER": "#define CLANG_TIDY_ENABLE_STATIC_ANALYZER 1",
59 },
60 "//conditions:default": {
61 "#cmakedefine01 CLANG_TIDY_ENABLE_STATIC_ANALYZER": "#define CLANG_TIDY_ENABLE_STATIC_ANALYZER 0",
62 },
63 }),
64 template = "clang-tidy-config.h.cmake",
65 visibility = ["//visibility:private"],
66 )
67
68 cc_binary(
69 name = "confusable_table_builder",
70 srcs = ["misc/ConfusableTable/BuildConfusableTable.cpp"],
71 visibility = ["//visibility:private"],
72 deps = ["//llvm:Support"],
73 )
74
75 genrule(
76 name = "confusables_inc",
77 srcs = ["misc/ConfusableTable/confusables.txt"],
78 outs = ["Confusables.inc"],
79 cmd = "$(location :confusable_table_builder) $(SRCS) $(OUTS)",
80 tools = [":confusable_table_builder"],
81 visibility = ["//visibility:private"],
82 )
83
84 cc_library(
85 name = "confusables",
86 hdrs = [":confusables_inc"],
87 include_prefix = ".",
88 )
89
90 clang_tidy_library(
91 name = "lib",
92 srcs = glob(["*.cpp"]) + [":config"],
93 hdrs = glob(["*.h"]),
94 includes = ["."],
95 deps = [
96 "//clang:analysis",
97 "//clang:format",
98 "//clang:frontend_rewrite",
99 "//clang:rewrite",
100 "//clang:sema",
101 "//clang:serialization",
102 "//clang:static_analyzer_checkers_gen",
103 "//clang:tooling",
104 "//clang:tooling_core",
105 ] + select({
106 ":static_analyzer_enabled": [
107 "//clang:static_analyzer_core",
108 "//clang:static_analyzer_frontend",
109 ],
110 "//conditions:default": [],
111 }),
112 )
113
114 clang_tidy_library(
115 name = "misc",
116 deps = [
117 ":confusables",
118 ":lib",
119 ":utils",
120 "//clang:analysis",
121 "//clang:format",
122 "//clang:serialization",
123 "//clang:tooling",
124 "//clang:tooling_core",
125 "//clang:tooling_inclusions",
126 "//clang-tools-extra/include-cleaner:include_cleaner",
127 ],
128 )
129
130 clang_tidy_library(
131 name = "portability",
132 deps = [
133 ":lib",
134 "//llvm:TargetParser",
135 ],
136 )
137
138 clang_tidy_library(
139 name = "utils",
140 deps = [
141 ":lib",
142 "//clang:analysis",
143 "//clang:sema",
144 "//clang:tooling",
145 "//clang:transformer",
146 ],
147 )
148
149 clang_tidy_library(
150 name = "readability",
151 deps = [
152 ":lib",
153 ":utils",
154 "//clang:analysis",
155 "//clang:tooling",
156 ],
157 )
158
159 clang_tidy_library(
160 name = "google",
161 deps = [
162 ":lib",
163 ":misc",
164 ":modernize",
165 ":readability",
166 ":utils",
167 ],
168 )
169
170 clang_tidy_library(
171 name = "fuchsia",
172 deps = [
173 ":google",
174 ":lib",
175 ":misc",
176 ":utils",
177 ],
178 )
179
180 clang_tidy_library(
181 name = "llvm",
182 deps = [
183 ":lib",
184 ":readability",
185 ":utils",
186 "//clang:tooling",
187 "//clang:transformer",
188 ],
189 )
190
191 clang_tidy_library(
192 name = "llvmlibc",
193 deps = [
194 ":lib",
195 ":portability",
196 ":utils",
197 ],
198 )
199
200 clang_tidy_library(
201 name = "abseil",
202 deps = [
203 ":lib",
204 ":utils",
205 "//clang:analysis",
206 "//clang:tooling",
207 "//clang:transformer",
208 ],
209 )
210
211 clang_tidy_library(
212 name = "altera",
213 deps = [":lib"],
214 )
215
216 clang_tidy_library(
217 name = "android",
218 deps = [
219 ":lib",
220 ":utils",
221 ],
222 )
223
224 clang_tidy_library(
225 name = "boost",
226 deps = [
227 ":lib",
228 ":utils",
229 ],
230 )
231
232 clang_tidy_library(
233 name = "custom",
234 deps = [
235 ":lib",
236 "//clang:ast_matchers_dynamic",
237 "//clang-tools-extra/clang-query:lib",
238 ],
239 )
240
241 clang_tidy_library(
242 name = "concurrency",
243 deps = [":lib"],
244 )
245
246 clang_tidy_library(
247 name = "darwin",
248 deps = [":lib"],
249 )
250
251 clang_tidy_library(
252 name = "linuxkernel",
253 deps = [":lib"],
254 )
255
256 clang_tidy_library(
257 name = "modernize",
258 deps = [
259 ":lib",
260 ":utils",
261 "//clang:tooling",
262 ],
263 )
264
265 clang_tidy_library(
266 name = "mpi",
267 deps = [
268 ":lib",
269 "//clang:static_analyzer_checkers",
270 "//clang:static_analyzer_core",
271 "//clang:static_analyzer_frontend",
272 "//clang:tooling",
273 ],
274 )
275
276 clang_tidy_library(
277 name = "objc",
278 deps = [
279 ":lib",
280 ":utils",
281 ],
282 )
283
284 clang_tidy_library(
285 name = "openmp",
286 deps = [
287 ":lib",
288 ":utils",
289 ],
290 )
291
292 clang_tidy_library(
293 name = "zircon",
294 deps = [
295 ":fuchsia",
296 ":lib",
297 ":utils",
298 ],
299 )
300
301 clang_tidy_library(
302 name = "cppcoreguidelines",
303 deps = [
304 ":bugprone",
305 ":lib",
306 ":misc",
307 ":modernize",
308 ":performance",
309 ":readability",
310 ":utils",
311 "//clang:analysis",
312 ],
313 )
314
315 clang_tidy_library(
316 name = "bugprone",
317 deps = [
318 ":lib",
319 ":utils",
320 "//clang:analysis",
321 "//clang:sema",
322 "//clang:tooling",
323 "//clang:transformer",
324 ],
325 )
326
327 clang_tidy_library(
328 name = "performance",
329 deps = [
330 ":lib",
331 ":utils",
332 "//clang:analysis",
333 "//clang:tooling",
334 ],
335 )
336
337 clang_tidy_library(
338 name = "cert",
339 deps = [
340 ":bugprone",
341 ":concurrency",
342 ":google",
343 ":lib",
344 ":misc",
345 ":modernize",
346 ":performance",
347 ":readability",
348 ":utils",
349 ],
350 )
351
352 clang_tidy_library(
353 name = "hicpp",
354 deps = [
355 ":bugprone",
356 ":cppcoreguidelines",
357 ":google",
358 ":lib",
359 ":misc",
360 ":modernize",
361 ":performance",
362 ":readability",
363 ],
364 )
365
366 clang_tidy_library(
367 name = "plugin",
368 deps = [":lib"],
369 )
370
371 CHECKS = [
372 ":abseil",
373 ":altera",
374 ":android",
375 ":boost",
376 ":bugprone",
377 ":cert",
378 ":concurrency",
379 ":cppcoreguidelines",
380 ":darwin",
381 ":fuchsia",
382 ":google",
383 ":hicpp",
384 ":linuxkernel",
385 ":llvm",
386 ":llvmlibc",
387 ":misc",
388 ":modernize",
389 ":objc",
390 ":openmp",
391 ":performance",
392 ":portability",
393 ":readability",
394 ":zircon",
395 ] + select({
396 ":static_analyzer_enabled": [":mpi"],
397 "//conditions:default": [],
398 }) + select({
399 ":custom_checks_enabled": [":custom"],
400 "//conditions:default": [],
401 })
402
403 cc_library(
404 name = "tool",
405 srcs = ["tool/ClangTidyMain.cpp"],
406 hdrs = ["tool/ClangTidyMain.h"],
407 deps = CHECKS + [
408 ":lib",
409 ":utils",
410 "//clang:tooling",
411 "//llvm:Support",
412 "//llvm:TargetParser",
413 ],
414 )
415
416 cc_binary(
417 name = "clang-tidy",
418 srcs = ["tool/ClangTidyToolMain.cpp"],
419 stamp = 0,
420 deps = [":tool"],
421 )
422
423 native_binary(
424 name = "run-clang-tidy",
425 src = "tool/run-clang-tidy.py",
426 out = "run-clang-tidy",
427 data = [":clang-tidy"],
428 )