jjb: archive top-level test suite log
[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"
4afa623f 108LIBDIR="lib"
32dde2a3 109LIBDIR_ARCH="$LIBDIR"
4afa623f
MJ
110
111# RHEL and SLES both use lib64 but don't bother shipping a default autoconf
112# site config that matches this.
85322e5d
MJ
113if [[ ( -f /etc/redhat-release || -f /etc/SuSE-release || -f /etc/yocto-release ) ]]; then
114 # Detect the userspace bitness in a distro agnostic way
115 if file -L /bin/bash | grep '64-bit' >/dev/null 2>&1; then
116 LIBDIR_ARCH="${LIBDIR}64"
85322e5d 117 fi
4afa623f 118fi
275b59d2 119
07dafe32
MJ
120# Create tmp directory
121rm -rf "$TMPDIR"
122mkdir -p "$TMPDIR"
e6be9fb0 123
0e9967db 124export TMPDIR
72d087d4 125export CFLAGS="-g -O2"
0e9967db 126
6476f917
MJ
127# Set compiler variables
128case "$cc" in
129gcc)
130 export CC=gcc
131 export CXX=g++
132 ;;
0f505d21
MJ
133gcc-*)
134 export CC=gcc-${cc#gcc-}
135 export CXX=g++-${cc#gcc-}
6476f917
MJ
136 ;;
137clang)
138 export CC=clang
139 export CXX=clang++
140 ;;
0f505d21
MJ
141clang-*)
142 export CC=clang-${cc#clang-}
143 export CXX=clang++-${cc#clang-}
6476f917
MJ
144 ;;
145*)
146 if [ "x$cc" != "x" ]; then
147 export CC="$cc"
148 fi
149 ;;
150esac
151
1183a118 152if [ "x${CC:-}" != "x" ]; then
6476f917
MJ
153 echo "Selected compiler:"
154 "$CC" -v
155fi
156
c56b9301 157# Set platform variables
776b0d3d 158case "$platform" in
f0d7e5b1 159macos*)
a0b535b2
MJ
160 export MAKE=make
161 export TAR=tar
162 export NPROC="getconf _NPROCESSORS_ONLN"
221450b6 163 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
07dafe32 164 export CPPFLAGS="-I/opt/local/include"
221450b6 165 export LDFLAGS="-L/opt/local/lib"
00f7bb3f
MJ
166 export PYTHON="python3"
167 export PYTHON_CONFIG="python3-config"
221450b6 168 ;;
07dafe32 169
0f505d21 170freebsd*)
894db5f1
MJ
171 export MAKE=gmake
172 export TAR=tar
173 export NPROC="getconf _NPROCESSORS_ONLN"
174 export CPPFLAGS="-I/usr/local/include"
175 export LDFLAGS="-L/usr/local/lib"
176 export PYTHON="python3"
177 export PYTHON_CONFIG="python3-config"
178
179 # For bt 1.5
180 export YACC="bison -y"
181 ;;
182
87e41bca 183*)
a0b535b2
MJ
184 export MAKE=make
185 export TAR=tar
186 export NPROC=nproc
1f620ba0
MJ
187 export PYTHON="python3"
188 export PYTHON_CONFIG="python3-config"
87e41bca
MJ
189 ;;
190esac
191
51c9c62d
MJ
192# Print build env details
193print_os || true
194print_tooling || true
195
a0b535b2
MJ
196# Enter the source directory
197cd "$SRCDIR"
198
199# Run bootstrap in the source directory prior to configure
200./bootstrap
201
202# Get source version from configure script
203eval "$(grep '^PACKAGE_VERSION=' ./configure)"
07dafe32 204PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
a0b535b2 205
11ba7264 206# Enable dev mode by default for BT 2.0 builds
9201e00d
MJ
207export BABELTRACE_DEBUG_MODE=1
208export BABELTRACE_DEV_MODE=1
8130d845 209export BABELTRACE_MINIMAL_LOG_LEVEL=TRACE
11ba7264 210
07dafe32
MJ
211# Set configure options and environment variables for each build
212# configuration.
4afa623f 213CONF_OPTS=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH")
f0d7e5b1
MJ
214
215# -Werror is enabled by default in stable-2.0 but won't be in 2.1
216# Explicitly disable it for consistency.
217if vergte "$PACKAGE_VERSION" "2.0"; then
218 CONF_OPTS+=("--disable-Werror")
219fi
220
275b59d2
JRJ
221case "$conf" in
222static)
1f620ba0
MJ
223 echo "Static lib only configuration"
224
225 CONF_OPTS+=("--enable-static" "--disable-shared")
226
a0b535b2 227 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 228 CONF_OPTS+=("--enable-built-in-plugins")
a0b535b2 229 fi
275b59d2 230 ;;
1f620ba0 231
221450b6 232python-bindings)
1f620ba0
MJ
233 echo "Python bindings configuration"
234
235 CONF_OPTS+=("--enable-python-bindings")
a0b535b2
MJ
236
237 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 238 CONF_OPTS+=("--enable-python-bindings-doc" "--enable-python-plugins")
a0b535b2 239 fi
275b59d2 240 ;;
1f620ba0 241
0d30552d 242prod)
1f620ba0 243 echo "Production configuration"
9201e00d
MJ
244
245 # Unset the developper variables
246 unset BABELTRACE_DEBUG_MODE
247 unset BABELTRACE_DEV_MODE
248 unset BABELTRACE_MINIMAL_LOG_LEVEL
249
250 # Enable the python bindings
301b8fc9
MJ
251 CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins")
252 ;;
253
254doc)
255 echo "Documentation configuration"
256
257 CONF_OPTS+=("--enable-python-bindings" "--enable-python-bindings-doc" "--enable-python-plugins" "--enable-api-doc")
9201e00d 258 ;;
1f620ba0 259
1b232bc6
SM
260asan)
261 echo "Address Sanitizer configuration"
262
263 # --enable-asan was introduced after 2.0 but don't check the version, we
264 # want this configuration to fail if ASAN is unavailable.
265 CONF_OPTS+=("--enable-asan" "--enable-python-bindings" "--enable-python-plugins")
266 ;;
267
0d30552d 268min)
1f620ba0 269 echo "Minimal configuration"
0d30552d 270 ;;
1f620ba0 271
275b59d2 272*)
1f620ba0 273 echo "Standard configuration"
0d30552d 274
1f620ba0 275 # Enable the python bindings / plugins by default with babeltrace2,
0d30552d
MJ
276 # the test suite is mostly useless without it.
277 if vergte "$PACKAGE_VERSION" "2.0"; then
1f620ba0 278 CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins")
0d30552d 279 fi
6871000c
MJ
280
281 # Something is broken in docbook-xml on yocto
282 if [[ "$platform" = yocto* ]]; then
283 CONF_OPTS+=("--disable-man-pages")
284 fi
275b59d2
JRJ
285 ;;
286esac
287
aad6ac90 288# Build type
07dafe32
MJ
289# oot : out-of-tree build
290# dist : build via make dist
291# oot-dist: build via make dist out-of-tree
292# * : normal tree build
aad6ac90 293#
07dafe32 294# Make sure to move to the build directory and run configure
1f620ba0 295# before continuing.
aad6ac90 296case "$build" in
b8475d72
MJ
297oot)
298 echo "Out of tree build"
299
300 # Create and enter a temporary build directory
301 builddir=$(mktemp -d)
302 cd "$builddir"
303
51c9c62d 304 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
b8475d72 305 ;;
1f620ba0 306
b8475d72
MJ
307dist)
308 echo "Distribution in-tree build"
1f620ba0 309
b8475d72
MJ
310 # Run configure and generate the tar file
311 # in the source directory
51c9c62d 312 ./configure || failed_configure
b8475d72 313 $MAKE dist
c56b9301 314
b8475d72
MJ
315 # Create and enter a temporary build directory
316 builddir=$(mktemp -d)
317 cd "$builddir"
318
319 # Extract the distribution tar in the build directory,
320 # ignore the first directory level
321 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
322
07dafe32 323 # Build in extracted source tree
51c9c62d 324 ./configure "${CONF_OPTS[@]}" || failed_configure
b8475d72 325 ;;
c56b9301 326
b8475d72
MJ
327oot-dist)
328 echo "Distribution out of tree build"
c56b9301 329
b8475d72
MJ
330 # Create and enter a temporary build directory
331 builddir=$(mktemp -d)
332 cd "$builddir"
c56b9301 333
b8475d72 334 # Run configure out of tree and generate the tar file
51c9c62d 335 "$SRCDIR/configure" || failed_configure
b8475d72 336 $MAKE dist
c56b9301 337
b8475d72
MJ
338 dist_srcdir="$(mktemp -d)"
339 cd "$dist_srcdir"
c56b9301 340
b8475d72
MJ
341 # Extract the distribution tar in the new source directory,
342 # ignore the first directory level
343 $TAR xvf "$builddir"/*.tar.* --strip 1
344
345 # Create and enter a second temporary build directory
346 builddir="$(mktemp -d)"
347 cd "$builddir"
348
349 # Run configure from the extracted distribution tar,
350 # out of the source tree
51c9c62d 351 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
b8475d72
MJ
352 ;;
353
354*)
355 echo "Standard in-tree build"
51c9c62d 356 ./configure "${CONF_OPTS[@]}" || failed_configure
b8475d72 357 ;;
aad6ac90
JR
358esac
359
1f620ba0
MJ
360# We are now inside a configured build directory
361
c56b9301 362# BUILD!
a57a60d9 363$MAKE -j "$($NPROC)" V=1
07dafe32
MJ
364
365# Install in the workspace
366$MAKE install DESTDIR="$WORKSPACE"
c56b9301 367
9d56171a 368# Run tests, don't fail now, we want to run the archiving steps
1d56e325 369failed_tests=0
e3c32202
JR
370if [ "$BABELTRACE_RUN_TESTS" = "yes" ]; then
371 $MAKE --keep-going check || failed_tests=1
372
373 # Copy tap logs for the jenkins tap parser before cleaning the build dir
374 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
375
4174b905
MJ
376 # Copy the test suites top-level log which includes all tests failures
377 rsync -a --include 'test-suite.log' --include '*/' --exclude='*' tests/ "$WORKSPACE/log"
378
e3c32202
JR
379 # The test suite prior to 1.5 did not produce TAP logs
380 if verlt "$PACKAGE_VERSION" "1.5"; then
381 mkdir -p "$WORKSPACE/tap/no-log"
382 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
383 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
384 fi
649c39a6
MJ
385fi
386
e6be9fb0
MJ
387# Clean the build directory
388$MAKE clean
275b59d2 389
c56b9301 390# Cleanup rpath in executables and shared libraries
07dafe32 391find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
4afa623f 392find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath --delete {} \;
c56b9301
MJ
393
394# Remove libtool .la files
4afa623f 395find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -exec rm -f {} \;
87e41bca 396
1d56e325
MJ
397# Exit with failure if any of the tests failed
398exit $failed_tests
9d56171a 399
87e41bca 400# EOF
This page took 0.051921 seconds and 4 git commands to generate.