jjb: babeltrace: use --enable-asan (on some builds)
[lttng-ci.git] / scripts / babeltrace / build.sh
CommitLineData
51c9c62d 1#!/bin/bash
890bff23 2#
9d56171a 3# Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
51c9c62d 4# Copyright (C) 2016-2020 Michael Jeanson <mjeanson@efficios.com>
890bff23
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
19set -exu
20
a0b535b2
MJ
21# Version compare functions
22vercomp () {
23 set +u
24 if [[ "$1" == "$2" ]]; then
25 return 0
26 fi
27 local IFS=.
6946ebc0
SM
28 # Ignore the shellcheck warning, we want splitting to happen based on IFS.
29 # shellcheck disable=SC2206
a0b535b2
MJ
30 local i ver1=($1) ver2=($2)
31 # fill empty fields in ver1 with zeros
32 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
33 ver1[i]=0
34 done
35 for ((i=0; i<${#ver1[@]}; i++)); do
36 if [[ -z ${ver2[i]} ]]; then
37 # fill empty fields in ver2 with zeros
38 ver2[i]=0
39 fi
40 if ((10#${ver1[i]} > 10#${ver2[i]})); then
41 return 1
42 fi
43 if ((10#${ver1[i]} < 10#${ver2[i]})); then
44 return 2
45 fi
46 done
47 set -u
48 return 0
49}
50
6946ebc0
SM
51# Shellcheck flags the following functions that are unused as "unreachable",
52# ignore that.
53
54# shellcheck disable=SC2317
a0b535b2 55verlte() {
6946ebc0
SM
56 vercomp "$1" "$2"
57 local res="$?"
a0b535b2
MJ
58 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
59}
60
6946ebc0 61# shellcheck disable=SC2317
a0b535b2
MJ
62verlt() {
63 vercomp "$1" "$2"; local res="$?"
64 [ "$res" -eq "2" ]
65}
66
6946ebc0 67# shellcheck disable=SC2317
a0b535b2
MJ
68vergte() {
69 vercomp "$1" "$2"; local res="$?"
70 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
71}
72
6946ebc0 73# shellcheck disable=SC2317
a0b535b2
MJ
74vergt() {
75 vercomp "$1" "$2"; local res="$?"
76 [ "$res" -eq "1" ]
77}
78
6946ebc0 79# shellcheck disable=SC2317
a0b535b2
MJ
80verne() {
81 vercomp "$1" "$2"; local res="$?"
82 [ "$res" -ne "0" ]
83}
84
51c9c62d
MJ
85failed_configure() {
86 # Assume we are in the configured build directory
87 echo "#################### BEGIN config.log ####################"
88 cat config.log
89 echo "#################### END config.log ####################"
90 exit 1
91}
92
93
07dafe32
MJ
94# Required variables
95WORKSPACE=${WORKSPACE:-}
96
776b0d3d 97platform=${platform:-}
a57a60d9
MJ
98conf=${conf:-}
99build=${build:-}
6476f917 100cc=${cc:-}
a57a60d9 101
e3c32202
JR
102# Controls if the tests are run
103BABELTRACE_RUN_TESTS="${BABELTRACE_RUN_TESTS:=yes}"
c56b9301 104
e6be9fb0
MJ
105SRCDIR="$WORKSPACE/src/babeltrace"
106TMPDIR="$WORKSPACE/tmp"
07dafe32 107PREFIX="/build"
275b59d2 108
07dafe32
MJ
109# Create tmp directory
110rm -rf "$TMPDIR"
111mkdir -p "$TMPDIR"
e6be9fb0 112
0e9967db 113export TMPDIR
72d087d4 114export CFLAGS="-g -O2"
0e9967db 115
6476f917
MJ
116# Set compiler variables
117case "$cc" in
118gcc)
119 export CC=gcc
120 export CXX=g++
121 ;;
0f505d21
MJ
122gcc-*)
123 export CC=gcc-${cc#gcc-}
124 export CXX=g++-${cc#gcc-}
6476f917
MJ
125 ;;
126clang)
127 export CC=clang
128 export CXX=clang++
129 ;;
0f505d21
MJ
130clang-*)
131 export CC=clang-${cc#clang-}
132 export CXX=clang++-${cc#clang-}
6476f917
MJ
133 ;;
134*)
135 if [ "x$cc" != "x" ]; then
136 export CC="$cc"
137 fi
138 ;;
139esac
140
1183a118 141if [ "x${CC:-}" != "x" ]; then
6476f917
MJ
142 echo "Selected compiler:"
143 "$CC" -v
144fi
145
c56b9301 146# Set platform variables
776b0d3d 147case "$platform" in
f0d7e5b1 148macos*)
a0b535b2
MJ
149 export MAKE=make
150 export TAR=tar
151 export NPROC="getconf _NPROCESSORS_ONLN"
221450b6 152 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
07dafe32 153 export CPPFLAGS="-I/opt/local/include"
221450b6 154 export LDFLAGS="-L/opt/local/lib"
00f7bb3f
MJ
155 export PYTHON="python3"
156 export PYTHON_CONFIG="python3-config"
221450b6 157 ;;
07dafe32 158
0f505d21 159freebsd*)
894db5f1
MJ
160 export MAKE=gmake
161 export TAR=tar
162 export NPROC="getconf _NPROCESSORS_ONLN"
163 export CPPFLAGS="-I/usr/local/include"
164 export LDFLAGS="-L/usr/local/lib"
165 export PYTHON="python3"
166 export PYTHON_CONFIG="python3-config"
167
168 # For bt 1.5
169 export YACC="bison -y"
170 ;;
171
87e41bca 172*)
a0b535b2
MJ
173 export MAKE=make
174 export TAR=tar
175 export NPROC=nproc
1f620ba0
MJ
176 export PYTHON="python3"
177 export PYTHON_CONFIG="python3-config"
87e41bca
MJ
178 ;;
179esac
180
51c9c62d
MJ
181# Print build env details
182print_os || true
183print_tooling || true
184
a0b535b2
MJ
185# Enter the source directory
186cd "$SRCDIR"
187
188# Run bootstrap in the source directory prior to configure
189./bootstrap
190
191# Get source version from configure script
192eval "$(grep '^PACKAGE_VERSION=' ./configure)"
07dafe32 193PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
a0b535b2 194
11ba7264 195# Enable dev mode by default for BT 2.0 builds
9201e00d
MJ
196export BABELTRACE_DEBUG_MODE=1
197export BABELTRACE_DEV_MODE=1
8130d845 198export BABELTRACE_MINIMAL_LOG_LEVEL=TRACE
11ba7264 199
07dafe32
MJ
200# Set configure options and environment variables for each build
201# configuration.
202CONF_OPTS=("--prefix=$PREFIX")
f0d7e5b1
MJ
203
204# -Werror is enabled by default in stable-2.0 but won't be in 2.1
205# Explicitly disable it for consistency.
206if vergte "$PACKAGE_VERSION" "2.0"; then
207 CONF_OPTS+=("--disable-Werror")
208fi
209
275b59d2
JRJ
210case "$conf" in
211static)
1f620ba0
MJ
212 echo "Static lib only configuration"
213
214 CONF_OPTS+=("--enable-static" "--disable-shared")
215
a0b535b2 216 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 217 CONF_OPTS+=("--enable-built-in-plugins")
a0b535b2 218 fi
275b59d2 219 ;;
1f620ba0 220
221450b6 221python-bindings)
1f620ba0
MJ
222 echo "Python bindings configuration"
223
224 CONF_OPTS+=("--enable-python-bindings")
a0b535b2
MJ
225
226 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 227 CONF_OPTS+=("--enable-python-bindings-doc" "--enable-python-plugins")
a0b535b2 228 fi
275b59d2 229 ;;
1f620ba0 230
0d30552d 231prod)
1f620ba0 232 echo "Production configuration"
9201e00d
MJ
233
234 # Unset the developper variables
235 unset BABELTRACE_DEBUG_MODE
236 unset BABELTRACE_DEV_MODE
237 unset BABELTRACE_MINIMAL_LOG_LEVEL
238
239 # Enable the python bindings
301b8fc9
MJ
240 CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins")
241 ;;
242
243doc)
244 echo "Documentation configuration"
245
246 CONF_OPTS+=("--enable-python-bindings" "--enable-python-bindings-doc" "--enable-python-plugins" "--enable-api-doc")
9201e00d 247 ;;
1f620ba0 248
1b232bc6
SM
249asan)
250 echo "Address Sanitizer configuration"
251
252 # --enable-asan was introduced after 2.0 but don't check the version, we
253 # want this configuration to fail if ASAN is unavailable.
254 CONF_OPTS+=("--enable-asan" "--enable-python-bindings" "--enable-python-plugins")
255 ;;
256
0d30552d 257min)
1f620ba0 258 echo "Minimal configuration"
0d30552d 259 ;;
1f620ba0 260
275b59d2 261*)
1f620ba0 262 echo "Standard configuration"
0d30552d 263
1f620ba0 264 # Enable the python bindings / plugins by default with babeltrace2,
0d30552d
MJ
265 # the test suite is mostly useless without it.
266 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 267 CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins")
0d30552d 268 fi
275b59d2
JRJ
269 ;;
270esac
271
aad6ac90 272# Build type
07dafe32
MJ
273# oot : out-of-tree build
274# dist : build via make dist
275# oot-dist: build via make dist out-of-tree
276# * : normal tree build
aad6ac90 277#
07dafe32 278# Make sure to move to the build directory and run configure
1f620ba0 279# before continuing.
aad6ac90 280case "$build" in
b8475d72
MJ
281oot)
282 echo "Out of tree build"
283
284 # Create and enter a temporary build directory
285 builddir=$(mktemp -d)
286 cd "$builddir"
287
51c9c62d 288 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
b8475d72 289 ;;
1f620ba0 290
b8475d72
MJ
291dist)
292 echo "Distribution in-tree build"
1f620ba0 293
b8475d72
MJ
294 # Run configure and generate the tar file
295 # in the source directory
51c9c62d 296 ./configure || failed_configure
b8475d72 297 $MAKE dist
c56b9301 298
b8475d72
MJ
299 # Create and enter a temporary build directory
300 builddir=$(mktemp -d)
301 cd "$builddir"
302
303 # Extract the distribution tar in the build directory,
304 # ignore the first directory level
305 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
306
07dafe32 307 # Build in extracted source tree
51c9c62d 308 ./configure "${CONF_OPTS[@]}" || failed_configure
b8475d72 309 ;;
c56b9301 310
b8475d72
MJ
311oot-dist)
312 echo "Distribution out of tree build"
c56b9301 313
b8475d72
MJ
314 # Create and enter a temporary build directory
315 builddir=$(mktemp -d)
316 cd "$builddir"
c56b9301 317
b8475d72 318 # Run configure out of tree and generate the tar file
51c9c62d 319 "$SRCDIR/configure" || failed_configure
b8475d72 320 $MAKE dist
c56b9301 321
b8475d72
MJ
322 dist_srcdir="$(mktemp -d)"
323 cd "$dist_srcdir"
c56b9301 324
b8475d72
MJ
325 # Extract the distribution tar in the new source directory,
326 # ignore the first directory level
327 $TAR xvf "$builddir"/*.tar.* --strip 1
328
329 # Create and enter a second temporary build directory
330 builddir="$(mktemp -d)"
331 cd "$builddir"
332
333 # Run configure from the extracted distribution tar,
334 # out of the source tree
51c9c62d 335 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
b8475d72
MJ
336 ;;
337
338*)
339 echo "Standard in-tree build"
51c9c62d 340 ./configure "${CONF_OPTS[@]}" || failed_configure
b8475d72 341 ;;
aad6ac90
JR
342esac
343
1f620ba0
MJ
344# We are now inside a configured build directory
345
c56b9301 346# BUILD!
a57a60d9 347$MAKE -j "$($NPROC)" V=1
07dafe32
MJ
348
349# Install in the workspace
350$MAKE install DESTDIR="$WORKSPACE"
c56b9301 351
9d56171a 352# Run tests, don't fail now, we want to run the archiving steps
1d56e325 353failed_tests=0
e3c32202
JR
354if [ "$BABELTRACE_RUN_TESTS" = "yes" ]; then
355 $MAKE --keep-going check || failed_tests=1
356
357 # Copy tap logs for the jenkins tap parser before cleaning the build dir
358 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
359
360 # The test suite prior to 1.5 did not produce TAP logs
361 if verlt "$PACKAGE_VERSION" "1.5"; then
362 mkdir -p "$WORKSPACE/tap/no-log"
363 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
364 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
365 fi
649c39a6
MJ
366fi
367
e6be9fb0
MJ
368# Clean the build directory
369$MAKE clean
275b59d2 370
c56b9301 371# Cleanup rpath in executables and shared libraries
07dafe32
MJ
372find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
373find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
c56b9301
MJ
374
375# Remove libtool .la files
07dafe32 376find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
87e41bca 377
1d56e325
MJ
378# Exit with failure if any of the tests failed
379exit $failed_tests
9d56171a 380
87e41bca 381# EOF
This page took 0.04952 seconds and 4 git commands to generate.