2018-06-09 20:08:34 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Run clang's static analyzer (scan-build) and record its output in output-scan-build/
|
|
|
|
|
2023-11-09 13:51:48 +00:00
|
|
|
# Allow overriding binary names, like clang-12
|
2021-07-14 18:13:38 +00:00
|
|
|
export CC=${CC:-clang}
|
|
|
|
SCAN_BUILD=${SCAN_BUILD:-scan-build}
|
|
|
|
|
2018-06-09 20:08:34 +00:00
|
|
|
# Ensure the current directory is where this script is
|
|
|
|
cd "$(dirname -- "$0")" || exit $?
|
|
|
|
|
|
|
|
OUTPUTDIR="$(pwd)/output-scan-build"
|
|
|
|
|
|
|
|
# Display the commands which are run, and make sure they succeed
|
|
|
|
set -x -e
|
|
|
|
|
|
|
|
# Use a temporary directory as an installation directory, if $DESTDIR is not set
|
|
|
|
if [ -z "$DESTDIR" ] ; then
|
|
|
|
DESTDIR="$(mktemp --tmpdir -d scan-build-destdir-XXXXXXXXXX)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Make sure to use the newly-installed libraries when running tests
|
|
|
|
export LD_LIBRARY_PATH="$DESTDIR/usr/lib:$DESTDIR/lib"
|
|
|
|
export PATH="$DESTDIR/usr/sbin:$DESTDIR/usr/bin:$DESTDIR/sbin:$DESTDIR/bin:$PATH"
|
2022-10-28 20:21:35 +00:00
|
|
|
export PYTHONPATH="$DESTDIR$(${PYTHON:-python3} -c "import sysconfig; print(sysconfig.get_path('purelib', vars={'platbase': '/usr', 'base': '/usr'}))")"
|
2018-06-09 20:08:34 +00:00
|
|
|
export RUBYLIB="$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorlibdir"]'):$DESTDIR/$(${RUBY:-ruby} -e 'puts RbConfig::CONFIG["vendorarchdir"]')"
|
|
|
|
|
2022-06-29 07:12:54 +00:00
|
|
|
if [ -f /etc/debian_version ] && [ -z "${IS_CIRCLE_CI:-}" ] ; then
|
2023-11-09 13:51:47 +00:00
|
|
|
export DEB_PYTHON_INSTALL_LAYOUT='deb'
|
2021-07-14 18:13:38 +00:00
|
|
|
fi
|
|
|
|
|
2018-06-09 20:08:34 +00:00
|
|
|
# Build and analyze
|
2021-07-14 18:13:38 +00:00
|
|
|
make -C .. clean distclean -j"$(nproc)"
|
|
|
|
$SCAN_BUILD -analyze-headers -o "$OUTPUTDIR" make -C .. \
|
2019-09-26 22:04:05 +00:00
|
|
|
DESTDIR="$DESTDIR" \
|
2023-11-09 13:51:48 +00:00
|
|
|
CFLAGS="-O2 -Wall -Wextra -D_FORTIFY_SOURCE=3 -D__CHECKER__ -I$DESTDIR/usr/include" \
|
2021-07-14 18:13:38 +00:00
|
|
|
-j"$(nproc)" \
|
2023-11-09 13:51:48 +00:00
|
|
|
install install-pywrap install-rubywrap all \
|
|
|
|
|| { echo "++ Build failed!"; exit 1; }
|
2018-06-09 20:08:34 +00:00
|
|
|
|
2023-11-09 13:51:48 +00:00
|
|
|
echo "++ Build succeeded"
|
2021-07-14 18:13:38 +00:00
|
|
|
|
2018-06-09 20:08:34 +00:00
|
|
|
# Reduce the verbosity in order to keep the message from scan-build saying
|
|
|
|
# "scan-build: Run 'scan-view /.../output-scan-build/2018-...' to examine bug reports.
|
|
|
|
set +x
|
|
|
|
|
|
|
|
# Remove the destination directory without using "rm -rf"
|
|
|
|
chmod u+w "$DESTDIR/usr/bin/newrole"
|
|
|
|
rm -r "$DESTDIR"
|