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
7 # shellcheck disable=SC2103
11 # Version compare functions
14 if [[ "$1" == "$2" ]]; then
18 # Ignore the shellcheck warning, we want splitting to happen based on IFS.
19 # shellcheck disable=SC2206
20 local i ver1
=($1) ver2
=($2)
21 # fill empty fields in ver1 with zeros
22 for ((i
=${#ver1[@]}; i
<${#ver2[@]}; i
++)); do
25 for ((i
=0; i
<${#ver1[@]}; i
++)); do
26 if [[ -z ${ver2[i]} ]]; then
27 # fill empty fields in ver2 with zeros
30 if ((10#${ver1[i]} > 10#${ver2[i]})); then
33 if ((10#${ver1[i]} < 10#${ver2[i]})); then
42 vercomp
"$1" "$2"; local res
="$?"
43 [ "$res" -eq "0" ] ||
[ "$res" -eq "2" ]
47 vercomp
"$1" "$2"; local res
="$?"
52 vercomp
"$1" "$2"; local res
="$?"
53 [ "$res" -eq "0" ] ||
[ "$res" -eq "1" ]
57 vercomp
"$1" "$2"; local res
="$?"
62 vercomp
"$1" "$2"; local res
="$?"
73 message_len
="${#message}"
74 padding_len
=$
(( (80 - (message_len
)) / 2 ))
77 printf '\n'; printf -- '#%.0s' {1.
.80}; printf '\n'
78 printf -- '-%.0s' {1.
.80}; printf '\n'
79 printf -- '#%.0s' $
(seq 1 $padding_len); printf '%s' "$message"; printf -- '#%.0s' $
(seq 1 $padding_len); printf '\n'
80 printf -- '-%.0s' {1.
.80}; printf '\n'
81 printf -- '#%.0s' {1.
.80}; printf '\n\n'
87 # Assume we are in the configured build directory
88 print_header
"BEGIN config.log"
90 print_header
"END config.log"
92 # End the build with failure
96 set_execute_traversal_bit
()
101 if [ ! -d "$path" ]; then
102 fail
"Path is not a directory"
104 while level
="$(dirname "$level")"
106 if [ "$level" = / ]; then
114 print_header
"LTTng-tools build script starting"
117 WORKSPACE
=${WORKSPACE:-}
120 platform
=${platform:-}
125 # Build steps that can be overriden by the environment
126 LTTNG_TOOLS_MAKE_INSTALL
="${LTTNG_TOOLS_MAKE_INSTALL:-yes}"
127 LTTNG_TOOLS_MAKE_CLEAN
="${LTTNG_TOOLS_MAKE_CLEAN:-yes}"
128 LTTNG_TOOLS_GEN_COMPILE_COMMANDS
="${LTTNG_TOOLS_GEN_COMPILE_COMMANDS:-no}"
129 LTTNG_TOOLS_RUN_TESTS
="${LTTNG_TOOLS_RUN_TESTS:-yes}"
130 LTTNG_TOOLS_RUN_TESTS_LONG_REGRESSION
="${LTTNG_TOOLS_RUN_TESTS_LONG_REGRESSION:-no}"
131 LTTNG_TOOLS_RUN_UST_JAVA_TESTS
="${LTTNG_TOOLS_RUN_UST_JAVA_TESTS:-yes}"
132 LTTNG_TOOLS_CLANG_TIDY
="${LTTNG_TOOLS_CLANG_TIDY:-no}"
134 SRCDIR
="$WORKSPACE/src/lttng-tools"
135 TAPDIR
="$WORKSPACE/tap"
138 LIBDIR_ARCH
="$LIBDIR"
140 # RHEL and SLES both use lib64 but don't bother shipping a default autoconf
141 # site config that matches this.
142 if [[ ( -f /etc
/redhat-release ||
-f /etc
/products.d
/SLES.prod ||
-f /etc
/yocto-release
) ]]; then
143 # Detect the userspace bitness in a distro agnostic way
144 if file -L /bin
/bash |
grep '64-bit' >/dev
/null
2>&1; then
145 LIBDIR_ARCH
="${LIBDIR}64"
149 DEPS_INC
="$WORKSPACE/deps/build/include"
150 DEPS_LIB
="$WORKSPACE/deps/build/$LIBDIR_ARCH"
151 DEPS_PKGCONFIG
="$DEPS_LIB/pkgconfig"
152 DEPS_BIN
="$WORKSPACE/deps/build/bin"
153 DEPS_JAVA
="$WORKSPACE/deps/build/share/java"
155 export PATH
="$DEPS_BIN:$PATH"
156 export LD_LIBRARY_PATH
="$DEPS_LIB:${LD_LIBRARY_PATH:-}"
157 export PKG_CONFIG_PATH
="$DEPS_PKGCONFIG"
158 export CPPFLAGS
="-I$DEPS_INC"
159 export LDFLAGS
="-L$DEPS_LIB"
163 # Use bear to generate compile_commands.json when enabled
165 if [ "$LTTNG_TOOLS_GEN_COMPILE_COMMANDS" = "yes" ]; then
169 # Create tmp directory
170 TMPDIR
="$WORKSPACE/tmp"
173 # Use a symlink in /tmp to point to the the tmp directory
174 # inside the workspace, this is to work around the path length
175 # limit of unix sockets which are created by the test suite.
177 ln -sf "$TMPDIR" "$tmpdir"
178 export TMPDIR
="$tmpdir"
180 # Create a symlink to "babeltrace" when the "babeltrace2" executable is found.
181 # This is a temporary workaround until lttng-tools either allows the override of
182 # the trace reader in its test suite or that we move to only supporting
184 if [ -x "$DEPS_BIN/babeltrace2" ]; then
185 ln -s "$DEPS_BIN/babeltrace2" "$DEPS_BIN/babeltrace"
188 # When using babeltrace2 make sure that it finds its plugins and
190 export BABELTRACE_PLUGIN_PATH
="$DEPS_LIB/babeltrace2/plugins/"
191 export LIBBABELTRACE2_PLUGIN_PROVIDER_DIR
="$DEPS_LIB/babeltrace2/plugin-providers/"
193 export CFLAGS
="-g -O2"
194 export CXXFLAGS
="-g -O2"
196 # Set compiler variables
203 export CC
=gcc-
${cc#gcc-}
204 export CXX
=g
++-${cc#gcc-}
211 export CC
=clang-
${cc#clang-}
212 export CXX
=clang
++-${cc#clang-}
215 if [ "x$cc" != "x" ]; then
221 # Set platform variables
226 export NPROC
="getconf _NPROCESSORS_ONLN"
227 export PATH
="/opt/local/bin:/opt/local/sbin:$PATH"
228 export CPPFLAGS
="-I/opt/local/include $CPPFLAGS"
229 export LDFLAGS
="-L/opt/local/lib $LDFLAGS"
230 export PYTHON
="python3"
231 export PYTHON_CONFIG
="python3-config"
234 cygwin|cygwin64|msys32|msys64
)
248 if command -v $PYTHON2 >/dev
/null
2>&1; then
249 P2_VERSION
=$
($PYTHON2 -c 'import sys;v = sys.version.split()[0].split("."); print("{}.{}".format(v[0], v[1]))')
250 DEPS_PYTHON2
="$WORKSPACE/deps/build/$LIBDIR/python$P2_VERSION/site-packages"
251 if [ "$LIBDIR" != "$LIBDIR_ARCH" ]; then
252 DEPS_PYTHON2
="$DEPS_PYTHON2:$WORKSPACE/deps/build/$LIBDIR_ARCH/python$P2_VERSION/site-packages"
256 P3_VERSION
=$
($PYTHON3 -c 'import sys;v = sys.version.split()[0].split("."); print("{}.{}".format(v[0], v[1]))')
258 # Temporary fix for an issue on debian python >= 3.10, add the 'local' prefix
259 DEPS_PYTHON3
="$WORKSPACE/deps/build/$LIBDIR/python$P3_VERSION/site-packages:$WORKSPACE/deps/build/local/$LIBDIR/python$P3_VERSION/dist-packages"
260 if [ "$LIBDIR" != "$LIBDIR_ARCH" ]; then
261 DEPS_PYTHON3
="$DEPS_PYTHON3:$WORKSPACE/deps/build/$LIBDIR_ARCH/python$P3_VERSION/site-packages"
264 # Most build configs require access to the babeltrace 2 python bindings.
265 # This also makes the lttngust python agent available for `agents` builds.
266 export PYTHONPATH
="${DEPS_PYTHON2:-}${DEPS_PYTHON2:+:}$DEPS_PYTHON3"
270 # Some warning flags are very dumb in GCC 4.8 on SLES12 / EL7, disable them
271 # even if they are available.
272 if [[ $platform = sles12sp5
* ]] ||
[[ $platform = el7
* ]]; then
273 CFLAGS
="$CFLAGS -Wno-missing-field-initializers -Wno-shadow"
274 CXXFLAGS
="$CXXFLAGS -Wno-missing-field-initializers -Wno-shadow"
277 # If we have modules, build them
278 if [ -d "$WORKSPACE/src/lttng-modules" ]; then
279 print_header
"Build and install LTTng-modules"
280 cd "$WORKSPACE/src/lttng-modules"
281 $MAKE -j"$($NPROC)" V
=1
282 $MAKE modules_install V
=1
286 # Print build env details
287 print_header
"Build environment details"
288 print_hardware || true
290 print_tooling || true
292 # Enter the source directory
295 # Run bootstrap in the source directory prior to configure
296 print_header
"Bootstrap autotools"
299 # Get source version from configure script
300 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
301 PACKAGE_VERSION
=${PACKAGE_VERSION//\-pre*/}
303 CONF_OPTS
=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH" "--disable-maintainer-mode")
304 DIST_CONF_OPTS
=("--disable-maintainer-mode")
306 # Set configure options and environment variables for each build
310 print_header
"Conf: Static lib only"
312 CONF_OPTS
+=("--enable-static" "--disable-shared" "--enable-python-bindings")
316 print_header
"Conf: Without UST support"
318 CONF_OPTS
+=("--without-lttng-ust")
319 DIST_CONF_OPTS
+=("--without-lttng-ust")
323 print_header
"Conf: Java and Python agents"
325 if [[ -z "${JAVA_HOME:-}" ]] ; then
326 export JAVA_HOME
="/usr/lib/jvm/default-java"
328 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"
329 if [[ -f /etc
/products.d
/SLES.prod
]] ; then
330 export JAVA_HOME
="/usr/${LIBDIR_ARCH}/jvm/java-1.8.0-openjdk-1.8.0"
331 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}"
332 SLES_VERSION
="$(grep -E '</version>' /etc/products.d/SLES.prod | grep -E -o '[0-9]+\.[0-9]+')"
333 if vergte
"${SLES_VERSION}" "15.5" ; then
334 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"
339 CONF_OPTS
+=("--enable-python-bindings" "--enable-test-java-agent-all")
341 # Explicitly add '--enable-test-java-agent-log4j2', it's not part of '-all' in stable 2.12/2.13
342 if verlt
"$PACKAGE_VERSION" "2.14"; then
343 CONF_OPTS
+=("--enable-test-java-agent-log4j2")
346 # Some distros don't ship python2 anymore
347 if command -v $PYTHON2 >/dev
/null
2>&1; then
348 CONF_OPTS
+=("--enable-test-python-agent-all")
350 CONF_OPTS
+=("--enable-test-python3-agent")
355 print_header
"Conf: Relayd only"
357 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")
361 print_header
"Conf: RCU sanity checks for debugging"
363 CONF_OPTS
+=("--enable-python-bindings")
365 export CPPFLAGS
="$CPPFLAGS -DDEBUG_RCU"
369 print_header
"Conf: Standard"
371 CONF_OPTS
+=("--enable-python-bindings")
373 # Something is broken in docbook-xml on yocto
374 if [[ "$platform" = yocto
* ]]; then
375 CONF_OPTS
+=("--disable-man-pages")
381 # oot : out-of-tree build
382 # dist : build via make dist
383 # oot-dist: build via make dist out-of-tree
384 # * : normal tree build
386 # Make sure to move to the build directory and run configure
390 print_header
"Build: Out of tree"
392 # Create and enter a temporary build directory
393 builddir
=$
(mktemp
-d)
396 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
400 print_header
"Build: Distribution in-tree"
402 # Run configure and generate the tar file
403 # in the source directory
405 .
/configure
"${DIST_CONF_OPTS[@]}" || failed_configure
408 # Create and enter a temporary build directory
409 builddir
=$
(mktemp
-d)
412 # Extract the distribution tar in the build directory,
413 # ignore the first directory level
414 $TAR xvf
"$SRCDIR"/*.
tar.
* --strip 1
416 # Build in extracted source tree
417 .
/configure
"${CONF_OPTS[@]}" || failed_configure
421 print_header
"Build: Distribution Out of tree"
423 # Create and enter a temporary build directory
424 builddir
=$
(mktemp
-d)
427 # Run configure out of tree and generate the tar file
428 "$SRCDIR/configure" "${DIST_CONF_OPTS[@]}" || failed_configure
431 dist_srcdir
="$(mktemp -d)"
434 # Extract the distribution tar in the new source directory,
435 # ignore the first directory level
436 $TAR xvf
"$builddir"/*.
tar.
* --strip 1
438 # Create and enter a second temporary build directory
439 builddir
="$(mktemp -d)"
442 # Run configure from the extracted distribution tar,
443 # out of the source tree
444 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
448 print_header
"Build: Standard In-tree"
449 .
/configure
"${CONF_OPTS[@]}" || failed_configure
453 # We are now inside a configured build directory
456 print_header
"BUILD!"
457 $BEAR ${BEAR:+--} $MAKE -j "$($NPROC)" V
=1
459 # Install in the workspace if enabled
460 if [ "$LTTNG_TOOLS_MAKE_INSTALL" = "yes" ]; then
461 print_header
"Install"
463 $MAKE install V
=1 DESTDIR
="$WORKSPACE"
465 # Cleanup rpath in executables
466 find "$WORKSPACE/$PREFIX/bin" -type f
-perm -0500 -exec chrpath
--delete {} \
;
468 # Some configs don't build liblttng-ctl
469 if [ -d "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" ]; then
470 # Cleanup rpath in shared libraries
471 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath
--delete {} \
;
472 # Remove libtool .la files
473 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -delete
477 # Run clang-tidy on the topmost commit
478 if [ "$LTTNG_TOOLS_CLANG_TIDY" = "yes" ]; then
479 print_header
"Run clang-tidy"
481 # This would be better by linting only the lines touched by a patch but it
482 # doesn't seem to work, the lines are always filtered and no error is
484 #git diff -U0 HEAD^ | clang-tidy-diff -p1 -j "$($NPROC)" -timeout 60 -fix
486 # Instead, run clan-tidy on all the files touched by the patch.
487 while read -r filepath
; do
488 if [[ "$filepath" =~
(\.cpp|\.hhp|\.c|\.h
)$
]]; then
489 clang-tidy
--fix-errors "$(realpath "$filepath")"
491 done < <(git diff-tree
--no-commit-id --diff-filter=d
--name-only -r HEAD
)
493 # If the tree has local changes, the formatting was incorrect
494 GIT_DIFF_OUTPUT
=$
(git
diff)
495 if [ -n "$GIT_DIFF_OUTPUT" ]; then
496 echo "Saving clang-tidy proposed fixes in clang-tidy-fixes.diff"
497 git
diff > "$WORKSPACE/clang-tidy-fixes.diff"
499 # Restore the unfixed files so they can be viewed in the warnings web
506 # Run tests for all configs except 'no-ust' / 'relayd-only'
507 if [ "$LTTNG_TOOLS_RUN_TESTS" = "yes" ] && [[ ! "$conf" =~
(no-ust|relayd-only
) ]]; then
508 print_header
"Run test suite"
513 # Force the lttng-sessiond path to /bin/true to prevent the spawing of a
514 # lttng-sessiond --daemonize on "lttng create"
515 export LTTNG_SESSIOND_PATH
="/bin/true"
517 # It is implied that tests depending on LTTNG_ENABLE_DESTRUCTIVE_TESTS
518 # only run for the root user. Note that here `destructive` means that
519 # operations are performed at the host level (add user etc.) that
520 # effectively modify the host. Running those tests are acceptable on our
521 # CI and root jobs since we always run root tests against a `snapshot`
523 if [ "$(id -u)" == "0" ]; then
524 # Allow the traversal of all directories leading to the
525 # DEPS_LIBS directory to enable test app run by temp users to
527 set_execute_traversal_bit
"$DEPS_LIB"
528 # Allow `all` to interact with all deps libs.
529 chmod a
+rwx
-R "$DEPS_LIB"
531 export LTTNG_ENABLE_DESTRUCTIVE_TESTS
="will-break-my-system"
533 # Some destructive tests play with the system clock, disable timesyncd
534 systemctl stop systemd-timesyncd.service || true
537 make --keep-going check || exit_status
=1
539 # Copy tap logs for the jenkins tap parser before cleaning the build dir
540 rsync
-a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests
/ "$TAPDIR"
542 # Copy the test suites top-level log which includes all tests failures
543 rsync
-a --include 'test-suite.log' --include '*/' --exclude='*' tests
/ "$WORKSPACE/log"
545 if [ "$LTTNG_TOOLS_RUN_TESTS_LONG_REGRESSION" = "yes" ]; then
546 print_header
"Run long regression tests"
548 mkdir
-p "$TAPDIR/long_regression"
549 prove
--merge -v --exec '' - < long_regression
--archive "$TAPDIR/long_regression/" || exit_status
=1
553 if [ "$LTTNG_TOOLS_RUN_UST_JAVA_TESTS" = "yes" ] && [ "$LTTNG_TOOLS_MAKE_INSTALL" = "yes" ] && [ "$conf" = "agents" ] ; then
554 print_header
"Run lttng-ust-java-tests"
556 LTTNG_UST_JAVA_TESTS_GIT_SOURCE
="${LTTNG_UST_JAVA_TESTS_GIT_SOURCE:-https://github.com/lttng/lttng-ust-java-tests.git}"
557 LTTNG_UST_JAVA_TESTS_GIT_BRANCH
="${LTTNG_UST_JAVA_TESTS_GIT_BRANCH:-master}"
561 git clone
-b "${LTTNG_UST_JAVA_TESTS_GIT_BRANCH}" "${LTTNG_UST_JAVA_TESTS_GIT_SOURCE}" lttng-ust-java-tests
562 cd lttng-ust-java-tests
564 LTTNG_UST_JAVA_TESTS_ENV
=(
565 # Some ci nodes (eg. SLES12) don't have maven distributed by their
566 # package manager. As a result, the maven binary is deployed in
567 # '/opt/apache/maven/bin'.
568 PATH
="${WORKSPACE}/build/bin/:$PATH:/opt/apache/maven/bin/"
569 LD_LIBRARY_PATH
="${WORKSPACE}/build/${LIBDIR}/:${WORKSPACE}/build/${LIBDIR_ARCH}:$LD_LIBRARY_PATH"
571 LTTNG_CONSUMERD32_BIN
="${WORKSPACE}/build/${LIBDIR_ARCH}/lttng/libexec/lttng-consumerd"
572 LTTNG_CONSUMERD64_BIN
="${WORKSPACE}/build/${LIBDIR_ARCH}/lttng/libexec/lttng-consumerd"
573 LTTNG_SESSION_CONFIG_XSD_PATH
="${WORKSPACE}/build/share/xml/lttng"
574 BABELTRACE_PLUGIN_PATH
="${WORKSPACE}/deps/build/${LIBDIR_ARCH}/babeltrace2/plugins"
575 LIBBABELTRACE2_PLUGIN_PROVIDER_DIR
="${WORKSPACE}/deps/build/${LIBDIR_ARCH}/babeltrace2/plugin-providers"
577 LTTNG_UST_JAVA_TESTS_MAVEN_OPTS
=(
578 "-Dmaven.test.failure.ignore=true"
579 "-Dcommon-jar-location=${WORKSPACE}/deps/build/share/java/lttng-ust-agent-common.jar"
580 "-Djul-jar-location=${WORKSPACE}/deps/build/share/java/lttng-ust-agent-jul.jar"
581 "-Dlog4j-jar-location=${WORKSPACE}/deps/build/share/java/lttng-ust-agent-log4j.jar"
582 "-Dlog4j2-jar-location=${WORKSPACE}/deps/build/share/java/lttng-ust-agent-log4j2.jar"
583 "-DargLine=-Djava.library.path=${WORKSPACE}/deps/build/${LIBDIR_ARCH}"
584 '-Dgroups=!domain:log4j2'
586 env
"${LTTNG_UST_JAVA_TESTS_ENV[@]}" mvn
-version
587 mkdir
-p "${WORKSPACE}/log"
588 env
"${LTTNG_UST_JAVA_TESTS_ENV[@]}" lttng-sessiond
-b -vvv 1>"${WORKSPACE}/log/lttng-ust-java-tests-lttng-sessiond.log" 2>&1
589 env
"${LTTNG_UST_JAVA_TESTS_ENV[@]}" mvn
"${LTTNG_UST_JAVA_TESTS_MAVEN_OPTS[@]}" clean verify || exit_status
=1
590 killall lttng-sessiond
596 if [ "$LTTNG_TOOLS_RUN_TESTS" = "yes" ] && [[ "$conf" =~
(no-ust|relayd-only
) ]]; then
597 # The TAP plugin will fail the job if no test logs are present
598 mkdir
-p "$TAPDIR/no-tests"
599 echo "1..1" > "$TAPDIR/no-tests/tests.log"
600 echo "ok 1 - Test suite disabled" >> "$TAPDIR/no-tests/tests.log"
603 # Clean the build directory
604 if [ "$LTTNG_TOOLS_MAKE_CLEAN" = "yes" ]; then
609 print_header
"LTTng-tools build script ended with: $(test $exit_status == 0 && echo SUCCESS || echo FAILURE)"
611 # Exit with failure if any of the tests failed
615 # vim: expandtab tabstop=4 shiftwidth=4