build-scripts/checker-buildbot.sh
author Ryan C. Gordon
Wed, 19 Mar 2014 16:02:25 -0400
changeset 8640 89bab8249c74
parent 8639 21093d07b958
child 8644 f218b4e65498
permissions -rwxr-xr-x
Don't overwrite SDL_dynapi.h in checker-buildbot.sh.
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
FINALDIR="$1"
icculus@8635
    12
icculus@8639
    13
CHECKERDIR="/usr/local/checker-276"
icculus@8635
    14
if [ ! -d "$CHECKERDIR" ]; then
icculus@8639
    15
    echo "$CHECKERDIR not found. Trying /usr/share/clang ..." 1>&2
icculus@8639
    16
    CHECKERDIR="/usr/share/clang/scan-build"
icculus@8639
    17
fi
icculus@8639
    18
icculus@8639
    19
if [ ! -d "$CHECKERDIR" ]; then
icculus@8639
    20
    echo "$CHECKERDIR not found. Giving up." 1>&2
icculus@8635
    21
    exit 1
icculus@8635
    22
fi
icculus@8635
    23
icculus@8635
    24
if [ -z "$MAKE" ]; then
icculus@8635
    25
    OSTYPE=`uname -s`
icculus@8635
    26
    if [ "$OSTYPE" == "Linux" ]; then
icculus@8635
    27
        NCPU=`cat /proc/cpuinfo |grep vendor_id |wc -l`
icculus@8635
    28
        let NCPU=$NCPU+1
icculus@8635
    29
    elif [ "$OSTYPE" = "Darwin" ]; then
icculus@8635
    30
        NCPU=`sysctl -n hw.ncpu`
icculus@8635
    31
    elif [ "$OSTYPE" = "SunOS" ]; then
icculus@8635
    32
        NCPU=`/usr/sbin/psrinfo |wc -l |sed -e 's/^ *//g;s/ *$//g'`
icculus@8635
    33
    else
icculus@8635
    34
        NCPU=1
icculus@8635
    35
    fi
icculus@8635
    36
icculus@8635
    37
    if [ -z "$NCPU" ]; then
icculus@8635
    38
        NCPU=1
icculus@8635
    39
    elif [ "$NCPU" = "0" ]; then
icculus@8635
    40
        NCPU=1
icculus@8635
    41
    fi
icculus@8635
    42
icculus@8635
    43
    MAKE="make -j$NCPU"
icculus@8635
    44
fi
icculus@8635
    45
icculus@8635
    46
echo "\$MAKE is '$MAKE'"
icculus@8635
    47
icculus@8635
    48
set -x
icculus@8635
    49
set -e
icculus@8635
    50
icculus@8635
    51
cd `dirname "$0"`
icculus@8635
    52
cd ..
icculus@8635
    53
icculus@8635
    54
rm -rf checker-buildbot analysis
icculus@8635
    55
if [ ! -z "$FINALDIR" ]; then
icculus@8635
    56
    rm -rf "$FINALDIR"
icculus@8635
    57
fi
icculus@8635
    58
icculus@8635
    59
mkdir checker-buildbot
icculus@8635
    60
cd checker-buildbot
icculus@8637
    61
#cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER="$CHECKERDIR/libexec/ccc-analyzer" -DSDL_STATIC=OFF ..
icculus@8639
    62
#CC="$CHECKERDIR/libexec/ccc-analyzer" CFLAGS="-O0" ../configure
icculus@8639
    63
CFLAGS="-O0" PATH="$CHECKERDIR:$PATH" scan-build -o analysis ../configure
icculus@8639
    64
rm -rf analysis
icculus@8635
    65
PATH="$CHECKERDIR:$PATH" scan-build -o analysis $MAKE
icculus@8635
    66
mv analysis/* ../analysis
icculus@8635
    67
rmdir analysis   # Make sure this is empty.
icculus@8635
    68
cd ..
icculus@8635
    69
chmod -R a+r analysis
icculus@8635
    70
chmod -R go-w analysis
icculus@8635
    71
find analysis -type d -exec chmod a+x {} \;
icculus@8635
    72
if [ -x /usr/bin/xattr ]; then find analysis -exec /usr/bin/xattr -d com.apple.quarantine {} \; 2>/dev/null ; fi
icculus@8635
    73
icculus@8635
    74
if [ ! -z "$FINALDIR" ]; then
icculus@8635
    75
    mv analysis "$FINALDIR"
icculus@8635
    76
else
icculus@8635
    77
    FINALDIR=analysis
icculus@8635
    78
fi
icculus@8635
    79
icculus@8635
    80
rm -rf checker-buildbot
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