Import of compile_database.json where file is missing.
IAR Export of compile_database.json contains information about the linking step.
The format of this entry is.
{ "arguments": ["FOO"] "directory": "BAR" "files": ["BAZ"] "type": "LINKER" }
CppCheck fails with "ICOJSON_ASSERT("type mismatch! call is
Ignore entries where "file" is not provided. The parsing should probably be improved to only include entries where type="COMPILER".
Thanks for your contribution!
Is there some documentation about this? I do not see type or files mentioned at https://clang.llvm.org/docs/JSONCompilationDatabase.html. The documentation there is also not clear if file is actually required.
Is clang-tidy properly handling these files?
Also please add a testcase for this in test/cli/test-more-projects.py.
I did a quick check and it seems this is an extremely new feature to IAR and it seems the generated files do not work as intended with other tools and need to be modified to be usable - see https://stackoverflow.com/questions/58353422/how-to-convert-iar-ewp-to-lsp-compile-commands-json-database#comment122968363_58353422. This might actually be an issue with IAR and not with Cppcheck.
The format is defined here. https://wwwfiles.iar.com/riscv/EWRISCV_IDEGuide.pdf Page 122
-jsondb
Generates a JSON description of the project. The format is based on the compiler
database format but also contains the linking, custom, and conversion steps of the build.
Optionally, you can specify the -output option to name the output file, and the -tool
option to run a tool or set of tools. By default, the output is generated in the file
$PROJ_DIR$/config/project_jsondb.json.
The database contains entries on how to build the project on the format:
[
{
"arguments" : [ Comma-separated list of arguments],
"directory" : "The directory in which to perform the
action",
"file" : "The input file",
"output" : "The output file",
"type" : "Name of the tool"
}
]
In case of multiple inputs or multiple outputs, the "output" or "file" tag is replaced by "outputs" or "files" followed by a comma-separated list of the files:
[
{
"arguments" : [ Comma-separated list of arguments],
"directory" : "The directory in which to perform the
action",
"files" : [Comma-separated list of files],
"outputs" : [Comma-separated list of files],
"type" : "Name of the tool"
}
]
But you are right. It seems to be against the specs on https://clang.llvm.org/docs/JSONCompilationDatabase.html which says there MUST be a "file" field.
But you are right. It seems to be against the specs on https://clang.llvm.org/docs/JSONCompilationDatabase.html which says there MUST be a "file" field.
well.. the difference seems to be by design so then it's reasonable to support that in Cppcheck.
In case of multiple inputs or multiple outputs, the "output" or "file" tag is replaced by "outputs" or "files" followed by a comma-separated list of the files:
That's straight forward and reasonable to add. So let's do this right now and look for file first with obj.find() and with fallback to files. Store that in a container and just put the code below in a loop. And please add tests and comments in the code for that. We should also document that we support the "standard" and the IAR version of the compilation database (with links to the documentation).
"files" : [Comma-separated list of files],
I hope that just means it's a JSON array.
I still wonder how clang-tidy handles those.