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