Different compile_commands.json for clangd/sonar-scanner

Hi,

Since the build-wrapper is no longer supported, we’re using sonar-scanner to analyze our C++ Xcode project.
As described we create our compile_commands.json via

xcodebuild ...  OTHER_CFLAGS="\$(inherited) -gen-cdb-fragment-path \$(PROJECT_DIR)/CompilationDatabase"

followed by this sed expression

sed -e '1s/^/[\'$'\n''/' -e '$s/,$/\'$'\n'']/' ...

And this works fine for sonar-scanner. That is if you perform an additional compilation w/o the OTHER_CFLAGS option and thus require two compilations for every analysis.

However, clangd (e.g. used in VS Code / clang-tidy) has problems with this file.
For clangd I need to create the compile_commands.json via xcpretty:

xcodebuild ...  | xcpretty -r json-compilation-database -o build/compile_commands.json

Can anyone tell me what the difference is between these approaches? Ideally, we could use the same compile_commands.json for both purposes. It would be even better if sonar-scanner could process the xcpretty version, because this doesn’t require an additional compilation.

Hi @Winfried_Auner,

Since the build-wrapper is no longer supported, we’re using sonar-scanner to analyze our C++ Xcode project.

FYI, support of build-wrapper was reintroduced and is gonna be part of SonarQube 10.2: [CPP-3987] - Jira

We don’t mind how you generate the compilation database as long as it is reliable and accurate; It should represent your actual compilation command. Also, if you execute the command from directory entry on the file entry it should successfully compile your file.

We previously noticed that xcpretty doesn’t generate an accurate compilation database. It populates the directory entry with the wrong value.

If you still want to use xcpretty, there is a workaround described in this ticket to fix the directory entry:
[CPP-3665] - Jira.

Thanks