Skip to content

-MJ Compilation Database with a single file produces invalid json #155129

@FaultyPine

Description

@FaultyPine

Running clang with -MJ on my project, which uses a unity build file, produces the following (truncated for viewing ease) compile_commands.json.
{ "directory": "....", "file": "...", "output": "...", "arguments": [........] },
Note the trailing comma at the very end there, which breaks most json parsers, like nlohmann/json.
Though in general, the schema for this json is that there should be an array of these command objects, so really this should probably look like
[ { "directory": "....", ......, "arguments": [...] } ]
https://clang.llvm.org/docs/JSONCompilationDatabase.html
"A compilation database is a JSON file, which consist of an array of “command objects”"

Metadata

Metadata

Assignees

No one assigned

    Labels

    clangClang issues not falling into any other categoryquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions