build-scripts/checker-buildbot.sh
changeset 8635 f1076ec9e707
child 8636 c10618240799
equal deleted inserted replaced
8634:a60eaa04d3fb 8635:f1076ec9e707
       
     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 CHECKERDIR="/usr/local/checker-276"
       
    14 
       
    15 FINALDIR="$1"
       
    16 
       
    17 if [ ! -d "$CHECKERDIR" ]; then
       
    18     echo "$CHECKERDIR not found." 1>&2
       
    19     exit 1
       
    20 fi
       
    21 
       
    22 if [ -z "$MAKE" ]; then
       
    23     OSTYPE=`uname -s`
       
    24     if [ "$OSTYPE" == "Linux" ]; then
       
    25         NCPU=`cat /proc/cpuinfo |grep vendor_id |wc -l`
       
    26         let NCPU=$NCPU+1
       
    27     elif [ "$OSTYPE" = "Darwin" ]; then
       
    28         NCPU=`sysctl -n hw.ncpu`
       
    29     elif [ "$OSTYPE" = "SunOS" ]; then
       
    30         NCPU=`/usr/sbin/psrinfo |wc -l |sed -e 's/^ *//g;s/ *$//g'`
       
    31     else
       
    32         NCPU=1
       
    33     fi
       
    34 
       
    35     if [ -z "$NCPU" ]; then
       
    36         NCPU=1
       
    37     elif [ "$NCPU" = "0" ]; then
       
    38         NCPU=1
       
    39     fi
       
    40 
       
    41     MAKE="make -j$NCPU"
       
    42 fi
       
    43 
       
    44 echo "\$MAKE is '$MAKE'"
       
    45 
       
    46 set -x
       
    47 set -e
       
    48 
       
    49 cd `dirname "$0"`
       
    50 cd ..
       
    51 
       
    52 # Turn off the dynamic API. Makes the analysis output clearer.
       
    53 echo '#pragma once' >src/dynapi/SDL_dynapi.h
       
    54 echo '#define SDL_DYNAMIC_API 0' >>src/dynapi/SDL_dynapi.h
       
    55 
       
    56 rm -rf checker-buildbot analysis
       
    57 if [ ! -z "$FINALDIR" ]; then
       
    58     rm -rf "$FINALDIR"
       
    59 fi
       
    60 
       
    61 mkdir checker-buildbot
       
    62 cd checker-buildbot
       
    63 cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER="$CHECKERDIR/libexec/ccc-analyzer" ..
       
    64 PATH="$CHECKERDIR:$PATH" scan-build -o analysis $MAKE
       
    65 mv analysis/* ../analysis
       
    66 rmdir analysis   # Make sure this is empty.
       
    67 cd ..
       
    68 chmod -R a+r analysis
       
    69 chmod -R go-w analysis
       
    70 find analysis -type d -exec chmod a+x {} \;
       
    71 if [ -x /usr/bin/xattr ]; then find analysis -exec /usr/bin/xattr -d com.apple.quarantine {} \; 2>/dev/null ; fi
       
    72 
       
    73 if [ ! -z "$FINALDIR" ]; then
       
    74     mv analysis "$FINALDIR"
       
    75 else
       
    76     FINALDIR=analysis
       
    77 fi
       
    78 
       
    79 rm -rf checker-buildbot
       
    80 hg revert src/dynapi/SDL_dynapi.h
       
    81 
       
    82 echo "Done. Final output is in '$FINALDIR' ..."
       
    83 
       
    84 # end of checker-buildbot.sh ...
       
    85