Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[analyzer] Handle relative file paths in compilation database #3587

Conversation

csordasmarton
Copy link
Contributor

Let's suppose that we have the following directory stucture:

|- .codechecker
  |- compilation_commands.json
  |- reports
|- main.cpp

And all the file paths in the compilation database are relative:

[
  {
    "file": "main.cpp",
    "command": "g++ -c main.cpp -o /dev/null",
    "directory": "."
  }
]

If we run the CodeChecker analyze command on this project, ClangSA analyzer
will generate a plist file where the file path will be relative to the directory
where the analyzer was called on.

After the plist files are produced, report converter will try to post-process these
files and creates absolute paths from the relative paths.

With this patch now we will create absolute paths based on the following values:

  • Current directory (os.getcwd()) where the CodeChecker command was executed.
  • The value of the directory key from the build action (in the example above it is .).
  • File path in the plist file.

If any of the above mentioned values are already absolute paths during the join it will
skip the previous values from the file path.

@csordasmarton csordasmarton added bugfix 🔨 analyzer 📈 Related to the analyze commands (analysis driver) labels Jan 27, 2022
@csordasmarton csordasmarton added this to the release 6.19.0 milestone Jan 27, 2022
Copy link
Contributor

@bruntib bruntib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch looks good.
In the meantime I was thinking how is it possible that a compilation_database.json contains relative directory paths. Probably it is possible with intercept-build or some other logger. This patch technically makes analysis possible with such a build log as input. However, it's important to know for the users that in this case analyzer should be executed in the same directory as the logger was run (i.e. that paths are relative to). This could be mentioned in some documentation.

Maybe here we could mention that CodeChecker supports analysis based on log files of other loggers, but in case of relative paths we should make sure that analysis is executed from the correct directory: https://github.com/Ericsson/codechecker/blob/master/docs/analyzer/user_guide.md#analyze-

Let's suppose that we have the following directory stucture:
```
|- .codechecker
  |- compilation_commands.json
  |- reports
|- main.cpp
```

And all the file paths in the compilation database are relative:
```json
[
  {
    "file": "main.cpp",
    "command": "g++ -c main.cpp -o /dev/null",
    "directory": "."
  }
]
```

If we run the `CodeChecker analyze` command on this project, ClangSA analyzer
will generate a plist file where the file path will be relative to the directory
where the analyzer was called on.

After the plist files are produced, report converter will try to post-process these
files and creates absolute paths from the relative paths.

With this patch now we will create absolute paths based on the following values:
- Current directory (`os.getcwd()`) where the CodeChecker command was executed.
- The value of the `directory` key from the build action (in the example above it is `.`).
- File path in the plist file.

If any of the above mentioned values are already absolute paths during the join it will
skip the previous values from the file path.
@csordasmarton csordasmarton merged commit f2beb60 into Ericsson:master Mar 1, 2022
@csordasmarton csordasmarton deleted the handle_relative_path_in_compilation_db branch April 7, 2022 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer 📈 Related to the analyze commands (analysis driver) bugfix 🔨
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants