build-scripts/checker-buildbot.sh
author Ryan C. Gordon <icculus@icculus.org>
Wed, 19 Mar 2014 22:43:30 -0400
changeset 8644 f218b4e65498
parent 8640 89bab8249c74
child 9100 441e6cee6d14
permissions -rwxr-xr-x
Minor comment cleanups 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@8644
     7
# Install Clang (you already have it on Mac OS X, apt-get install clang
icculus@8644
     8
#  on Ubuntu, etc),
icculus@8644
     9
# or download checker at http://clang-analyzer.llvm.org/ and unpack it in
icculus@8635
    10
#  /usr/local ... update CHECKERDIR as appropriate.
icculus@8635
    11
icculus@8635
    12
FINALDIR="$1"
icculus@8635
    13
icculus@8639
    14
CHECKERDIR="/usr/local/checker-276"
icculus@8635
    15
if [ ! -d "$CHECKERDIR" ]; then
icculus@8639
    16
    echo "$CHECKERDIR not found. Trying /usr/share/clang ..." 1>&2
icculus@8639
    17
    CHECKERDIR="/usr/share/clang/scan-build"
icculus@8639
    18
fi
icculus@8639
    19
icculus@8639
    20
if [ ! -d "$CHECKERDIR" ]; then
icculus@8639
    21
    echo "$CHECKERDIR not found. Giving up." 1>&2
icculus@8635
    22
    exit 1
icculus@8635
    23
fi
icculus@8635
    24
icculus@8635
    25
if [ -z "$MAKE" ]; then
icculus@8635
    26
    OSTYPE=`uname -s`
icculus@8635
    27
    if [ "$OSTYPE" == "Linux" ]; then
icculus@8635
    28
        NCPU=`cat /proc/cpuinfo |grep vendor_id |wc -l`
icculus@8635
    29
        let NCPU=$NCPU+1
icculus@8635
    30
    elif [ "$OSTYPE" = "Darwin" ]; then
icculus@8635
    31
        NCPU=`sysctl -n hw.ncpu`
icculus@8635
    32
    elif [ "$OSTYPE" = "SunOS" ]; then
icculus@8635
    33
        NCPU=`/usr/sbin/psrinfo |wc -l |sed -e 's/^ *//g;s/ *$//g'`
icculus@8635
    34
    else
icculus@8635
    35
        NCPU=1
icculus@8635
    36
    fi
icculus@8635
    37
icculus@8635
    38
    if [ -z "$NCPU" ]; then
icculus@8635
    39
        NCPU=1
icculus@8635
    40
    elif [ "$NCPU" = "0" ]; then
icculus@8635
    41
        NCPU=1
icculus@8635
    42
    fi
icculus@8635
    43
icculus@8635
    44
    MAKE="make -j$NCPU"
icculus@8635
    45
fi
icculus@8635
    46
icculus@8635
    47
echo "\$MAKE is '$MAKE'"
icculus@8635
    48
icculus@8635
    49
set -x
icculus@8635
    50
set -e
icculus@8635
    51
icculus@8635
    52
cd `dirname "$0"`
icculus@8635
    53
cd ..
icculus@8635
    54
icculus@8635
    55
rm -rf checker-buildbot analysis
icculus@8635
    56
if [ ! -z "$FINALDIR" ]; then
icculus@8635
    57
    rm -rf "$FINALDIR"
icculus@8635
    58
fi
icculus@8635
    59
icculus@8635
    60
mkdir checker-buildbot
icculus@8635
    61
cd checker-buildbot
icculus@8644
    62
icculus@8644
    63
# You might want to do this for CMake-backed builds instead...
icculus@8644
    64
#cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER="$CHECKERDIR/libexec/ccc-analyzer" ..
icculus@8644
    65
icculus@8644
    66
# ...or run configure without the scan-build wrapper...
icculus@8639
    67
#CC="$CHECKERDIR/libexec/ccc-analyzer" CFLAGS="-O0" ../configure
icculus@8644
    68
icculus@8644
    69
# ...but this works for our buildbots just fine.
icculus@8639
    70
CFLAGS="-O0" PATH="$CHECKERDIR:$PATH" scan-build -o analysis ../configure
icculus@8644
    71
icculus@8639
    72
rm -rf analysis
icculus@8635
    73
PATH="$CHECKERDIR:$PATH" scan-build -o analysis $MAKE
icculus@8635
    74
mv analysis/* ../analysis
icculus@8635
    75
rmdir analysis   # Make sure this is empty.
icculus@8635
    76
cd ..
icculus@8635
    77
chmod -R a+r analysis
icculus@8635
    78
chmod -R go-w analysis
icculus@8635
    79
find analysis -type d -exec chmod a+x {} \;
icculus@8635
    80
if [ -x /usr/bin/xattr ]; then find analysis -exec /usr/bin/xattr -d com.apple.quarantine {} \; 2>/dev/null ; fi
icculus@8635
    81
icculus@8635
    82
if [ ! -z "$FINALDIR" ]; then
icculus@8635
    83
    mv analysis "$FINALDIR"
icculus@8635
    84
else
icculus@8635
    85
    FINALDIR=analysis
icculus@8635
    86
fi
icculus@8635
    87
icculus@8635
    88
rm -rf checker-buildbot
icculus@8635
    89
icculus@8635
    90
echo "Done. Final output is in '$FINALDIR' ..."
icculus@8635
    91
icculus@8635
    92
# end of checker-buildbot.sh ...
icculus@8635
    93