Skip to content

Instantly share code, notes, and snippets.

@coryalder
Forked from gavrix/gist:5054182
Last active July 11, 2017 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coryalder/6effee57a123420f2f949955f039fcee to your computer and use it in GitHub Desktop.
Save coryalder/6effee57a123420f2f949955f039fcee to your computer and use it in GitHub Desktop.
Script integrating OCLint into XCode. Put it in "Run script" build phase.
#!/bin/bash
# https://gist.github.com/gavrix/5054182 original
source ~/.bash_profile
hash oclint &> /dev/null
if [ $? -eq 1 ]; then
echo >&2 "oclint not found, analyzing stopped"
exit 1
fi
echo "[*] copying rules to tmp dir"
cp ${SRCROOT}/.oclint ${TARGET_TEMP_DIR}/.oclint
cd ${TARGET_TEMP_DIR}
if [ ! -f compile_commands.json ]; then
echo "[*] compile_commands.json not found, possibly clean was performed"
echo "[*] starting xcodebuild to rebuild the project.."
# clean previous output
if [ -f xcodebuild.log ]; then
rm xcodebuild.log
fi
cd ${SRCROOT}
xcodebuild clean
#build xcodebuild.log
xcodebuild | tee ${TARGET_TEMP_DIR}/xcodebuild.log | xcpretty -r json-compilation-database --output ${TARGET_TEMP_DIR}/compile_commands.json
fi
#run static analyzer
echo "[*] starting analyzing"
cd ${TARGET_TEMP_DIR}
oclint-json-compilation-database -- -report-type xcode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment