Skip to content

Commit dbee53a

Browse files
authored
Update rules for clang-tidy and clang --analyze (#125)
Why: Bazel rules for clang-tidy and clang --analyze were never updated and never tested on real projects. What: - Collect sources and headers in transitive dependencies - Support platform transitions (for multi platform projects) - Simplify launcher scripts, bazelify parameters - Fix plist generation for clang --analyze - Support config file to accept input from a file_group - Remove clang-tidy aspect since it is not actually used - Minor cosmetic changes - Test on some of real Ericsson projects - Updated README
1 parent ddcd387 commit dbee53a

3 files changed

Lines changed: 122 additions & 156 deletions

File tree

README.md

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ The main Bazel rule for CodeChecker is `codechecker_test()`.
2121

2222
### Clang-tidy
2323

24-
Clang-tidy is a fast static analyzer/linter for the C family of languages. This
25-
repository provides Bazel aspect `clang_tidy_aspect()` and rule `clang_tidy_test()`
24+
Clang-tidy is a fast static analyzer/linter for the C family of languages.
25+
This repository provides Bazel rule `clang_tidy_test()`
2626
to run clang-tidy natively (without CodeChecker).
2727

2828
Find more information about LLVM clang-tidy:
@@ -313,9 +313,10 @@ codechecker_test(
313313

314314
The following rules are _not_ using CodeChecker.
315315

316-
### Clang-tidy: `clang_tidy_aspect()` and `clang_tidy_test()`
316+
### Clang-tidy: `clang_tidy_test()`
317317

318-
The Bazel rule `clang_tidy_test()` runs clang-tidy natively without CodeChecker. To use it, add the following to your BUILD file:
318+
The Bazel rule `clang_tidy_test()` runs clang-tidy natively without CodeChecker.
319+
To use it, add the following to your BUILD file:
319320

320321
```python
321322
load(
@@ -331,15 +332,11 @@ clang_tidy_test(
331332
)
332333
```
333334

334-
You can also run clang-tidy via the Bazel aspect `clang_tidy_aspect()` that can be invoked from the command line by passing the following parameter to Bazel build/test: `--aspects @codechecker_bazel//src:clang.bzl%clang_tidy_aspect`:
335-
336-
```bash
337-
bazel build ... --aspects @codechecker_bazel//src:clang.bzl%clang_tidy_aspect --output_groups=report
338-
```
339-
340335
### Clang Static Analyzer: `clang_analyze_test()`
341336

342-
The Bazel rule `clang_analyze_test()` runs The Clang Static Analyzer natively without CodeChecker. To use it, add the following to your BUILD file:
337+
The Bazel rule `clang_analyze_test()` runs The Clang Static Analyzer
338+
natively without CodeChecker.
339+
To use it, add the following to your BUILD file:
343340

344341
```python
345342
load(
@@ -355,6 +352,9 @@ clang_analyze_test(
355352
)
356353
```
357354

355+
> [!Note]
356+
> Currently `clang_analyze_test()` rule does not support CTU (Cross Translation Unit) analysis.
357+
358358
### Generating a compilation database: `compile_commands()`
359359

360360
As generating a compilation database for C/C++ is a known pain point for bazel, this repository defines the Bazel rule `compile_commands()` rule which can be used independently of CodeChecker. The implementation is based on https://github.com/grailbio/bazel-compilation-database with some fixes on some tricky edge cases. To use it, include the following in your BUILD file:
@@ -420,7 +420,3 @@ After that you can find all artifacts in `bazel-bin` directory:
420420

421421
# compile_commands.json for compile_commands_pass
422422
cat bazel-bin/test/compile_commands_pass/compile_commands.json
423-
424-
To run `clang_tidy_aspect()` on all C/C++ code:
425-
426-
bazel build ... --aspects @codechecker_bazel//src:clang.bzl%clang_tidy_aspect --output_groups=report

0 commit comments

Comments
 (0)