Skip to content

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

Description

@WeiHe1991

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions