extras/buildbot-checker.sh
author Ryan C. Gordon <icculus@icculus.org>
Tue, 12 May 2020 15:49:53 -0400
changeset 1684 eb8b181d8301
parent 1425 176efd35457c
child 1685 12063a77c51d
permissions -rwxr-xr-x
Have static analysis script use Ninja.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1411
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
#!/bin/bash
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
# This is a script used by some Buildbot buildslaves to push the project
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
#  through Clang's static analyzer and prepare the output to be uploaded
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
#  back to the buildmaster. You might find it useful too.
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
# Install Clang (you already have it on Mac OS X, apt-get install clang
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
#  on Ubuntu, etc),
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
# or download checker at http://clang-analyzer.llvm.org/ and unpack it in
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
#  /usr/local ... update CHECKERDIR as appropriate.
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
FINALDIR="$1"
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
CHECKERDIR="/usr/local/checker-279"
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
if [ ! -d "$CHECKERDIR" ]; then
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
    echo "$CHECKERDIR not found. Trying /usr/share/clang ..." 1>&2
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
    CHECKERDIR="/usr/share/clang/scan-build"
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
fi
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
if [ ! -d "$CHECKERDIR" ]; then
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
    echo "$CHECKERDIR not found. Giving up." 1>&2
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
    exit 1
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
fi
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
set -x
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
set -e
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
cd `dirname "$0"`
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
cd ..
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
rm -rf checker-buildbot analysis
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
if [ ! -z "$FINALDIR" ]; then
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
    rm -rf "$FINALDIR"
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
fi
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
mkdir checker-buildbot
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
cd checker-buildbot
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
# We turn off deprecated declarations, because we don't care about these warnings during static analysis.
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
# The -Wno-liblto is new since our checker-279 upgrade, I think; checker otherwise warns "libLTO.dylib relative to clang installed dir not found"
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
# You might want to do this for CMake-backed builds instead...
1684
eb8b181d8301 Have static analysis script use Ninja.
Ryan C. Gordon <icculus@icculus.org>
parents: 1425
diff changeset
    43
PATH="$CHECKERDIR/bin:$PATH" scan-build -o analysis cmake -G Ninja -Wno-dev -DPHYSFS_BUILD_SHARED=False -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS="-Wno-deprecated-declarations" -DCMAKE_EXE_LINKER_FLAGS="-Wno-liblto" ..
1411
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
# ...or run configure without the scan-build wrapper...
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
#CC="$CHECKERDIR/libexec/ccc-analyzer" CFLAGS="-O0 -Wno-deprecated-declarations" LDFLAGS="-Wno-liblto" ../configure --enable-assertions=enabled
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
rm -rf analysis
1684
eb8b181d8301 Have static analysis script use Ninja.
Ryan C. Gordon <icculus@icculus.org>
parents: 1425
diff changeset
    49
PATH="$CHECKERDIR/bin:$PATH" scan-build -o analysis cmake --build . --config Debug
1411
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
if [ `ls -A analysis |wc -l` == 0 ] ; then
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
    mkdir analysis/zarro
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
    echo '<html><head><title>Zarro boogs</title></head><body>Static analysis: no issues to report.</body></html>' >analysis/zarro/index.html
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
fi
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
mv analysis/* ../analysis
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
rmdir analysis   # Make sure this is empty.
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
cd ..
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
chmod -R a+r analysis
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
chmod -R go-w analysis
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
find analysis -type d -exec chmod a+x {} \;
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
if [ -x /usr/bin/xattr ]; then find analysis -exec /usr/bin/xattr -d com.apple.quarantine {} \; 2>/dev/null ; fi
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
if [ ! -z "$FINALDIR" ]; then
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
    mv analysis "$FINALDIR"
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
else
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
    FINALDIR=analysis
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
fi
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
rm -rf checker-buildbot
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
echo "Done. Final output is in '$FINALDIR' ..."
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
# end of checker-buildbot.sh ...
c69e2a678c5a Added script to run Clang static analysis.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75