jjb: babeltrace: use clang-format-16
[lttng-ci.git] / scripts / lttng-tools / build.sh
CommitLineData
51c9c62d 1#!/bin/bash
b4005bbf 2#
1ad4c3d0
MJ
3# SPDX-FileCopyrightText: 2016 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4# SPDX-FileCopyrightText: 2016-2023 Michael Jeanson <mjeanson@efficios.com>
5# SPDX-License-Identifier: GPL-2.0-or-later
b4005bbf 6#
1ad4c3d0 7# shellcheck disable=SC2103
b4005bbf 8
51c9c62d
MJ
9set -exu
10
0cdaa21c 11# Version compare functions
b6e62a6a
MJ
12vercomp () {
13 set +u
14 if [[ "$1" == "$2" ]]; then
15 return 0
16 fi
17 local IFS=.
4afa623f
MJ
18 # Ignore the shellcheck warning, we want splitting to happen based on IFS.
19 # shellcheck disable=SC2206
b6e62a6a
MJ
20 local i ver1=($1) ver2=($2)
21 # fill empty fields in ver1 with zeros
22 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
23 ver1[i]=0
24 done
25 for ((i=0; i<${#ver1[@]}; i++)); do
26 if [[ -z ${ver2[i]} ]]; then
27 # fill empty fields in ver2 with zeros
28 ver2[i]=0
29 fi
30 if ((10#${ver1[i]} > 10#${ver2[i]})); then
31 return 1
32 fi
33 if ((10#${ver1[i]} < 10#${ver2[i]})); then
34 return 2
35 fi
36 done
37 set -u
38 return 0
39}
40
0cdaa21c 41verlte() {
b6e62a6a
MJ
42 vercomp "$1" "$2"; local res="$?"
43 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
0cdaa21c
MJ
44}
45
46verlt() {
b6e62a6a
MJ
47 vercomp "$1" "$2"; local res="$?"
48 [ "$res" -eq "2" ]
0cdaa21c
MJ
49}
50
51vergte() {
b6e62a6a
MJ
52 vercomp "$1" "$2"; local res="$?"
53 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
0cdaa21c
MJ
54}
55
56vergt() {
b6e62a6a
MJ
57 vercomp "$1" "$2"; local res="$?"
58 [ "$res" -eq "1" ]
59}
60
61verne() {
62 vercomp "$1" "$2"; local res="$?"
63 [ "$res" -ne "0" ]
0cdaa21c
MJ
64}
65
52be5739
KS
66mktemp_compat() {
67 case "$platform" in
68 macos*)
69 # On MacOSX, mktemp doesn't respect TMPDIR in the same way as many
70 # other systems. Use the final positional argument to force the
71 # tempfile or tempdir to be created inside $TMPDIR, which must
72 # already exist.
73 if [ -n "${TMPDIR}" ] ; then
74 mktemp "${@}" "${TMPDIR}/tmp.XXXXXXXXXX"
75 else
76 mktemp "${@}"
77 fi
78 ;;
79 *)
80 mktemp "${@}"
81 ;;
82 esac
83}
84
1ad4c3d0
MJ
85print_header() {
86 set +x
87
88 local message=" $1 "
89 local message_len
90 local padding_len
91
92 message_len="${#message}"
93 padding_len=$(( (80 - (message_len)) / 2 ))
94
95
96 printf '\n'; printf -- '#%.0s' {1..80}; printf '\n'
97 printf -- '-%.0s' {1..80}; printf '\n'
98 printf -- '#%.0s' $(seq 1 $padding_len); printf '%s' "$message"; printf -- '#%.0s' $(seq 1 $padding_len); printf '\n'
99 printf -- '-%.0s' {1..80}; printf '\n'
100 printf -- '#%.0s' {1..80}; printf '\n\n'
101
102 set -x
103}
104
51c9c62d
MJ
105failed_configure() {
106 # Assume we are in the configured build directory
1ad4c3d0 107 print_header "BEGIN config.log"
51c9c62d 108 cat config.log
1ad4c3d0 109 print_header "END config.log"
51c9c62d
MJ
110
111 # End the build with failure
112 exit 1
113}
114
54c3c7ec
JR
115set_execute_traversal_bit()
116{
117 path=$1
118
119 level="$path"
120 if [ ! -d "$path" ]; then
121 fail "Path is not a directory"
122 fi
123 while level="$(dirname "$level")"
124 do
125 if [ "$level" = / ]; then
126 break
127 fi
128 chmod a+x "$level"
129 done
130 chmod a+x "$path"
131}
132
1ad4c3d0
MJ
133print_header "LTTng-tools build script starting"
134
09d45745
MJ
135# Required variables
136WORKSPACE=${WORKSPACE:-}
137
1ad4c3d0 138# Axis
5fcae288 139platform=${platform:-}
212d2afd
MJ
140conf=${conf:-}
141build=${build:-}
09d45745 142cc=${cc:-}
1ad4c3d0
MJ
143
144# Build steps that can be overriden by the environment
145LTTNG_TOOLS_MAKE_INSTALL="${LTTNG_TOOLS_MAKE_INSTALL:-yes}"
146LTTNG_TOOLS_MAKE_CLEAN="${LTTNG_TOOLS_MAKE_CLEAN:-yes}"
147LTTNG_TOOLS_GEN_COMPILE_COMMANDS="${LTTNG_TOOLS_GEN_COMPILE_COMMANDS:-no}"
148LTTNG_TOOLS_RUN_TESTS="${LTTNG_TOOLS_RUN_TESTS:-yes}"
149LTTNG_TOOLS_RUN_TESTS_LONG_REGRESSION="${LTTNG_TOOLS_RUN_TESTS_LONG_REGRESSION:-no}"
80cc6268 150LTTNG_TOOLS_RUN_UST_JAVA_TESTS="${LTTNG_TOOLS_RUN_UST_JAVA_TESTS:-yes}"
1ad4c3d0 151LTTNG_TOOLS_CLANG_TIDY="${LTTNG_TOOLS_CLANG_TIDY:-no}"
b4005bbf 152
4afa623f
MJ
153SRCDIR="$WORKSPACE/src/lttng-tools"
154TAPDIR="$WORKSPACE/tap"
155PREFIX="/build"
156LIBDIR="lib"
32dde2a3 157LIBDIR_ARCH="$LIBDIR"
4afa623f
MJ
158
159# RHEL and SLES both use lib64 but don't bother shipping a default autoconf
160# site config that matches this.
47ca4354 161if [[ ( -f /etc/redhat-release || -f /etc/products.d/SLES.prod || -f /etc/yocto-release ) ]]; then
85322e5d
MJ
162 # Detect the userspace bitness in a distro agnostic way
163 if file -L /bin/bash | grep '64-bit' >/dev/null 2>&1; then
164 LIBDIR_ARCH="${LIBDIR}64"
85322e5d 165 fi
4afa623f
MJ
166fi
167
09d45745 168DEPS_INC="$WORKSPACE/deps/build/include"
4afa623f 169DEPS_LIB="$WORKSPACE/deps/build/$LIBDIR_ARCH"
b8bdba8f 170DEPS_PKGCONFIG="$DEPS_LIB/pkgconfig"
09d45745
MJ
171DEPS_BIN="$WORKSPACE/deps/build/bin"
172DEPS_JAVA="$WORKSPACE/deps/build/share/java"
173
174export PATH="$DEPS_BIN:$PATH"
175export LD_LIBRARY_PATH="$DEPS_LIB:${LD_LIBRARY_PATH:-}"
b8bdba8f 176export PKG_CONFIG_PATH="$DEPS_PKGCONFIG"
09d45745
MJ
177export CPPFLAGS="-I$DEPS_INC"
178export LDFLAGS="-L$DEPS_LIB"
179
1ad4c3d0
MJ
180exit_status=0
181
182# Use bear to generate compile_commands.json when enabled
183BEAR=""
184if [ "$LTTNG_TOOLS_GEN_COMPILE_COMMANDS" = "yes" ]; then
185 BEAR="bear"
186fi
212d2afd 187
09d45745
MJ
188# Create tmp directory
189TMPDIR="$WORKSPACE/tmp"
190mkdir -p "$TMPDIR"
212d2afd 191
09d45745
MJ
192# Use a symlink in /tmp to point to the the tmp directory
193# inside the workspace, this is to work around the path length
194# limit of unix sockets which are created by the test suite.
195tmpdir="$(mktemp)"
196ln -sf "$TMPDIR" "$tmpdir"
197export TMPDIR="$tmpdir"
b4005bbf 198
481eadc8
JR
199# Create a symlink to "babeltrace" when the "babeltrace2" executable is found.
200# This is a temporary workaround until lttng-tools either allows the override of
201# the trace reader in its test suite or that we move to only supporting
202# babeltrace2
203if [ -x "$DEPS_BIN/babeltrace2" ]; then
65444f1c 204 ln -s "$DEPS_BIN/babeltrace2" "$DEPS_BIN/babeltrace"
481eadc8
JR
205fi
206
207# When using babeltrace2 make sure that it finds its plugins and
208# plugin-providers.
209export BABELTRACE_PLUGIN_PATH="$DEPS_LIB/babeltrace2/plugins/"
210export LIBBABELTRACE2_PLUGIN_PROVIDER_DIR="$DEPS_LIB/babeltrace2/plugin-providers/"
211
09d45745 212export CFLAGS="-g -O2"
fdb66460 213export CXXFLAGS="-g -O2"
b4005bbf 214
09d45745
MJ
215# Set compiler variables
216case "$cc" in
217gcc)
218 export CC=gcc
219 export CXX=g++
220 ;;
1ad4c3d0
MJ
221gcc-*)
222 export CC=gcc-${cc#gcc-}
223 export CXX=g++-${cc#gcc-}
09d45745
MJ
224 ;;
225clang)
226 export CC=clang
227 export CXX=clang++
228 ;;
1ad4c3d0
MJ
229clang-*)
230 export CC=clang-${cc#clang-}
231 export CXX=clang++-${cc#clang-}
09d45745
MJ
232 ;;
233*)
234 if [ "x$cc" != "x" ]; then
1ad4c3d0 235 export CC="$cc"
09d45745
MJ
236 fi
237 ;;
238esac
b4005bbf 239
0cdaa21c 240# Set platform variables
5fcae288 241case "$platform" in
f0d7e5b1 242macos*)
09d45745
MJ
243 export MAKE=make
244 export TAR=tar
245 export NPROC="getconf _NPROCESSORS_ONLN"
246 export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
247 export CPPFLAGS="-I/opt/local/include $CPPFLAGS"
248 export LDFLAGS="-L/opt/local/lib $LDFLAGS"
00f7bb3f
MJ
249 export PYTHON="python3"
250 export PYTHON_CONFIG="python3-config"
b6e62a6a
MJ
251 ;;
252
61afb3c3 253cygwin|cygwin64|msys32|msys64)
09d45745
MJ
254 export MAKE=make
255 export TAR=tar
256 export NPROC=nproc
61afb3c3
MJ
257 ;;
258
0cdaa21c 259*)
09d45745
MJ
260 export MAKE=make
261 export TAR=tar
262 export NPROC=nproc
263
0cdaa21c
MJ
264 PYTHON2=python2
265 PYTHON3=python3
266
b4c6a892
MJ
267 if command -v $PYTHON2 >/dev/null 2>&1; then
268 P2_VERSION=$($PYTHON2 -c 'import sys;v = sys.version.split()[0].split("."); print("{}.{}".format(v[0], v[1]))')
4afa623f
MJ
269 DEPS_PYTHON2="$WORKSPACE/deps/build/$LIBDIR/python$P2_VERSION/site-packages"
270 if [ "$LIBDIR" != "$LIBDIR_ARCH" ]; then
271 DEPS_PYTHON2="$DEPS_PYTHON2:$WORKSPACE/deps/build/$LIBDIR_ARCH/python$P2_VERSION/site-packages"
272 fi
b4c6a892 273 fi
0cdaa21c 274
b4c6a892 275 P3_VERSION=$($PYTHON3 -c 'import sys;v = sys.version.split()[0].split("."); print("{}.{}".format(v[0], v[1]))')
05615fb2
MJ
276
277 # Temporary fix for an issue on debian python >= 3.10, add the 'local' prefix
278 DEPS_PYTHON3="$WORKSPACE/deps/build/$LIBDIR/python$P3_VERSION/site-packages:$WORKSPACE/deps/build/local/$LIBDIR/python$P3_VERSION/dist-packages"
4afa623f
MJ
279 if [ "$LIBDIR" != "$LIBDIR_ARCH" ]; then
280 DEPS_PYTHON3="$DEPS_PYTHON3:$WORKSPACE/deps/build/$LIBDIR_ARCH/python$P3_VERSION/site-packages"
281 fi
de7e8d55
JG
282
283 # Most build configs require access to the babeltrace 2 python bindings.
284 # This also makes the lttngust python agent available for `agents` builds.
285 export PYTHONPATH="${DEPS_PYTHON2:-}${DEPS_PYTHON2:+:}$DEPS_PYTHON3"
0cdaa21c
MJ
286 ;;
287esac
288
6843e673
MJ
289# Some warning flags are very dumb in GCC 4.8 on SLES12 / EL7, disable them
290# even if they are available.
29d9c2b2 291if [[ $platform = sles12sp5* ]] || [[ $platform = el7* ]]; then
6843e673
MJ
292 CFLAGS="$CFLAGS -Wno-missing-field-initializers -Wno-shadow"
293 CXXFLAGS="$CXXFLAGS -Wno-missing-field-initializers -Wno-shadow"
fdb66460
MJ
294fi
295
7361d941
MJ
296# If we have modules, build them
297if [ -d "$WORKSPACE/src/lttng-modules" ]; then
1ad4c3d0 298 print_header "Build and install LTTng-modules"
7361d941
MJ
299 cd "$WORKSPACE/src/lttng-modules"
300 $MAKE -j"$($NPROC)" V=1
301 $MAKE modules_install V=1
302 depmod
f81a4222
KS
303
304 if [[ -f /etc/products.d/SLES.prod ]] ; then
305 echo 'allow_unsupported_modules 1' > /etc/modprobe.d/10-unsupported-modules.conf
306 fi
7361d941
MJ
307fi
308
51c9c62d 309# Print build env details
1ad4c3d0 310print_header "Build environment details"
8c956c4b 311print_hardware || true
51c9c62d
MJ
312print_os || true
313print_tooling || true
314
212d2afd
MJ
315# Enter the source directory
316cd "$SRCDIR"
317
318# Run bootstrap in the source directory prior to configure
1ad4c3d0 319print_header "Bootstrap autotools"
0cdaa21c
MJ
320./bootstrap
321
322# Get source version from configure script
212d2afd 323eval "$(grep '^PACKAGE_VERSION=' ./configure)"
09d45745 324PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
0cdaa21c 325
1ad4c3d0
MJ
326CONF_OPTS=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH" "--disable-maintainer-mode")
327DIST_CONF_OPTS=("--disable-maintainer-mode")
edb933dd 328
09d45745
MJ
329# Set configure options and environment variables for each build
330# configuration.
b4005bbf 331case "$conf" in
0cdaa21c 332static)
1ad4c3d0 333 print_header "Conf: Static lib only"
09d45745 334
1ad4c3d0 335 CONF_OPTS+=("--enable-static" "--disable-shared" "--enable-python-bindings")
0cdaa21c
MJ
336 ;;
337
0cdaa21c 338no-ust)
1ad4c3d0 339 print_header "Conf: Without UST support"
2c34ea14 340
1ad4c3d0
MJ
341 CONF_OPTS+=("--without-lttng-ust")
342 DIST_CONF_OPTS+=("--without-lttng-ust")
0cdaa21c
MJ
343 ;;
344
67122b96 345agents)
1ad4c3d0 346 print_header "Conf: Java and Python agents"
09d45745 347
4a9fa8ba
KS
348 if [[ -z "${JAVA_HOME:-}" ]] ; then
349 export JAVA_HOME="/usr/lib/jvm/default-java"
350 fi
61c5ba32 351 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"
dc56017a 352 if [[ -f /etc/products.d/SLES.prod ]] ; then
ada7f884
KS
353 export JAVA_HOME="/usr/${LIBDIR_ARCH}/jvm/java-1.8.0-openjdk-1.8.0"
354 export PATH="/usr/${LIBDIR_ARCH}/jvm/java-1.8.0-openjdk-1.8.0/bin:/usr/${LIBDIR_ARCH}/jvm/jre-1.8.0-openjdk/bin:${PATH}"
dc56017a 355 SLES_VERSION="$(grep -E '</version>' /etc/products.d/SLES.prod | grep -E -o '[0-9]+\.[0-9]+')"
247873aa 356 if vergte "${SLES_VERSION}" "15.4" ; then
dc56017a
KS
357 export CLASSPATH="${DEPS_JAVA}/lttng-ust-agent-all.jar:/usr/share/java/log4j/log4j-api.jar:/usr/share/java/log4j/log4j-core.jar:/usr/share/java/log4j12/log4j-12.jar"
358 fi
359 fi
360
0cdaa21c 361
1ad4c3d0 362 CONF_OPTS+=("--enable-python-bindings" "--enable-test-java-agent-all")
d51c467a
MJ
363
364 # Explicitly add '--enable-test-java-agent-log4j2', it's not part of '-all' in stable 2.12/2.13
365 if verlt "$PACKAGE_VERSION" "2.14"; then
366 CONF_OPTS+=("--enable-test-java-agent-log4j2")
367 fi
b7b61fcb
MJ
368
369 # Some distros don't ship python2 anymore
370 if command -v $PYTHON2 >/dev/null 2>&1; then
371 CONF_OPTS+=("--enable-test-python-agent-all")
372 else
373 CONF_OPTS+=("--enable-test-python3-agent")
374 fi
0cdaa21c
MJ
375 ;;
376
377relayd-only)
1ad4c3d0 378 print_header "Conf: Relayd only"
09d45745 379
1ad4c3d0 380 CONF_OPTS+=("--disable-bin-lttng" "--disable-bin-lttng-consumerd" "--disable-bin-lttng-crash" "--disable-bin-lttng-sessiond" "--disable-extras" "--disable-man-pages" "--without-lttng-ust")
a2eb91f7
MJ
381
382 # A config option for lib-lttng-ctl was added in 2.14
383 if vergte "$PACKAGE_VERSION" "2.14"; then
384 CONF_OPTS+=("--disable-lib-lttng-ctl")
385 fi
0cdaa21c
MJ
386 ;;
387
22780fe6 388debug-rcu)
1ad4c3d0
MJ
389 print_header "Conf: RCU sanity checks for debugging"
390
391 CONF_OPTS+=("--enable-python-bindings")
09d45745
MJ
392
393 export CPPFLAGS="$CPPFLAGS -DDEBUG_RCU"
22780fe6
JR
394 ;;
395
0cdaa21c 396*)
1ad4c3d0
MJ
397 print_header "Conf: Standard"
398
399 CONF_OPTS+=("--enable-python-bindings")
6871000c
MJ
400
401 # Something is broken in docbook-xml on yocto
402 if [[ "$platform" = yocto* ]]; then
403 CONF_OPTS+=("--disable-man-pages")
404 fi
0cdaa21c 405 ;;
b4005bbf
MJ
406esac
407
408# Build type
67122b96
MJ
409# oot : out-of-tree build
410# dist : build via make dist
411# oot-dist: build via make dist out-of-tree
412# * : normal tree build
b4005bbf 413#
09d45745
MJ
414# Make sure to move to the build directory and run configure
415# before continuing.
b4005bbf 416case "$build" in
09d45745 417oot)
1ad4c3d0 418 print_header "Build: Out of tree"
09d45745
MJ
419
420 # Create and enter a temporary build directory
52be5739 421 builddir=$(mktemp_compat -d)
09d45745
MJ
422 cd "$builddir"
423
51c9c62d 424 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
09d45745
MJ
425 ;;
426
427dist)
1ad4c3d0 428 print_header "Build: Distribution in-tree"
09d45745
MJ
429
430 # Run configure and generate the tar file
431 # in the source directory
1ad4c3d0 432
51c9c62d 433 ./configure "${DIST_CONF_OPTS[@]}" || failed_configure
09d45745
MJ
434 $MAKE dist
435
436 # Create and enter a temporary build directory
52be5739 437 builddir=$(mktemp_compat -d)
09d45745
MJ
438 cd "$builddir"
439
440 # Extract the distribution tar in the build directory,
441 # ignore the first directory level
442 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
443
444 # Build in extracted source tree
51c9c62d 445 ./configure "${CONF_OPTS[@]}" || failed_configure
09d45745
MJ
446 ;;
447
448oot-dist)
1ad4c3d0 449 print_header "Build: Distribution Out of tree"
09d45745
MJ
450
451 # Create and enter a temporary build directory
52be5739 452 builddir=$(mktemp_compat -d)
09d45745
MJ
453 cd "$builddir"
454
455 # Run configure out of tree and generate the tar file
51c9c62d 456 "$SRCDIR/configure" "${DIST_CONF_OPTS[@]}" || failed_configure
09d45745
MJ
457 $MAKE dist
458
52be5739 459 dist_srcdir="$(mktemp_compat -d)"
09d45745
MJ
460 cd "$dist_srcdir"
461
462 # Extract the distribution tar in the new source directory,
463 # ignore the first directory level
464 $TAR xvf "$builddir"/*.tar.* --strip 1
465
466 # Create and enter a second temporary build directory
52be5739 467 builddir="$(mktemp_compat -d)"
09d45745
MJ
468 cd "$builddir"
469
470 # Run configure from the extracted distribution tar,
471 # out of the source tree
51c9c62d 472 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
09d45745
MJ
473 ;;
474
475*)
1ad4c3d0 476 print_header "Build: Standard In-tree"
51c9c62d 477 ./configure "${CONF_OPTS[@]}" || failed_configure
09d45745 478 ;;
b4005bbf
MJ
479esac
480
09d45745
MJ
481# We are now inside a configured build directory
482
0cdaa21c 483# BUILD!
1ad4c3d0
MJ
484print_header "BUILD!"
485$BEAR ${BEAR:+--} $MAKE -j "$($NPROC)" V=1
486
487# Install in the workspace if enabled
488if [ "$LTTNG_TOOLS_MAKE_INSTALL" = "yes" ]; then
489 print_header "Install"
490
491 $MAKE install V=1 DESTDIR="$WORKSPACE"
492
493 # Cleanup rpath in executables
494 find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
495
496 # Some configs don't build liblttng-ctl
497 if [ -d "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" ]; then
498 # Cleanup rpath in shared libraries
499 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath --delete {} \;
500 # Remove libtool .la files
501 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -delete
502 fi
503fi
504
505# Run clang-tidy on the topmost commit
506if [ "$LTTNG_TOOLS_CLANG_TIDY" = "yes" ]; then
507 print_header "Run clang-tidy"
b4005bbf 508
1ad4c3d0
MJ
509 # This would be better by linting only the lines touched by a patch but it
510 # doesn't seem to work, the lines are always filtered and no error is
511 # reported.
512 #git diff -U0 HEAD^ | clang-tidy-diff -p1 -j "$($NPROC)" -timeout 60 -fix
513
514 # Instead, run clan-tidy on all the files touched by the patch.
515 while read -r filepath; do
516 if [[ "$filepath" =~ (\.cpp|\.hhp|\.c|\.h)$ ]]; then
517 clang-tidy --fix-errors "$(realpath "$filepath")"
518 fi
519 done < <(git diff-tree --no-commit-id --diff-filter=d --name-only -r HEAD)
520
521 # If the tree has local changes, the formatting was incorrect
522 GIT_DIFF_OUTPUT=$(git diff)
523 if [ -n "$GIT_DIFF_OUTPUT" ]; then
524 echo "Saving clang-tidy proposed fixes in clang-tidy-fixes.diff"
525 git diff > "$WORKSPACE/clang-tidy-fixes.diff"
526
527 # Restore the unfixed files so they can be viewed in the warnings web
528 # interface
529 git checkout .
530 exit_status=1
531 fi
532fi
7671741c 533
d6237b1b
MJ
534# Run tests for all configs except 'no-ust' / 'relayd-only'
535if [ "$LTTNG_TOOLS_RUN_TESTS" = "yes" ] && [[ ! "$conf" =~ (no-ust|relayd-only) ]]; then
1ad4c3d0
MJ
536 print_header "Run test suite"
537
0cdaa21c
MJ
538 # Allow core dumps
539 ulimit -c unlimited
540
a4e98cc0
JR
541 # Force the lttng-sessiond path to /bin/true to prevent the spawing of a
542 # lttng-sessiond --daemonize on "lttng create"
543 export LTTNG_SESSIOND_PATH="/bin/true"
544
1ad4c3d0
MJ
545 # It is implied that tests depending on LTTNG_ENABLE_DESTRUCTIVE_TESTS
546 # only run for the root user. Note that here `destructive` means that
547 # operations are performed at the host level (add user etc.) that
548 # effectively modify the host. Running those tests are acceptable on our
549 # CI and root jobs since we always run root tests against a `snapshot`
550 # of the host.
551 if [ "$(id -u)" == "0" ]; then
552 # Allow the traversal of all directories leading to the
553 # DEPS_LIBS directory to enable test app run by temp users to
554 # access lttng-ust.
555 set_execute_traversal_bit "$DEPS_LIB"
556 # Allow `all` to interact with all deps libs.
557 chmod a+rwx -R "$DEPS_LIB"
558
559 export LTTNG_ENABLE_DESTRUCTIVE_TESTS="will-break-my-system"
560
561 # Some destructive tests play with the system clock, disable timesyncd
562 systemctl stop systemd-timesyncd.service || true
563 fi
65444f1c 564
1ad4c3d0 565 make --keep-going check || exit_status=1
4174b905 566
68d45ec8 567 # Copy tap logs for the jenkins tap parser before cleaning the build dir
1ad4c3d0 568 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$TAPDIR"
4174b905 569
1ad4c3d0
MJ
570 # Copy the test suites top-level log which includes all tests failures
571 rsync -a --include 'test-suite.log' --include '*/' --exclude='*' tests/ "$WORKSPACE/log"
09d45745 572
aff4e3d1 573 if [ "$LTTNG_TOOLS_RUN_TESTS_LONG_REGRESSION" = "yes" ]; then
1ad4c3d0 574 print_header "Run long regression tests"
09d45745
MJ
575 cd tests
576 mkdir -p "$TAPDIR/long_regression"
1ad4c3d0 577 prove --merge -v --exec '' - < long_regression --archive "$TAPDIR/long_regression/" || exit_status=1
65444f1c 578 cd ..
0cdaa21c 579 fi
68d45ec8 580
1b7b4b35 581 if [ "$LTTNG_TOOLS_RUN_UST_JAVA_TESTS" = "yes" ] && [ "$LTTNG_TOOLS_MAKE_INSTALL" = "yes" ] && [ "$conf" = "agents" ] ; then
68d45ec8
KS
582 print_header "Run lttng-ust-java-tests"
583 # Git Source
584 LTTNG_UST_JAVA_TESTS_GIT_SOURCE="${LTTNG_UST_JAVA_TESTS_GIT_SOURCE:-https://github.com/lttng/lttng-ust-java-tests.git}"
585 LTTNG_UST_JAVA_TESTS_GIT_BRANCH="${LTTNG_UST_JAVA_TESTS_GIT_BRANCH:-master}"
586
587 OWD="$(pwd)"
588 cd ..
589 git clone -b "${LTTNG_UST_JAVA_TESTS_GIT_BRANCH}" "${LTTNG_UST_JAVA_TESTS_GIT_SOURCE}" lttng-ust-java-tests
590 cd lttng-ust-java-tests
591
592 LTTNG_UST_JAVA_TESTS_ENV=(
4a9fa8ba
KS
593 # Some ci nodes (eg. SLES12) don't have maven distributed by their
594 # package manager. As a result, the maven binary is deployed in
595 # '/opt/apache/maven/bin'.
596 PATH="${WORKSPACE}/build/bin/:$PATH:/opt/apache/maven/bin/"
597 LD_LIBRARY_PATH="${WORKSPACE}/build/${LIBDIR}/:${WORKSPACE}/build/${LIBDIR_ARCH}:$LD_LIBRARY_PATH"
68d45ec8 598 LTTNG_UST_DEBUG=1
4a9fa8ba
KS
599 LTTNG_CONSUMERD32_BIN="${WORKSPACE}/build/${LIBDIR_ARCH}/lttng/libexec/lttng-consumerd"
600 LTTNG_CONSUMERD64_BIN="${WORKSPACE}/build/${LIBDIR_ARCH}/lttng/libexec/lttng-consumerd"
68d45ec8 601 LTTNG_SESSION_CONFIG_XSD_PATH="${WORKSPACE}/build/share/xml/lttng"
4a9fa8ba
KS
602 BABELTRACE_PLUGIN_PATH="${WORKSPACE}/deps/build/${LIBDIR_ARCH}/babeltrace2/plugins"
603 LIBBABELTRACE2_PLUGIN_PROVIDER_DIR="${WORKSPACE}/deps/build/${LIBDIR_ARCH}/babeltrace2/plugin-providers"
68d45ec8
KS
604 )
605 LTTNG_UST_JAVA_TESTS_MAVEN_OPTS=(
606 "-Dmaven.test.failure.ignore=true"
607 "-Dcommon-jar-location=${WORKSPACE}/deps/build/share/java/lttng-ust-agent-common.jar"
608 "-Djul-jar-location=${WORKSPACE}/deps/build/share/java/lttng-ust-agent-jul.jar"
609 "-Dlog4j-jar-location=${WORKSPACE}/deps/build/share/java/lttng-ust-agent-log4j.jar"
610 "-Dlog4j2-jar-location=${WORKSPACE}/deps/build/share/java/lttng-ust-agent-log4j2.jar"
4a9fa8ba 611 "-DargLine=-Djava.library.path=${WORKSPACE}/deps/build/${LIBDIR_ARCH}"
68d45ec8
KS
612 '-Dgroups=!domain:log4j2'
613 )
9a269c66 614
68d45ec8 615 env "${LTTNG_UST_JAVA_TESTS_ENV[@]}" mvn -version
9a269c66
KS
616
617 if [[ -n "${LTTNG_TOOLS_UST_JAVA_TESTS_LOG4J_API_VERSION:-}" ]] ; then
618 env "${LTTNG_UST_JAVA_TESTS_ENV[@]}" mvn versions:use-dep-version -Dincludes=org.apache.logging.log4j:'*' -DdepVersion="${LTTNG_TOOLS_UST_JAVA_TESTS_LOG4J_API_VERSION}"
619 fi
620
4a9fa8ba 621 mkdir -p "${WORKSPACE}/log"
68d45ec8 622 env "${LTTNG_UST_JAVA_TESTS_ENV[@]}" lttng-sessiond -b -vvv 1>"${WORKSPACE}/log/lttng-ust-java-tests-lttng-sessiond.log" 2>&1
9a269c66 623 env "${LTTNG_UST_JAVA_TESTS_ENV[@]}" mvn "${LTTNG_UST_JAVA_TESTS_MAVEN_OPTS[@]}" clean compile dependency:build-classpath dependency:tree verify || exit_status=1
68d45ec8
KS
624 killall lttng-sessiond
625
626 cd "${OWD}"
627 fi
2c34ea14
MJ
628fi
629
d6237b1b 630if [ "$LTTNG_TOOLS_RUN_TESTS" = "yes" ] && [[ "$conf" =~ (no-ust|relayd-only) ]]; then
09d45745
MJ
631 # The TAP plugin will fail the job if no test logs are present
632 mkdir -p "$TAPDIR/no-tests"
633 echo "1..1" > "$TAPDIR/no-tests/tests.log"
634 echo "ok 1 - Test suite disabled" >> "$TAPDIR/no-tests/tests.log"
b4005bbf
MJ
635fi
636
09d45745 637# Clean the build directory
1ad4c3d0
MJ
638if [ "$LTTNG_TOOLS_MAKE_CLEAN" = "yes" ]; then
639 print_header "Clean"
640 $MAKE clean
0a059dd4 641fi
b4005bbf 642
1ad4c3d0
MJ
643print_header "LTTng-tools build script ended with: $(test $exit_status == 0 && echo SUCCESS || echo FAILURE)"
644
09d45745 645# Exit with failure if any of the tests failed
1ad4c3d0 646exit $exit_status
95654431
MJ
647
648# EOF
1ad4c3d0 649# vim: expandtab tabstop=4 shiftwidth=4
This page took 0.066246 seconds and 4 git commands to generate.