jjb: Update scan-build script
[lttng-ci.git] / scripts / common / scan-build.sh
CommitLineData
a57a60d9 1#!/bin/bash -exu
2b68721a 2#
ae3ca8a0
MJ
3# Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4# Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com>
2b68721a
MJ
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
21set +e
1f4fba8c 22
69f05d59 23SRCDIR="$WORKSPACE/src/$PROJECT_NAME"
1f4fba8c 24TMPDIR="$WORKSPACE/tmp"
ae3ca8a0
MJ
25
26NPROC=$(nproc)
27export CFLAGS="-O0 -g -DDEBUG"
1f4fba8c
MJ
28
29# Directory to archive the scan-build report
2b68721a
MJ
30SCAN_BUILD_ARCHIVE="${WORKSPACE}/scan-build-archive"
31
ae3ca8a0
MJ
32# Create tmp directory
33rm -rf "$TMPDIR"
34mkdir -p "$TMPDIR"
1f4fba8c
MJ
35
36export TMPDIR
37
38# temp directory to store the scan-build report
39SCAN_BUILD_TMPDIR=$( mktemp -d )
2b68721a 40
ae3ca8a0
MJ
41case "$PROJECT_NAME" in
42babeltrace)
43 export BABELTRACE_DEV_MODE=1
44 CONF_OPTS="--enable-python-bindings --enable-python-bindings-doc --enable-python-plugins"
45 BUILD_TYPE="autotools"
46 ;;
47liburcu)
48 CONF_OPTS=""
49 BUILD_TYPE="autotools"
50 ;;
51lttng-modules)
52 CONF_OPTS=""
53 BUILD_TYPE="autotools"
54 ;;
55lttng-tools)
56 CONF_OPTS=""
57 BUILD_TYPE="autotools"
58 ;;
59lttng-ust)
60 CONF_OPTS="--enable-java-agent-all --enable-python-agent"
61 BUILD_TYPE="autotools"
62 export CLASSPATH="/usr/share/java/log4j-1.2.jar"
63 ;;
64linux-rseq)
65 CONF_OPTS=""
66 BUILD_TYPE="linux-rseq"
67 ;;
68*)
69 echo "Generic project, no configure options."
70 CONF_OPTS=""
71 BUILD_TYPE="autotools"
72 ;;
73esac
74
75# liburcu dependency
76if [ -d "$WORKSPACE/deps/liburcu" ]; then
77 URCU_INCS="$WORKSPACE/deps/liburcu/build/include/"
78 URCU_LIBS="$WORKSPACE/deps/liburcu/build/lib/"
79
80 export CPPFLAGS="-I$URCU_INCS ${CPPFLAGS:-}"
81 export LDFLAGS="-L$URCU_LIBS ${LDFLAGS:-}"
82 export LD_LIBRARY_PATH="$URCU_LIBS:${LD_LIBRARY_PATH:-}"
83fi
c9b78c7b 84
69f05d59 85
ae3ca8a0
MJ
86# lttng-ust dependency
87if [ -d "$WORKSPACE/deps/lttng-ust" ]; then
88 UST_INCS="$WORKSPACE/deps/lttng-ust/build/include/"
89 UST_LIBS="$WORKSPACE/deps/lttng-ust/build/lib/"
69f05d59 90
ae3ca8a0
MJ
91 export CPPFLAGS="-I$UST_INCS ${CPPFLAGS:-}"
92 export LDFLAGS="-L$UST_LIBS ${LDFLAGS:-}"
93 export LD_LIBRARY_PATH="$UST_LIBS:${LD_LIBRARY_PATH:-}"
94fi
95
96if [ -d "$WORKSPACE/src/linux" ]; then
97 export KERNELDIR="$WORKSPACE/src/linux"
98fi
c9b78c7b 99
1f4fba8c
MJ
100# Enter the source directory
101cd "$SRCDIR"
2b68721a 102
ae3ca8a0
MJ
103# Build
104echo -e "\033[33;1mRunning Coverity Scan Analysis Tool...\033[0m"
105case "$BUILD_TYPE" in
106autotools)
107 # Prepare build dir for autotools based projects
108 if [ -f "./bootstrap" ]; then
109 ./bootstrap
110 ./configure $CONF_OPTS
111 fi
1f4fba8c 112
ae3ca8a0
MJ
113 scan-build -k -o "${SCAN_BUILD_TMPDIR}" make -j"$NPROC" V=1
114 ;;
115linux-rseq)
116 make defconfig
117 make -j"$NPROC" prepare
118 scan-build -k -o "${SCAN_BUILD_TMPDIR}" make -j"$NPROC" kernel/rseq.o kernel/do_on_cpu/core.o kernel/do_on_cpu/interpreter.o kernel/do_on_cpu/validate.o V=1
119 ;;
120*)
121 echo "Unsupported build type: $BUILD_TYPE"
122 exit 1
123 ;;
124esac
1f4fba8c 125
1f4fba8c 126
2b68721a 127# get the directory name of the report created by scan-build
69f05d59 128SCAN_BUILD_REPORT=$(find "${SCAN_BUILD_TMPDIR}" -maxdepth 1 -not -empty -not -name "$(basename "${SCAN_BUILD_TMPDIR}")")
2b68721a 129rc=$?
1f4fba8c 130
2b68721a
MJ
131if [ -z "${SCAN_BUILD_REPORT}" ]; then
132 echo ">>> No new bugs identified."
133 echo ">>> No scan-build report has been generated"
134else
135 echo ">>> New scan-build report generated in ${SCAN_BUILD_REPORT}"
1f4fba8c 136
2b68721a
MJ
137 if [ ! -d "${SCAN_BUILD_ARCHIVE}" ]; then
138 echo ">>> Creating scan-build archive directory"
1f4fba8c 139 mkdir "${SCAN_BUILD_ARCHIVE}"
2b68721a
MJ
140 else
141 echo ">>> Removing any previous scan-build reports from ${SCAN_BUILD_ARCHIVE}"
1f4fba8c 142 rm -f "${SCAN_BUILD_ARCHIVE}/*"
2b68721a 143 fi
1f4fba8c 144
2b68721a 145 echo ">>> Archiving scan-build report to ${SCAN_BUILD_ARCHIVE}"
69f05d59 146 mv "${SCAN_BUILD_REPORT}"/* "${SCAN_BUILD_ARCHIVE}/"
1f4fba8c 147
2b68721a
MJ
148 echo ">>> Removing any temporary files and directories"
149 rm -rf "${SCAN_BUILD_TMPDIR}"
150fi
1f4fba8c 151
2b68721a 152exit ${rc}
This page took 0.033642 seconds and 4 git commands to generate.