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