build-scripts/checker-buildbot.sh
changeset 13815 8c7bf8f29b8c
parent 11170 b5fe34e8401f
equal deleted inserted replaced
13814:dc7142e7b47e 13815:8c7bf8f29b8c
     3 # This is a script used by some Buildbot buildslaves to push the project
     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
     4 #  through Clang's static analyzer and prepare the output to be uploaded
     5 #  back to the buildmaster. You might find it useful too.
     5 #  back to the buildmaster. You might find it useful too.
     6 
     6 
     7 # Install Clang (you already have it on Mac OS X, apt-get install clang
     7 # Install Clang (you already have it on Mac OS X, apt-get install clang
     8 #  on Ubuntu, etc),
     8 #  on Ubuntu, etc), and make sure scan-build is in your $PATH.
     9 # or download checker at http://clang-analyzer.llvm.org/ and unpack it in
       
    10 #  /usr/local ... update CHECKERDIR as appropriate.
       
    11 
     9 
    12 FINALDIR="$1"
    10 FINALDIR="$1"
    13 
       
    14 CHECKERDIR="/usr/local/checker-279"
       
    15 if [ ! -d "$CHECKERDIR" ]; then
       
    16     echo "$CHECKERDIR not found. Trying /usr/share/clang ..." 1>&2
       
    17     CHECKERDIR="/usr/share/clang/scan-build"
       
    18 fi
       
    19 
       
    20 if [ ! -d "$CHECKERDIR" ]; then
       
    21     echo "$CHECKERDIR not found. Giving up." 1>&2
       
    22     exit 1
       
    23 fi
       
    24 
       
    25 if [ -z "$MAKE" ]; then
       
    26     OSTYPE=`uname -s`
       
    27     if [ "$OSTYPE" == "Linux" ]; then
       
    28         NCPU=`cat /proc/cpuinfo |grep vendor_id |wc -l`
       
    29         let NCPU=$NCPU+1
       
    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'`
       
    34     else
       
    35         NCPU=1
       
    36     fi
       
    37 
       
    38     if [ -z "$NCPU" ]; then
       
    39         NCPU=1
       
    40     elif [ "$NCPU" = "0" ]; then
       
    41         NCPU=1
       
    42     fi
       
    43 
       
    44     MAKE="make -j$NCPU"
       
    45 fi
       
    46 
       
    47 echo "\$MAKE is '$MAKE'"
       
    48 
       
    49 # Unset $MAKE so submakes don't use it.
       
    50 MAKECOMMAND="$MAKE"
       
    51 unset MAKE
       
    52 
    11 
    53 set -x
    12 set -x
    54 set -e
    13 set -e
    55 
    14 
    56 cd `dirname "$0"`
    15 cd `dirname "$0"`
    66 
    25 
    67 # We turn off deprecated declarations, because we don't care about these warnings during static analysis.
    26 # We turn off deprecated declarations, because we don't care about these warnings during static analysis.
    68 # The -Wno-liblto is new since our checker-279 upgrade, I think; checker otherwise warns "libLTO.dylib relative to clang installed dir not found"
    27 # The -Wno-liblto is new since our checker-279 upgrade, I think; checker otherwise warns "libLTO.dylib relative to clang installed dir not found"
    69 
    28 
    70 # You might want to do this for CMake-backed builds instead...
    29 # You might want to do this for CMake-backed builds instead...
    71 PATH="$CHECKERDIR/bin:$PATH" scan-build -o analysis cmake -Wno-dev -DSDL_STATIC=OFF -DCMAKE_BUILD_TYPE=Debug -DASSERTIONS=enabled -DCMAKE_C_FLAGS="-Wno-deprecated-declarations" -DCMAKE_SHARED_LINKER_FLAGS="-Wno-liblto" ..
    30 scan-build -o analysis cmake -G Ninja -Wno-dev -DSDL_STATIC=OFF -DCMAKE_BUILD_TYPE=Debug -DASSERTIONS=enabled -DCMAKE_C_FLAGS="-Wno-deprecated-declarations" -DCMAKE_SHARED_LINKER_FLAGS="-Wno-liblto" ..
    72 
    31 
    73 # ...or run configure without the scan-build wrapper...
    32 # ...or run configure without the scan-build wrapper...
    74 #CC="$CHECKERDIR/libexec/ccc-analyzer" CFLAGS="-O0 -Wno-deprecated-declarations" LDFLAGS="-Wno-liblto" ../configure --enable-assertions=enabled
    33 #CC="$CHECKERDIR/libexec/ccc-analyzer" CFLAGS="-O0 -Wno-deprecated-declarations" LDFLAGS="-Wno-liblto" ../configure --enable-assertions=enabled
    75 
    34 
    76 rm -rf analysis
    35 rm -rf analysis
    77 PATH="$CHECKERDIR/bin:$PATH" scan-build -o analysis $MAKECOMMAND
    36 scan-build -o analysis ninja
    78 
    37 
    79 if [ `ls -A analysis |wc -l` == 0 ] ; then
    38 if [ `ls -A analysis |wc -l` == 0 ] ; then
    80     mkdir analysis/zarro
    39     mkdir analysis/zarro
    81     echo '<html><head><title>Zarro boogs</title></head><body>Static analysis: no issues to report.</body></html>' >analysis/zarro/index.html
    40     echo '<html><head><title>Zarro boogs</title></head><body>Static analysis: no issues to report.</body></html>' >analysis/zarro/index.html
    82 fi
    41 fi