title |
---|
Clang-tidy' |
Clang-tidy is the static-analyhsis tool associated with Clang. Clang is a C/C++ compiler that uses the LLVM framework for optimization. It is open-source software available under a permissive license{.extlink}. You can read more about Clang at its project page: https://clang-analyzer.llvm.org/{.extlink}
Clang-tidy can be run from the command-line. It can produce output in the format similar to compiler error messages...These should be piped to a file.
You will want to create a compile_commands.json
file, and the easiest
way to do this is to use the bear
command with your build process.
If your project is built using a make build
command, then you can
do:
bear make build
You must then procure all the source files. This could be done with a grep command and some judicious text editing:
grep '"file"' compile_commands.json
Once this is done, you can run clang-tidy on the sources:
clang-tidy -checks='*' ${SOURCE} > clang-tidy.txt
Note that clang-tidy will reference the compile_commands.json
file for compilation details if the file exists, even if you don't specify it on the command line. So you will get better results if you create it before running clang-
tidy.
If you want to run clang-tidy only on source files in the compile_commands.json
file, you could use this command:
grep --color=none '"file":' compile_commands.json | sed 's/"file"://; s/",/"/;' | sort -u | xargs clang-tidy -checks='*' > clang-tidy.txt