NNikN
NNikN

Reputation: 3850

OCLint Xcode 9.3.1 Failure

I have the following Run Script , available at http://oclint-docs.readthedocs.io/en/stable/guide/xcode.html

source ~/.bash_profile
cd ${SRCROOT}
xcodebuild clean
xcodebuild | xcpretty -r json-compilation-database --output compile_commands.json
oclint-json-compilation-database -- -report-type xcode

But, when I execute it, I receive the following error. (1 failure) oclint: Not enough positional command line arguments specified!

oclint version is OCLint version 0.13 and Xcode 9.3.1

Upvotes: 5

Views: 589

Answers (1)

T1T4N
T1T4N

Reputation: 321

I have found a way to generate a JSON compilation database from an Xcode project without relying on external tools. Tested with Xcode 13.4.1 on macOS 12 Monterey and Apple Silicon M1 Pro.

Inside your Xcode Build Settings, or when invoking xcodebuild you can set the following compiler flag:
OTHER_CFLAGS = $(inherited) -gen-cdb-fragment-path $(PROJECT_DIR)/CompilationDatabase

This instructs clang to emit a fragment of the compilation database for each compilation. These fragments can easily be combined into the final compilation database by using the following command:
sed -e '1s/^/[\'$'\n''/' -e '$s/,$/\'$'\n'']/' *.json > compile_commands.json

Of course it's a good idea to validate fragments, but that cannot be done without external tools.

For full details regarding compiler flags, validation of fragments, and references, check out the gist:
Generate a JSON Compilation Database from an Xcode project

Upvotes: 2

Related Questions