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

compile_commands.json generated by compdb has wrong command. #39

Open
WeiHe1991 opened this issue Jun 4, 2024 · 0 comments
Open

compile_commands.json generated by compdb has wrong command. #39

WeiHe1991 opened this issue Jun 4, 2024 · 0 comments

Comments

@WeiHe1991
Copy link

WeiHe1991 commented Jun 4, 2024

Hey! Here is a minimal reproducible example, where the compile_commands.json file generated by the tool compdb looks like:

[
    {
        "command": "/usr/bin/g++ -c -I . main.cc --std=c++11 -g3 -pipe -DDEBUG -Wall -Werror -fPIC",
        "directory": "<project_dir>/plz-out/gen",
        "file": "<project_dir>/main.cc"
    }
]

There are currently two issues:

Issue 1

In command, the path to the cc file is a relative one (main.cc in this case). This path, however, expands to <project_dir>/plz-out/gen/main.cc, which does not exist. If you run Clang tools such as clang-tidy against the source file, you'll get an error like:

clang-tidy main.cc               
Error while processing <project_dir>/main.cc.
error: no input files [clang-diagnostic-error]
error: no such file or directory: 'main.cc' [clang-diagnostic-error]
error: unable to handle compilation, expected exactly one compiler job in '' [clang-diagnostic-error]
Found compiler error(s).

IIUC this is due to please by design compiling each translation unit in a temporary directory plz-out/tmp/... using the source file copied into it, instead of the one in the source tree.

Issue 2

This command string is missing include paths. I would expect it to contain -isystem lib/include. Without it Clang tools won't work.

What I also noticed was that the query result from plz query graph (see attached file) is already missing include paths.
plz_query_graph.json

Is there already any workaround to mitigate this issue? If not, I would be happy to contribute.

@WeiHe1991 WeiHe1991 changed the title compile_commands.json generated by compdb contains stale paths. compile_commands.json generated by compdb has wrong command. Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant