Skip to content

Instantly share code, notes, and snippets.

@lqi
Forked from gavrix/gist:5054182
Last active July 29, 2017 14:33
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save lqi/5358513 to your computer and use it in GitHub Desktop.
Save lqi/5358513 to your computer and use it in GitHub Desktop.
source ~/.bash_profile
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 | sed 's/\(.*\.\m\{1,2\}:[0-9]*:[0-9]*:\)/\1 warning:/'
@getaaron
Copy link

All of the commands that take filenames as arguments will fail if there's a space in the directory name. If a directory has a space, you'll need to use (for example) xcodebuild | tee "${TARGET_TEMP_DIR}/xcodebuild.log".

@soniccat
Copy link

You forgot to handle warnings in .h files to remove error messages. I don't understand how sed. Can you help me?

@nhokkuteluv
Copy link

Any problem in this shell file? I used it but exception thrown at line two: source ~/.bash_profile --> not found?

@1951FDG
Copy link

1951FDG commented Jan 3, 2015

@getaaron

Check out my fork, https://gist.github.com/1951FDG/8146422, it handles file names with spaces correctly (hopefully one day OCLint will support file names with spaces, oclint-json-compilation-database and oclint-xcodebuild still have issues handling spaces in path).

@1951FDG
Copy link

1951FDG commented Jan 3, 2015

@nhokkuteluv

Check out my fork, https://gist.github.com/1951FDG/8146422, it fixes the exception thrown (it applies the file test below).

if [ -f ~/.bash_profile ]; then
    source ~/.bash_profile
fi

@1951FDG
Copy link

1951FDG commented Jan 3, 2015

@soniccat

Check out my fork, https://gist.github.com/1951FDG/8146422, it treats messages as warnings by default for a .c file, .m file or .mm file (as far as I know, OCLint does not produce messages for a .h file).

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