build-scripts/checker-buildbot.sh
author Ryan C. Gordon
Wed, 19 Mar 2014 15:25:27 -0400
changeset 8639 21093d07b958
parent 8638 d7a5c452411b
child 8640 89bab8249c74
permissions -rwxr-xr-x
Make checker-buildbot.sh work just about anywhere Clang is installed.
     1 #!/bin/bash
     2 
     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.
     6 
     7 # To use: get CMake from http://cmake.org/ or "apt-get install cmake" or whatever.
     8 # And download checker at http://clang-analyzer.llvm.org/ and unpack it in
     9 #  /usr/local ... update CHECKERDIR as appropriate.
    10 
    11 # this currently expects a mercurial working copy that it can modify a little.
    12 
    13 FINALDIR="$1"
    14 
    15 CHECKERDIR="/usr/local/checker-276"
    16 if [ ! -d "$CHECKERDIR" ]; then
    17     echo "$CHECKERDIR not found. Trying /usr/share/clang ..." 1>&2
    18     CHECKERDIR="/usr/share/clang/scan-build"
    19 fi
    20 
    21 if [ ! -d "$CHECKERDIR" ]; then
    22     echo "$CHECKERDIR not found. Giving up." 1>&2
    23     exit 1
    24 fi
    25 
    26 if [ -z "$MAKE" ]; then
    27     OSTYPE=`uname -s`
    28     if [ "$OSTYPE" == "Linux" ]; then
    29         NCPU=`cat /proc/cpuinfo |grep vendor_id |wc -l`
    30         let NCPU=$NCPU+1
    31     elif [ "$OSTYPE" = "Darwin" ]; then
    32         NCPU=`sysctl -n hw.ncpu`
    33     elif [ "$OSTYPE" = "SunOS" ]; then
    34         NCPU=`/usr/sbin/psrinfo |wc -l |sed -e 's/^ *//g;s/ *$//g'`
    35     else
    36         NCPU=1
    37     fi
    38 
    39     if [ -z "$NCPU" ]; then
    40         NCPU=1
    41     elif [ "$NCPU" = "0" ]; then
    42         NCPU=1
    43     fi
    44 
    45     MAKE="make -j$NCPU"
    46 fi
    47 
    48 echo "\$MAKE is '$MAKE'"
    49 
    50 set -x
    51 set -e
    52 
    53 cd `dirname "$0"`
    54 cd ..
    55 
    56 # Turn off the dynamic API. Makes the analysis output clearer.
    57 echo '#pragma once' >src/dynapi/SDL_dynapi.h
    58 echo '#define SDL_DYNAMIC_API 0' >>src/dynapi/SDL_dynapi.h
    59 
    60 rm -rf checker-buildbot analysis
    61 if [ ! -z "$FINALDIR" ]; then
    62     rm -rf "$FINALDIR"
    63 fi
    64 
    65 mkdir checker-buildbot
    66 cd checker-buildbot
    67 #cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER="$CHECKERDIR/libexec/ccc-analyzer" -DSDL_STATIC=OFF ..
    68 #CC="$CHECKERDIR/libexec/ccc-analyzer" CFLAGS="-O0" ../configure
    69 CFLAGS="-O0" PATH="$CHECKERDIR:$PATH" scan-build -o analysis ../configure
    70 rm -rf analysis
    71 PATH="$CHECKERDIR:$PATH" scan-build -o analysis $MAKE
    72 mv analysis/* ../analysis
    73 rmdir analysis   # Make sure this is empty.
    74 cd ..
    75 chmod -R a+r analysis
    76 chmod -R go-w analysis
    77 find analysis -type d -exec chmod a+x {} \;
    78 if [ -x /usr/bin/xattr ]; then find analysis -exec /usr/bin/xattr -d com.apple.quarantine {} \; 2>/dev/null ; fi
    79 
    80 if [ ! -z "$FINALDIR" ]; then
    81     mv analysis "$FINALDIR"
    82 else
    83     FINALDIR=analysis
    84 fi
    85 
    86 rm -rf checker-buildbot
    87 hg revert src/dynapi/SDL_dynapi.h
    88 
    89 echo "Done. Final output is in '$FINALDIR' ..."
    90 
    91 # end of checker-buildbot.sh ...
    92