1#!/bin/sh 2# Run clang's static analyzer (scan-build) and record its output in output-scan-build/ 3 4# Allow overriding binariy names, like clang-12 5export CC=${CC:-clang} 6SCAN_BUILD=${SCAN_BUILD:-scan-build} 7 8# Ensure the current directory is where this script is 9cd "$(dirname -- "$0")" || exit $? 10 11OUTPUTDIR="$(pwd)/output-scan-build" 12 13# Display the commands which are run, and make sure they succeed 14set -x -e 15 16# Use a temporary directory as an installation directory, if $DESTDIR is not set 17if [ -z "$DESTDIR" ] ; then 18 DESTDIR="$(mktemp --tmpdir -d scan-build-destdir-XXXXXXXXXX)" 19fi 20 21# Make sure to use the newly-installed libraries when running tests 22export LD_LIBRARY_PATH="$DESTDIR/usr/lib:$DESTDIR/lib" 23export PATH="$DESTDIR/usr/sbin:$DESTDIR/usr/bin:$DESTDIR/sbin:$DESTDIR/bin:$PATH" 24export PYTHONPATH="$DESTDIR$(${PYTHON:-python3} -c "from distutils.sysconfig import *;print(get_python_lib(prefix='/usr'))")" 25export RUBYLIB="$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorlibdir"]'):$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorarchdir"]')" 26 27if [ -f /etc/debian_version ]; then 28 export PYTHON_SETUP_ARGS='--install-layout=deb' 29fi 30 31# Build and analyze 32make -C .. clean distclean -j"$(nproc)" 33$SCAN_BUILD -analyze-headers -o "$OUTPUTDIR" make -C .. \ 34 DESTDIR="$DESTDIR" \ 35 CFLAGS="-O2 -Wall -Wextra -D_FORTIFY_SOURCE=2 -D__CHECKER__ -I$DESTDIR/usr/include" \ 36 -j"$(nproc)" \ 37 install install-pywrap install-rubywrap all test 38 39if [ $? -eq 0 ]; then 40 echo "++ Build succeeded" 41else 42 echo "++ Build failed" 43fi 44 45# Reduce the verbosity in order to keep the message from scan-build saying 46# "scan-build: Run 'scan-view /.../output-scan-build/2018-...' to examine bug reports. 47set +x 48 49# Remove the destination directory without using "rm -rf" 50chmod u+w "$DESTDIR/usr/bin/newrole" 51rm -r "$DESTDIR" 52