-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBUILD
296 lines (268 loc) · 6.02 KB
/
BUILD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# cc_binary for simple C++ tests
load(
"@rules_cc//cc:defs.bzl",
"cc_binary",
"cc_library",
)
# compile_commands rule
load(
"@bazel_codechecker//src:compile_commands.bzl",
"compile_commands",
)
# codechecker rules
load(
"@bazel_codechecker//src:codechecker.bzl",
"codechecker",
"codechecker_config",
"codechecker_suite",
"codechecker_test",
)
# clang-tidy and clang -analyze rules
load(
"@bazel_codechecker//src:clang.bzl",
"clang_analyze_test",
"clang_tidy_test",
)
# clang -analyze + CTU rule
load(
"@bazel_codechecker//src:clang_ctu.bzl",
"clang_ctu_test",
)
# Prototype for CodeChecker analyze --file
# NOTE: CodeChecker analyze --file --ctu does not work
load(
"@bazel_codechecker//src:code_checker.bzl",
"code_checker_test",
)
# Test for strip_include_prefix
cc_library(
name = "test_inc",
hdrs = glob(["inc/*.h"]),
# NOTE: the following is for test purpose only
# NOTE: use includes instead of strip_include_prefix
strip_include_prefix = "inc",
)
# Test defect in transitive dependencies
cc_library(
name = "test_lib",
srcs = ["src/lib.cc"],
)
# Test defect in CTU mode
cc_library(
name = "test_ctu",
srcs = ["src/ctu.cc"],
)
# Simplest C++ test which should PASS
cc_binary(
name = "test_pass",
srcs = ["src/pass.cc"],
deps = ["test_inc"],
)
# Simplest C++ test which should FAIL
cc_binary(
name = "test_fail",
srcs = ["src/fail.cc"],
deps = [
"test_ctu",
"test_inc",
"test_lib",
],
)
# Generate compile_commands.json file for host test
compile_commands(
name = "compile_commands_pass",
targets = [
":test_pass",
],
)
# CodeChecker configuration options specification
# based on Bazel configuration approach
codechecker_config(
name = "codechecker_config",
analyze = [
"--disable=profile:default",
"--enable=core",
"--enable=bugprone-dangling-handle",
"--enable=bugprone-fold-init-type",
"--enable=misc-non-copyable-objects",
"--report-hash=context-free-v2",
],
# env = CODECHECKER_ENV,
parse = [
"--print-step",
],
)
# CodeChecker configuration file in JSON format
filegroup(
name = "codechecker_config_file",
srcs = [":config.json"],
)
# CodeChecker configuration options specification
# using JSON configuration file based approach,
# inherently supported by CodeChecker
codechecker_config(
name = "codechecker_config_json",
config_file = "codechecker_config_file",
)
# Simple codechecker rule - performs only "build" phase without "test"
codechecker(
name = "codechecker_pass_build",
config = "codechecker_config_json",
targets = [
"test_pass",
],
)
# Simplest codechecker_test example
# Runs CodeChecker on "test_pass" target
codechecker_test(
name = "codechecker_pass",
analyze = [
"--ctu",
"--stats",
],
config = "codechecker_config_json",
targets = [
"test_pass",
],
)
# This codechecker_test example supposed to fail showing findings report
# Note "manual" tag (means should not be run with other tests)
codechecker_test(
name = "codechecker_fail",
tags = [
"manual",
],
targets = [
"test_fail",
],
)
# This codechecker_test CTU example supposed to fail showing findings report
# Note "manual" tag (means should not be run with other tests)
codechecker_test(
name = "codechecker_ctu",
analyze = [
"--ctu",
],
tags = [
"manual",
],
targets = [
"test_fail",
],
)
# Simplest codechecker_suite example for "test_pass"
# Can run CodeChecker on targets built for different platforms
# This example performs build for just default platform i.e gcc
codechecker_suite(
name = "codechecker_pass_multi",
config = "codechecker_config_json",
# platforms = [
# "@platforms//os:linux",
# "@platforms//os:ios",
# "@platforms//os:android",
# ],
targets = [
"test_pass",
],
)
# This simple clang-tidy test should pass
clang_tidy_test(
name = "clang_tidy_pass",
targets = [
"test_pass",
],
)
# And this clang-tidy test should fail
# Note "manual" tag (means should not be run with other tests)
clang_tidy_test(
name = "clang_tidy_fail",
tags = [
"manual",
],
targets = [
"test_pass",
"test_fail",
],
)
# This simple clang -analyze test should pass
clang_analyze_test(
name = "clang_analyze_pass",
options = [
"-fno-color-diagnostics", # Example
# "-Xanalyzer -analyzer-disable-all-checks",
],
targets = [
"test_pass",
],
)
# And this clang -analyze test should fail
# Note "manual" tag (means should not be run with other tests)
clang_analyze_test(
name = "clang_analyze_fail",
tags = [
"manual",
],
targets = [
"test_pass",
"test_fail",
],
)
# This simple clang -analyze + CTU test should pass
clang_ctu_test(
name = "clang_ctu_pass",
targets = [
"test_pass",
],
)
# And this clang -analyze + CTU test should fail
# Note "manual" tag (means should not be run with other tests)
clang_ctu_test(
name = "clang_ctu_fail",
options = [
# "-fno-color-diagnostics", # Example
# "-Xanalyzer -analyzer-disable-all-checks",
],
tags = [
"manual",
],
targets = [
"test_pass",
"test_fail",
],
)
code_checker_test(
name = "code_checker_pass",
options = [
"--ctu",
"--stats",
],
targets = [
"test_pass",
],
)
code_checker_test(
name = "code_checker_fail",
tags = [
"manual",
],
targets = [
"test_pass",
"test_fail",
],
)
# FIXME: The following test does not detect CTU problem
# CodeChecker analyze --file --ctu does not work
code_checker_test(
name = "code_checker_ctu",
options = [
"--ctu",
"--stats",
],
tags = [
"manual",
],
targets = [
"test_pass",
"test_fail",
],
)