Ericsson / codechecker

CodeChecker is an analyzer tooling, defect database and viewer extension for the Clang Static Analyzer and Clang Tidy
https://codechecker.readthedocs.io
Apache License 2.0
2.23k stars 373 forks source link

[DRAFT] Support for relative paths in CodeChecker #4181

Open vodorok opened 7 months ago

vodorok commented 7 months ago

Certain tools (bazel) produce such an output, where absolute paths cannot be used in a cross-environment way. Absolute paths in the .plist output make the CodeChecker store and diff commands unusable as (for example the Bazel) cache folder prefixes would not allow the proper identification of the source files.

A dedicated flag should be added to the CodeChecker analyze command, which would enable the option of the use of relative paths during the whole CodeChecker workflow.

I propose the --use-relative-paths flag for the function mentioned above.

analyze:

When using the analyze command with a compilation command, that contains "."

The current implementation defines the meaning of the relative directory in the compilation database in the following way: If the "directory" is a "." CodeChecker will pass the current working directory to the exec() function call in the cwd parameter. Eg. the actual analysis command will be executed from the CodeChecker analysis invocation location.

_We had an issue with the passing of a filename with leading path elements in the –file option.

4180 Should fix the problem with the --file option._

When the --use-relative-paths flag is active, all of the paths should be considered, and resolvable from the original CodeChecker analyze invocation, in every output format.

Considering the following directory layout:

/home/proj/src/source.c
/home/proj/src/include/header.h
/home/proj/reports/
/home/proj/reports/proj.plist

Example .plist

…
  <key>files</key>
        <array>
                <string>./src/source.c</string>
                <string>./src/include/header.h</string>
        </array>
…

The paths in the .plist file should be relative to the CodeChecker invocation location.

parse, store, cmd, and server:

The support for relative paths should also be added to the report management command line (parse/store/cmd) utilities, and possibly to the server too.

Because the .plist contains paths to the source files relative to the CodeChecker analyze invocation location, the user must invoke the CodeChecker store|parse|cmd from the original invocation location of CodeChecker analyze

/ The command only works if/$CWD=/home/proj/
CodeChecker store home/proj/reports
dkrupp commented 6 months ago

Wouldn't it be better to resolve the relative paths to the location of the compile_commands.json (instead of the CodeChecker invocation dir) and the plist files?

The advantage would be that you could run the CodeChecker (analyze/parse) from any directory because the location of real files could be calculated from the location of the compile_commands.json and the plist files.