| 1 | #!/bin/bash -exu |
| 2 | # |
| 3 | # Copyright (C) 2015 - Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com> |
| 4 | # 2016 - Michael Jeanson <mjeanson@efficios.com> |
| 5 | # |
| 6 | # This program is free software: you can redistribute it and/or modify |
| 7 | # it under the terms of the GNU General Public License as published by |
| 8 | # the Free Software Foundation, either version 3 of the License, or |
| 9 | # (at your option) any later version. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License |
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | |
| 19 | |
| 20 | # do not exit immediately if any command fails |
| 21 | set +e |
| 22 | |
| 23 | SRCDIR="$WORKSPACE/src/$PROJECT_NAME" |
| 24 | TMPDIR="$WORKSPACE/tmp" |
| 25 | PREFIX="$WORKSPACE/build" |
| 26 | |
| 27 | # Directory to archive the scan-build report |
| 28 | SCAN_BUILD_ARCHIVE="${WORKSPACE}/scan-build-archive" |
| 29 | |
| 30 | # Create build and tmp directories |
| 31 | rm -rf "$PREFIX" "$TMPDIR" |
| 32 | mkdir -p "$PREFIX" "$TMPDIR" |
| 33 | |
| 34 | export TMPDIR |
| 35 | |
| 36 | # temp directory to store the scan-build report |
| 37 | SCAN_BUILD_TMPDIR=$( mktemp -d ) |
| 38 | |
| 39 | # liburcu |
| 40 | URCU_INCS="$WORKSPACE/deps/liburcu/build/include/" |
| 41 | URCU_LIBS="$WORKSPACE/deps/liburcu/build/lib/" |
| 42 | |
| 43 | # lttng-ust |
| 44 | UST_INCS="$WORKSPACE/deps/lttng-ust/build/include/" |
| 45 | UST_LIBS="$WORKSPACE/deps/lttng-ust/build/lib/" |
| 46 | |
| 47 | export CFLAGS="-O0 -g -DDEBUG" |
| 48 | |
| 49 | export CPPFLAGS="-I$URCU_INCS -I$UST_INCS" |
| 50 | export LDFLAGS="-L$URCU_LIBS -L$UST_LIBS" |
| 51 | export LD_LIBRARY_PATH="$URCU_LIBS:$UST_LIBS:${LD_LIBRARY_PATH:-}" |
| 52 | |
| 53 | # Enter the source directory |
| 54 | cd "$SRCDIR" |
| 55 | |
| 56 | # Run bootstrap in the source directory prior to configure |
| 57 | ./bootstrap |
| 58 | |
| 59 | |
| 60 | ./configure --prefix="$PREFIX" |
| 61 | |
| 62 | # generate the scan-build report |
| 63 | scan-build -k -o "${SCAN_BUILD_TMPDIR}" make -j "$(nproc)" |
| 64 | |
| 65 | # get the directory name of the report created by scan-build |
| 66 | SCAN_BUILD_REPORT=$(find "${SCAN_BUILD_TMPDIR}" -maxdepth 1 -not -empty -not -name "$(basename "${SCAN_BUILD_TMPDIR}")") |
| 67 | rc=$? |
| 68 | |
| 69 | if [ -z "${SCAN_BUILD_REPORT}" ]; then |
| 70 | echo ">>> No new bugs identified." |
| 71 | echo ">>> No scan-build report has been generated" |
| 72 | else |
| 73 | echo ">>> New scan-build report generated in ${SCAN_BUILD_REPORT}" |
| 74 | |
| 75 | if [ ! -d "${SCAN_BUILD_ARCHIVE}" ]; then |
| 76 | echo ">>> Creating scan-build archive directory" |
| 77 | mkdir "${SCAN_BUILD_ARCHIVE}" |
| 78 | else |
| 79 | echo ">>> Removing any previous scan-build reports from ${SCAN_BUILD_ARCHIVE}" |
| 80 | rm -f "${SCAN_BUILD_ARCHIVE}/*" |
| 81 | fi |
| 82 | |
| 83 | echo ">>> Archiving scan-build report to ${SCAN_BUILD_ARCHIVE}" |
| 84 | mv "${SCAN_BUILD_REPORT}"/* "${SCAN_BUILD_ARCHIVE}/" |
| 85 | |
| 86 | echo ">>> Removing any temporary files and directories" |
| 87 | rm -rf "${SCAN_BUILD_TMPDIR}" |
| 88 | fi |
| 89 | |
| 90 | exit ${rc} |