Wrapper script for an xcodebuild
command that generates and updates compile-commands.json
.
Based on T1T4N
's excellent writeup here. The script invokes the build with -gen-cdb-fragment-path
to generate clangd
-compatible compilation database fragments and appends them to compile_commands.json
.
The python script is needed to:
- Normalize the output fragments generated by
-gen-cdb-fragment-path
, removing trailing commas and newlines. - Smartly update the entries in
compile-commands.json
, as not every build will produce compilation fragments for each input file.
python3
must be invokable from your path.
By default, the script will output compilation fragments to cdb
in the current directory, and output final compile-commands.json
also to the current directory.
Modifying GXC_SCRIPT_DIR
, FRAGMENT_DIR
, and OUTPUT_FILE
at the top of gxcWrapper.sh
controls this behavior.
Invoke the gxcWrapper.sh
script in front of your normal xcodebuild
command.
./gxcWrapper.sh xcodebuild -project sample.xcodeproj -configuration Debug -scheme sample -derivedDataPath build
If you are using VSCode, you may want to modify your tasks.json
to invoke this script. For example:
{
"label": "Build (Debug)",
"type": "shell",
"command": "./gxcWrapper.sh xcodebuild -project sample.xcodeproj -configuration Debug -scheme sample -derivedDataPath build",
"problemMatcher": ["$gcc"],
"group": {
"kind": "build"
}
}