This program generates a ninja build from compile_commands.json that can be used to run the clang static analyzer (with or without CTU) and clang-tidy.
You will need:
- A compilation database (compile_commands.json). Some build systems, like CMake, will generate this for you, but for others you may need to use a tool like Bear.
clang-extdef-mappingcommand- Both commands from this crate:
sa_ninja_genandmerge_extdefs
Most typically, you will want to run this in your build directory, after a build was executed, because many builds will generate files that are required but aren't listed in the compilation database.
A typical invocation will look like this:
$ sa_ninja_gen --ctu -o ./sa-output compile_commands.json sa.ninja
$ ninja -f sa.ninjaThe output directory will hold all intermediate files as well as the results of the analysis.
merge_extdefs is a separate command that can be used independently from sa_ninja_gen. The
invocation is simple:
$ merge_extdefs [file1...fileN] [output_file]
# or
$ merge_extdefs @responsefile.txt [output_file]The second form allows passing a text file that contains arguments separated by space or newline characters. This might be useful on Windows where there is a limitation on the number of characters that can be passed on the command line. You can supply multiple response files and ordinary input files in the same invocation, in any order.
Note: merge_extdefs will keep only one definition of a given symbol. It is possible that there are
duplicates despite not violating the One Definition Rule. This is because your project may compile
identical sources in different targets. There is no information in the compilation database about
targets, so there is currently no way to detect this situation. In practice, you will still get most
diagnostics, but some may be missing in fringe cases.
The following environment variables can be used to influence the behavior of sa_ninja_gen:
CLANG_EXTDEF_MAPPING: theclang-extdef-mappingbinary to useMERGE_EXTDEFS: themerge_extdefsbinary to use (this command is supplied by this project)
- The
ninja_syntaxcrate is heavily based on Tobias Hieta's excellent ninja-syntax port (used with permission)