3 # This is a script used by some Buildbot buildslaves to push the project
4 # through Clang's static analyzer and prepare the output to be uploaded
5 # back to the buildmaster. You might find it useful too.
7 # Install Clang (you already have it on Mac OS X, apt-get install clang
9 # or download checker at http://clang-analyzer.llvm.org/ and unpack it in
10 # /usr/local ... update CHECKERDIR as appropriate.
14 CHECKERDIR="/usr/local/checker-276"
15 if [ ! -d "$CHECKERDIR" ]; then
16 echo "$CHECKERDIR not found. Trying /usr/share/clang ..." 1>&2
17 CHECKERDIR="/usr/share/clang/scan-build"
20 if [ ! -d "$CHECKERDIR" ]; then
21 echo "$CHECKERDIR not found. Giving up." 1>&2
25 if [ -z "$MAKE" ]; then
27 if [ "$OSTYPE" == "Linux" ]; then
28 NCPU=`cat /proc/cpuinfo |grep vendor_id |wc -l`
30 elif [ "$OSTYPE" = "Darwin" ]; then
31 NCPU=`sysctl -n hw.ncpu`
32 elif [ "$OSTYPE" = "SunOS" ]; then
33 NCPU=`/usr/sbin/psrinfo |wc -l |sed -e 's/^ *//g;s/ *$//g'`
38 if [ -z "$NCPU" ]; then
40 elif [ "$NCPU" = "0" ]; then
47 echo "\$MAKE is '$MAKE'"
55 rm -rf checker-buildbot analysis
56 if [ ! -z "$FINALDIR" ]; then
60 mkdir checker-buildbot
63 # You might want to do this for CMake-backed builds instead...
64 PATH="$CHECKERDIR:$PATH" scan-build -o analysis cmake -DCMAKE_BUILD_TYPE=Debug -DASSERTIONS=enabled ..
66 # ...or run configure without the scan-build wrapper...
67 #CC="$CHECKERDIR/libexec/ccc-analyzer" CFLAGS="-O0" ../configure --enable-assertions=enabled
69 # ...but this works for our buildbots just fine (EXCEPT ON LATEST MAC OS X).
70 #CFLAGS="-O0" PATH="$CHECKERDIR:$PATH" scan-build -o analysis ../configure --enable-assertions=enabled
73 PATH="$CHECKERDIR:$PATH" scan-build -o analysis $MAKE
74 mv analysis/* ../analysis
75 rmdir analysis # Make sure this is empty.
78 chmod -R go-w analysis
79 find analysis -type d -exec chmod a+x {} \;
80 if [ -x /usr/bin/xattr ]; then find analysis -exec /usr/bin/xattr -d com.apple.quarantine {} \; 2>/dev/null ; fi
82 if [ ! -z "$FINALDIR" ]; then
83 mv analysis "$FINALDIR"
88 rm -rf checker-buildbot
90 echo "Done. Final output is in '$FINALDIR' ..."
92 # end of checker-buildbot.sh ...