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