Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script integrating OCLint into XCode. Put it in "Run script" build phase.
source ~/.bash_profile
cd ${SRCROOT}
xcodebuild clean
xcodebuild | xcpretty -r json-compilation-database
oclint-json-compilation-database -- -report-type xcode
@RajbharS-Consultant

This comment has been minimized.

RajbharS-Consultant commented Sep 16, 2016

.bash_profile: No such file or directory
getting shell script error?

@RajbharS-Consultant

This comment has been minimized.

RajbharS-Consultant commented Sep 20, 2016

Error: compile_commands.json not found at current location.?

@AshrafJaddo

This comment has been minimized.

AshrafJaddo commented Sep 30, 2016

Did anyone got this to work with xcode8?

I am getting no compile_commands.json after running xcodebuild | xcpretty -r json-compilation-database

all tools installed from brew

@bsameh

This comment has been minimized.

bsameh commented Oct 21, 2016

For those getting the "compile_commands.json not found" error; my solution was to change

xcodebuild | xcpretty -r json-compilation-database

to

xcodebuild | xcpretty -r json-compilation-database --output compile_commands.json

The --output parameter tells xcpretty to generate the compilation database JSON file in the same folder and with the filename that oclint expects, "compile_commands.json". By default, xcpretty generates a "commands_db.json" file under PROJECT_DIR/build/reports, which is why oclint-json-compilation-database can't seem to find it.

@iShawnWang

This comment has been minimized.

iShawnWang commented Dec 3, 2016

not works on Xcode 8 :( .... @bsameh

I got multiple target on my workspace

@GipsySh

This comment has been minimized.

GipsySh commented Apr 12, 2017

I tried the following commands:
xcodebuild -target TARGET -configuration Debug -scheme SCHEME | xcpretty --report json-compilation-database --output compile_commands.json
or
xcodebuild -target TARGET -configuration Debug -scheme SCHEME | xcpretty -r json-compilation-database --output compile_commands.json

But I got "Error: compile_commands.json not found at current location." for both in XCode.

@jcapp-gold-finance

This comment has been minimized.

jcapp-gold-finance commented Apr 26, 2017

cp: build/reports/compilation_db.json: No such file or directory

@jcapp-gold-finance

This comment has been minimized.

jcapp-gold-finance commented Apr 26, 2017

env: ruby_executable_hooks: No such file or directory

@tylermilner

This comment has been minimized.

tylermilner commented Jun 1, 2017

Hi all, I was having trouble getting this script to work as well. @bsameh's solution helped, but I still needed to make some tweaks to the parameters for the xcodebuild command by specifying the scheme and workspace (I'm using Cocoapods). I also had to make sure to use the same parameters for the xcodebuild clean command.

Here's what the final script looks like (substituting <projectName> for the correct value, of course). You may also need to tweak some of the exclude options for the oclint-json-compilation-database command:

source ~/.bash_profile
cd ${SRCROOT}
xcodebuild -scheme <projectName> -workspace <projectName>.xcworkspace clean
xcodebuild -scheme <projectName> -workspace <projectName>.xcworkspace | xcpretty -r json-compilation-database --output compile_commands.json
oclint-json-compilation-database -exclude Pods -exclude build -exclude Internal -exclude ThirdParties -- -report-type xcode
@plam4u

This comment has been minimized.

plam4u commented Feb 20, 2018

The solution of @tylermilner works for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment