jjb: lttng-tools: disable -Wmissing-field-initializers on el7
[lttng-ci.git] / scripts / lttng-tools / build.sh
CommitLineData
51c9c62d 1#!/bin/bash
09d45745 2# shellcheck disable=SC2103
b4005bbf 3#
09d45745 4# Copyright (C) 2016 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
7361d941 5# Copyright (C) 2016-2020 Michael Jeanson <mjeanson@efficios.com>
b4005bbf
MJ
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
51c9c62d
MJ
20set -exu
21
0cdaa21c 22# Version compare functions
b6e62a6a
MJ
23vercomp () {
24 set +u
25 if [[ "$1" == "$2" ]]; then
26 return 0
27 fi
28 local IFS=.
4afa623f
MJ
29 # Ignore the shellcheck warning, we want splitting to happen based on IFS.
30 # shellcheck disable=SC2206
b6e62a6a
MJ
31 local i ver1=($1) ver2=($2)
32 # fill empty fields in ver1 with zeros
33 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
34 ver1[i]=0
35 done
36 for ((i=0; i<${#ver1[@]}; i++)); do
37 if [[ -z ${ver2[i]} ]]; then
38 # fill empty fields in ver2 with zeros
39 ver2[i]=0
40 fi
41 if ((10#${ver1[i]} > 10#${ver2[i]})); then
42 return 1
43 fi
44 if ((10#${ver1[i]} < 10#${ver2[i]})); then
45 return 2
46 fi
47 done
48 set -u
49 return 0
50}
51
0cdaa21c 52verlte() {
b6e62a6a
MJ
53 vercomp "$1" "$2"; local res="$?"
54 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
0cdaa21c
MJ
55}
56
57verlt() {
b6e62a6a
MJ
58 vercomp "$1" "$2"; local res="$?"
59 [ "$res" -eq "2" ]
0cdaa21c
MJ
60}
61
62vergte() {
b6e62a6a
MJ
63 vercomp "$1" "$2"; local res="$?"
64 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
0cdaa21c
MJ
65}
66
67vergt() {
b6e62a6a
MJ
68 vercomp "$1" "$2"; local res="$?"
69 [ "$res" -eq "1" ]
70}
71
72verne() {
73 vercomp "$1" "$2"; local res="$?"
74 [ "$res" -ne "0" ]
0cdaa21c
MJ
75}
76
51c9c62d
MJ
77failed_configure() {
78 # Assume we are in the configured build directory
79 echo "#################### BEGIN config.log ####################"
80 cat config.log
81 echo "#################### END config.log ####################"
82
83 # End the build with failure
84 exit 1
85}
86
54c3c7ec
JR
87set_execute_traversal_bit()
88{
89 path=$1
90
91 level="$path"
92 if [ ! -d "$path" ]; then
93 fail "Path is not a directory"
94 fi
95 while level="$(dirname "$level")"
96 do
97 if [ "$level" = / ]; then
98 break
99 fi
100 chmod a+x "$level"
101 done
102 chmod a+x "$path"
103}
104
09d45745
MJ
105# Required variables
106WORKSPACE=${WORKSPACE:-}
107
5fcae288 108platform=${platform:-}
212d2afd
MJ
109conf=${conf:-}
110build=${build:-}
09d45745 111cc=${cc:-}
9699c0e7 112test_type=${test_type:-}
b4005bbf 113
4afa623f
MJ
114SRCDIR="$WORKSPACE/src/lttng-tools"
115TAPDIR="$WORKSPACE/tap"
116PREFIX="/build"
117LIBDIR="lib"
118
119# RHEL and SLES both use lib64 but don't bother shipping a default autoconf
120# site config that matches this.
121if [[ ( -f /etc/redhat-release || -f /etc/SuSE-release ) && ( "$(uname -m)" == "x86_64" ) ]]; then
122 LIBDIR_ARCH="${LIBDIR}64"
123else
124 LIBDIR_ARCH="$LIBDIR"
125fi
126
09d45745 127DEPS_INC="$WORKSPACE/deps/build/include"
4afa623f 128DEPS_LIB="$WORKSPACE/deps/build/$LIBDIR_ARCH"
b8bdba8f 129DEPS_PKGCONFIG="$DEPS_LIB/pkgconfig"
09d45745
MJ
130DEPS_BIN="$WORKSPACE/deps/build/bin"
131DEPS_JAVA="$WORKSPACE/deps/build/share/java"
132
133export PATH="$DEPS_BIN:$PATH"
134export LD_LIBRARY_PATH="$DEPS_LIB:${LD_LIBRARY_PATH:-}"
b8bdba8f 135export PKG_CONFIG_PATH="$DEPS_PKGCONFIG"
09d45745
MJ
136export CPPFLAGS="-I$DEPS_INC"
137export LDFLAGS="-L$DEPS_LIB"
138
212d2afd 139
09d45745
MJ
140# Create tmp directory
141TMPDIR="$WORKSPACE/tmp"
142mkdir -p "$TMPDIR"
212d2afd 143
09d45745
MJ
144# Use a symlink in /tmp to point to the the tmp directory
145# inside the workspace, this is to work around the path length
146# limit of unix sockets which are created by the test suite.
147tmpdir="$(mktemp)"
148ln -sf "$TMPDIR" "$tmpdir"
149export TMPDIR="$tmpdir"
b4005bbf 150
481eadc8
JR
151# Create a symlink to "babeltrace" when the "babeltrace2" executable is found.
152# This is a temporary workaround until lttng-tools either allows the override of
153# the trace reader in its test suite or that we move to only supporting
154# babeltrace2
155if [ -x "$DEPS_BIN/babeltrace2" ]; then
65444f1c 156 ln -s "$DEPS_BIN/babeltrace2" "$DEPS_BIN/babeltrace"
481eadc8
JR
157fi
158
159# When using babeltrace2 make sure that it finds its plugins and
160# plugin-providers.
161export BABELTRACE_PLUGIN_PATH="$DEPS_LIB/babeltrace2/plugins/"
162export LIBBABELTRACE2_PLUGIN_PROVIDER_DIR="$DEPS_LIB/babeltrace2/plugin-providers/"
163
09d45745 164export CFLAGS="-g -O2"
fdb66460 165export CXXFLAGS="-g -O2"
b4005bbf 166
09d45745
MJ
167# Set compiler variables
168case "$cc" in
169gcc)
170 export CC=gcc
171 export CXX=g++
172 ;;
173gcc-4.8)
174 export CC=gcc-4.8
175 export CXX=g++-4.8
176 ;;
177gcc-5)
178 export CC=gcc-5
179 export CXX=g++-5
180 ;;
181gcc-6)
182 export CC=gcc-6
183 export CXX=g++-6
184 ;;
185gcc-7)
186 export CC=gcc-7
187 export CXX=g++-7
188 ;;
189gcc-8)
190 export CC=gcc-8
191 export CXX=g++-8
192 ;;
193clang)
194 export CC=clang
195 export CXX=clang++
196 ;;
197clang-3.9)
198 export CC=clang-3.9
199 export CXX=clang++-3.9
200 ;;
201clang-4.0)
202 export CC=clang-4.0
203 export CXX=clang++-4.0
204 ;;
205clang-5.0)
206 export CC=clang-5.0
207 export CXX=clang++-5.0
208 ;;
209clang-6.0)
210 export CC=clang-6.0
211 export CXX=clang++-6.0
212 ;;
213clang-7)
214 export CC=clang-7
215 export CXX=clang++-7
216 ;;
217*)
218 if [ "x$cc" != "x" ]; then
65444f1c 219 export CC="$cc"
09d45745
MJ
220 fi
221 ;;
222esac
b4005bbf 223
09d45745
MJ
224if [ "x${CC:-}" != "x" ]; then
225 echo "Selected compiler:"
226 "$CC" -v
227fi
b4005bbf 228
0cdaa21c 229# Set platform variables
5fcae288 230case "$platform" in
f0d7e5b1 231macos*)
09d45745
MJ
232 export MAKE=make
233 export TAR=tar
234 export NPROC="getconf _NPROCESSORS_ONLN"
235 export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
236 export CPPFLAGS="-I/opt/local/include $CPPFLAGS"
237 export LDFLAGS="-L/opt/local/lib $LDFLAGS"
00f7bb3f
MJ
238 export PYTHON="python3"
239 export PYTHON_CONFIG="python3-config"
b6e62a6a 240
aff4e3d1 241 LTTNG_TOOLS_RUN_TESTS="no"
b6e62a6a
MJ
242 ;;
243
61afb3c3 244cygwin|cygwin64|msys32|msys64)
09d45745
MJ
245 export MAKE=make
246 export TAR=tar
247 export NPROC=nproc
248
aff4e3d1 249 LTTNG_TOOLS_RUN_TESTS="no"
61afb3c3
MJ
250 ;;
251
0cdaa21c 252*)
09d45745
MJ
253 export MAKE=make
254 export TAR=tar
255 export NPROC=nproc
256
aff4e3d1 257 LTTNG_TOOLS_RUN_TESTS="yes"
0cdaa21c
MJ
258
259 PYTHON2=python2
260 PYTHON3=python3
261
b4c6a892
MJ
262 if command -v $PYTHON2 >/dev/null 2>&1; then
263 P2_VERSION=$($PYTHON2 -c 'import sys;v = sys.version.split()[0].split("."); print("{}.{}".format(v[0], v[1]))')
4afa623f
MJ
264 DEPS_PYTHON2="$WORKSPACE/deps/build/$LIBDIR/python$P2_VERSION/site-packages"
265 if [ "$LIBDIR" != "$LIBDIR_ARCH" ]; then
266 DEPS_PYTHON2="$DEPS_PYTHON2:$WORKSPACE/deps/build/$LIBDIR_ARCH/python$P2_VERSION/site-packages"
267 fi
b4c6a892 268 fi
0cdaa21c 269
b4c6a892 270 P3_VERSION=$($PYTHON3 -c 'import sys;v = sys.version.split()[0].split("."); print("{}.{}".format(v[0], v[1]))')
4afa623f
MJ
271 DEPS_PYTHON3="$WORKSPACE/deps/build/$LIBDIR/python$P3_VERSION/site-packages"
272 if [ "$LIBDIR" != "$LIBDIR_ARCH" ]; then
273 DEPS_PYTHON3="$DEPS_PYTHON3:$WORKSPACE/deps/build/$LIBDIR_ARCH/python$P3_VERSION/site-packages"
274 fi
de7e8d55
JG
275
276 # Most build configs require access to the babeltrace 2 python bindings.
277 # This also makes the lttngust python agent available for `agents` builds.
278 export PYTHONPATH="${DEPS_PYTHON2:-}${DEPS_PYTHON2:+:}$DEPS_PYTHON3"
0cdaa21c
MJ
279 ;;
280esac
281
fdb66460 282# The missing-field-initializers warning code is very dumb in GCC 4.8 on
29d9c2b2
MJ
283# SLES12 / EL7, disable it even if it's available.
284if [[ $platform = sles12sp5* ]] || [[ $platform = el7* ]]; then
65444f1c
MJ
285 CFLAGS="$CFLAGS -Wno-missing-field-initializers"
286 CXXFLAGS="$CXXFLAGS -Wno-missing-field-initializers"
fdb66460
MJ
287fi
288
9699c0e7 289case "$test_type" in
9699c0e7 290full)
aff4e3d1 291 LTTNG_TOOLS_RUN_TESTS_LONG_REGRESSION="yes"
09d45745 292 ;;
9699c0e7 293*)
aff4e3d1 294 LTTNG_TOOLS_RUN_TESTS_LONG_REGRESSION="no"
09d45745 295 ;;
9699c0e7 296esac
0cdaa21c 297
7361d941
MJ
298# If we have modules, build them
299if [ -d "$WORKSPACE/src/lttng-modules" ]; then
300 cd "$WORKSPACE/src/lttng-modules"
301 $MAKE -j"$($NPROC)" V=1
302 $MAKE modules_install V=1
303 depmod
304fi
305
51c9c62d
MJ
306# Print build env details
307print_os || true
308print_tooling || true
309
212d2afd
MJ
310# Enter the source directory
311cd "$SRCDIR"
312
313# Run bootstrap in the source directory prior to configure
0cdaa21c
MJ
314./bootstrap
315
316# Get source version from configure script
212d2afd 317eval "$(grep '^PACKAGE_VERSION=' ./configure)"
09d45745 318PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
0cdaa21c 319
b4005bbf 320
0cdaa21c
MJ
321# The switch to build without UST changed in 2.8
322if vergte "$PACKAGE_VERSION" "2.8"; then
323 NO_UST="--without-lttng-ust"
324else
325 NO_UST="--disable-lttng-ust"
326fi
b4005bbf 327
6c3ec80e 328# Most build configs require the python bindings
4afa623f 329CONF_OPTS=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH" "--enable-python-bindings")
6c3ec80e 330
edb933dd
MJ
331DIST_CONF_OPTS=()
332
09d45745
MJ
333# Set configure options and environment variables for each build
334# configuration.
b4005bbf 335case "$conf" in
0cdaa21c 336static)
09d45745
MJ
337 echo "Static lib only configuration"
338
339 CONF_OPTS+=("--enable-static" "--disable-shared")
0cdaa21c
MJ
340 ;;
341
0cdaa21c
MJ
342no-ust)
343 echo "Build without UST support"
09d45745 344 CONF_OPTS+=("$NO_UST")
edb933dd 345 DIST_CONF_OPTS+=("$NO_UST")
0cdaa21c
MJ
346 ;;
347
67122b96 348agents)
09d45745
MJ
349 echo "Java and Python agents configuration"
350
0cdaa21c 351 export JAVA_HOME="/usr/lib/jvm/default-java"
61c5ba32 352 export CLASSPATH="$DEPS_JAVA/lttng-ust-agent-all.jar:/usr/share/java/log4j-api.jar:/usr/share/java/log4j-core.jar:/usr/share/java/log4j-1.2.jar"
0cdaa21c 353
09d45745 354 CONF_OPTS+=("--enable-test-java-agent-all" "--enable-test-python-agent-all")
d51c467a
MJ
355
356 # Explicitly add '--enable-test-java-agent-log4j2', it's not part of '-all' in stable 2.12/2.13
357 if verlt "$PACKAGE_VERSION" "2.14"; then
358 CONF_OPTS+=("--enable-test-java-agent-log4j2")
359 fi
0cdaa21c
MJ
360 ;;
361
362relayd-only)
09d45745
MJ
363 echo "Relayd only configuration"
364
365 CONF_OPTS=("--prefix=$PREFIX" "--disable-bin-lttng" "--disable-bin-lttng-consumerd" "--disable-bin-lttng-crash" "--disable-bin-lttng-sessiond" "--disable-extras" "--disable-man-pages" "$NO_UST")
0cdaa21c
MJ
366 ;;
367
22780fe6
JR
368debug-rcu)
369 echo "Enable RCU sanity checks for debugging"
09d45745
MJ
370
371 export CPPFLAGS="$CPPFLAGS -DDEBUG_RCU"
22780fe6
JR
372 ;;
373
0cdaa21c 374*)
09d45745 375 echo "Standard configuration"
6871000c
MJ
376
377 # Something is broken in docbook-xml on yocto
378 if [[ "$platform" = yocto* ]]; then
379 CONF_OPTS+=("--disable-man-pages")
380 fi
0cdaa21c 381 ;;
b4005bbf
MJ
382esac
383
384# Build type
67122b96
MJ
385# oot : out-of-tree build
386# dist : build via make dist
387# oot-dist: build via make dist out-of-tree
388# * : normal tree build
b4005bbf 389#
09d45745
MJ
390# Make sure to move to the build directory and run configure
391# before continuing.
b4005bbf 392case "$build" in
09d45745
MJ
393oot)
394 echo "Out of tree build"
395
396 # Create and enter a temporary build directory
397 builddir=$(mktemp -d)
398 cd "$builddir"
399
51c9c62d 400 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
09d45745
MJ
401 ;;
402
403dist)
404 echo "Distribution in-tree build"
405
406 # Run configure and generate the tar file
407 # in the source directory
51c9c62d 408 ./configure "${DIST_CONF_OPTS[@]}" || failed_configure
09d45745
MJ
409 $MAKE dist
410
411 # Create and enter a temporary build directory
412 builddir=$(mktemp -d)
413 cd "$builddir"
414
415 # Extract the distribution tar in the build directory,
416 # ignore the first directory level
417 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
418
419 # Build in extracted source tree
51c9c62d 420 ./configure "${CONF_OPTS[@]}" || failed_configure
09d45745
MJ
421 ;;
422
423oot-dist)
424 echo "Distribution out of tree build"
425
426 # Create and enter a temporary build directory
427 builddir=$(mktemp -d)
428 cd "$builddir"
429
430 # Run configure out of tree and generate the tar file
51c9c62d 431 "$SRCDIR/configure" "${DIST_CONF_OPTS[@]}" || failed_configure
09d45745
MJ
432 $MAKE dist
433
434 dist_srcdir="$(mktemp -d)"
435 cd "$dist_srcdir"
436
437 # Extract the distribution tar in the new source directory,
438 # ignore the first directory level
439 $TAR xvf "$builddir"/*.tar.* --strip 1
440
441 # Create and enter a second temporary build directory
442 builddir="$(mktemp -d)"
443 cd "$builddir"
444
445 # Run configure from the extracted distribution tar,
446 # out of the source tree
51c9c62d 447 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
09d45745
MJ
448 ;;
449
450*)
451 echo "Standard in-tree build"
51c9c62d 452 ./configure "${CONF_OPTS[@]}" || failed_configure
09d45745 453 ;;
b4005bbf
MJ
454esac
455
09d45745
MJ
456# We are now inside a configured build directory
457
0cdaa21c 458# BUILD!
212d2afd 459$MAKE -j "$($NPROC)" V=1
b4005bbf 460
09d45745
MJ
461# Install in the workspace
462$MAKE install DESTDIR="$WORKSPACE"
7671741c 463
09d45745
MJ
464# Run tests for all configs except 'no-ust'
465failed_tests=0
aff4e3d1 466if [ "$LTTNG_TOOLS_RUN_TESTS" = "yes" ] && [ "$conf" != "no-ust" ]; then
0cdaa21c
MJ
467 # Allow core dumps
468 ulimit -c unlimited
469
a4e98cc0
JR
470 # Force the lttng-sessiond path to /bin/true to prevent the spawing of a
471 # lttng-sessiond --daemonize on "lttng create"
472 export LTTNG_SESSIOND_PATH="/bin/true"
473
09d45745
MJ
474 # Run 'unit_tests', 2.8 and up has a new test suite
475 if vergte "$PACKAGE_VERSION" "2.8"; then
65444f1c
MJ
476 # It is implied that tests depending on LTTNG_ENABLE_DESTRUCTIVE_TESTS
477 # only run for the root user. Note that here `destructive` means that
478 # operations are performed at the host level (add user etc.) that
479 # effectively modify the host. Running those tests are acceptable on our
480 # CI and root jobs since we always run root tests against a `snapshot`
481 # of the host.
482 if [ "$(id -u)" == "0" ]; then
483 # Allow the traversal of all directories leading to the
484 # DEPS_LIBS directory to enable test app run by temp users to
485 # access lttng-ust.
486 set_execute_traversal_bit "$DEPS_LIB"
487 # Allow `all` to interact with all deps libs.
488 chmod a+rwx -R "$DEPS_LIB"
489
490 export LTTNG_ENABLE_DESTRUCTIVE_TESTS="will-break-my-system"
491
492 # Some destructive tests play with the system clock, disable timesyncd
493 systemctl stop systemd-timesyncd.service || true
494 fi
495
09d45745
MJ
496 make --keep-going check || failed_tests=1
497 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$TAPDIR"
0cdaa21c 498 else
09d45745
MJ
499 cd tests
500 mkdir -p "$TAPDIR/unit"
501 mkdir -p "$TAPDIR/fast_regression"
502 mkdir -p "$TAPDIR/with_bindings_regression"
503 prove --merge -v --exec '' - < unit_tests --archive "$TAPDIR/unit/" || failed_tests=1
504 prove --merge -v --exec '' - < fast_regression --archive "$TAPDIR/fast_regression/" || failed_tests=1
505 prove --merge -v --exec '' - < with_bindings_regression --archive "$TAPDIR/with_bindings_regression/" || failed_tests=1
65444f1c 506 cd ..
09d45745
MJ
507 fi
508
aff4e3d1 509 if [ "$LTTNG_TOOLS_RUN_TESTS_LONG_REGRESSION" = "yes" ]; then
09d45745
MJ
510 cd tests
511 mkdir -p "$TAPDIR/long_regression"
512 prove --merge -v --exec '' - < long_regression --archive "$TAPDIR/long_regression/" || failed_tests=1
65444f1c 513 cd ..
0cdaa21c
MJ
514 fi
515
0cdaa21c 516 # TAP plugin is having a hard time with .yml files.
212d2afd 517 find "$TAPDIR" -name "meta.yml" -exec rm -f {} \;
09d45745
MJ
518else
519 # The TAP plugin will fail the job if no test logs are present
520 mkdir -p "$TAPDIR/no-tests"
521 echo "1..1" > "$TAPDIR/no-tests/tests.log"
522 echo "ok 1 - Test suite disabled" >> "$TAPDIR/no-tests/tests.log"
b4005bbf
MJ
523fi
524
09d45745 525# Clean the build directory
0cdaa21c 526$MAKE clean
b4005bbf 527
0a059dd4 528# Cleanup rpath in executables
09d45745 529find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
0cdaa21c 530
0a059dd4 531# Some configs don't build liblttng-ctl
4afa623f 532if [ -d "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" ]; then
0a059dd4 533 # Cleanup rpath in shared libraries
4afa623f 534 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath --delete {} \;
0a059dd4 535 # Remove libtool .la files
4afa623f 536 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -exec rm -f {} \;
0a059dd4 537fi
b4005bbf 538
09d45745
MJ
539# Exit with failure if any of the tests failed
540exit $failed_tests
95654431
MJ
541
542# EOF
This page took 0.054284 seconds and 4 git commands to generate.