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