Skip to content

Instantly share code, notes, and snippets.

@wooster
Last active August 29, 2015 13:59
Show Gist options
  • Save wooster/10607828 to your computer and use it in GitHub Desktop.
Save wooster/10607828 to your computer and use it in GitHub Desktop.
Xcode Run Script Phase for OCLint
source ~/.bash_profile
OCLINT_HOME="/Users/andrew/Downloads/oclint-0.9.dev.6a4451b"
PATH=$OCLINT_HOME/bin:$PATH
hash oclint &> /dev/null
if [ $? -eq 1 ]; then
echo >&2 "oclint not found, analyzing stopped"
exit 1
fi
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"
#xcodebuild <options>| tee ${TARGET_TEMP_DIR}/xcodebuild.log
echo "[*] transforming xcodebuild.log into compile_commands.json..."
cd "${TARGET_TEMP_DIR}"
#transform it into compile_commands.json
oclint-xcodebuild
echo "[*] copy compile_commands.json to the project root..."
cp "${TARGET_TEMP_DIR}/compile_commands.json" "${SRCROOT}/compile_commands.json"
fi
echo "[*] starting analyzing"
cd ${TARGET_TEMP_DIR}
oclint-json-compilation-database oclint_args oclint_args "-disable-rule=FeatureEnvy -disable-rule=IvarAssignmentOutsideAccessorsOrInit -rc LONG_LINE=1000 -rc LONG_VARIABLE_NAME=100" | sed 's/\(.*\.\m\{1,2\}:[0-9]*:[0-9]*:\)/\1 warning:/'
@wooster
Copy link
Author

wooster commented Apr 14, 2014

Based on the example script, but with some extra arguments to disable some of the more aggressive warnings.

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