Skip to content

Instantly share code, notes, and snippets.

@paularmstrong
Created March 11, 2011 18:09
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 paularmstrong/866297 to your computer and use it in GitHub Desktop.
Save paularmstrong/866297 to your computer and use it in GitHub Desktop.
Installs Clang Static Analyzer
#!/bin/bash
installonly=no
while [ $# -gt 0 ]
do
case "$1" in
(-i) installonly=yes;;
(-*) echo "$0: error - urecognized option $1" 1>&2; exit 1;;
(*) break;;
esac
shift
done
if which scan-build &>/dev/null; then
printf ''
else
echo 'Downloading Clang Static Analyzer...'
curl -o checker-255.bz2 http://clang-analyzer.llvm.org/checker/checker-255.tar.bz2
tar -xvjf checker-255.bz2 &>/dev/null
mv checker-255 /usr/local/lib/
ln -s /usr/local/lib/checker-255/scan-build /usr/local/bin/scan-build
ln -s /usr/local/lib/checker-255/scan-view /usr/local/bin/scan-view
rm checker-255.bz2
echo 'Clang Analyzer installed.'
fi
if [[ $installonly == yes ]]; then
echo 'Clang is installed.'
exit 0
fi
echo 'Cleaning targets...'
make clean &>/dev/null
mkdir -p .clangtmp
echo 'Building & Scanning...'
scan-build --status-bugs -analyzer-check-objc-missing-dealloc -analyzer-check-objc-unused-ivars -analyzer-check-objc-methodsigs -analyzer-check-objc-mem xcodebuild -target 'HideAndSeek' -sdk iphoneos4.3 &>.clangtmp/output
if tail .clangtmp/output | grep 'BUILD FAILED' &>/dev/null; then
echo 'Build Failed'
exit 1
fi
BUGS=$(tail .clangtmp/output | grep 'bugs found.' | awk '$1 { print $2 }')
if [[ $BUGS -gt 0 ]]; then
echo $BUGS 'bugs found'
DIR=$(tail .clangtmp/output | grep ' to examine bug reports')
DIR=${DIR/scan-build: Run \'}
DIR=${DIR/\' to examine bug reports.}
eval $DIR
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment