Skip to content

clangsa-sast: add include-directory rebasing to cdb-rebase

Problem to solve

When a CDB is generated in one place for use in another, it is often more than the directory entry of each command that needs changing. E.g. -I /usr/local/include/some_lib might become -I system_includes/some_lib.

Proposal

Add the ability to detect included directories outside of the source project, copy to the destination project, and update commands.

The command invocation in a compilation database can be represented as a list of arguments or as a string command. Both should be handled

  • update the CLI
    • add an include-cache, -c, flag with a default value of include-cache that must be relative
    • add an include, -I option for include paths that are not automatically detected, but must be copied into the include-cache
    • add an extra-argument, -X that appends the argument to the end of every build command
    • add an exclude, -e flag that takes a glob pattern for paths that should be skipped during the copy into the include cache.
  • parse the command form of arguments into a []string, e.g. using shellparse
  • for each argument -I followed by an include path or -I<include-path> (or variations like -isystem)
    • detect if an include path needs rewriting, i.e. because it is absolute or outside of the project directory
    • apply the rewrites and update the CDB object
  • test
    • add unit tests of CDBs with both absolute and relative includes outside the source directory. The absolute paths can be dynamically created in the test.
    • add a fixture that uses an include directory outside its project directory integration-test is meant for use with a before_script operation like cdb-rebase.
Edited by Jason Leasure