Skip to content

Generate a ninja build for running static analysis

License

Notifications You must be signed in to change notification settings

sztomi/sa_ninja_gen

Repository files navigation

sa_ninja_gen

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.

⚠️ This is a work in progress ⚠️

Usage

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-mapping command
  • Both commands from this crate: sa_ninja_gen and merge_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.ninja

The output directory will hold all intermediate files as well as the results of the analysis.

Using merge_extdefs independently

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.

Environment variables

The following environment variables can be used to influence the behavior of sa_ninja_gen:

  • CLANG_EXTDEF_MAPPING: the clang-extdef-mapping binary to use
  • MERGE_EXTDEFS: the merge_extdefs binary to use (this command is supplied by this project)

Acknowledgments

About

Generate a ninja build for running static analysis

Resources

License

Stars

Watchers

Forks

Packages

No packages published