3 # SPDX-FileCopyrightText: 2015 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
9 # Version compare functions
12 if [[ "$1" == "$2" ]]; then
16 # Ignore the shellcheck warning, we want splitting to happen based on IFS.
17 # shellcheck disable=SC2206
18 local i ver1
=($1) ver2
=($2)
19 # fill empty fields in ver1 with zeros
20 for ((i
=${#ver1[@]}; i
<${#ver2[@]}; i
++)); do
23 for ((i
=0; i
<${#ver1[@]}; i
++)); do
24 if [[ -z ${ver2[i]} ]]; then
25 # fill empty fields in ver2 with zeros
28 if ((10#${ver1[i]} > 10#${ver2[i]})); then
31 if ((10#${ver1[i]} < 10#${ver2[i]})); then
40 vercomp
"$1" "$2"; local res
="$?"
41 [ "$res" -eq "0" ] ||
[ "$res" -eq "2" ]
45 vercomp
"$1" "$2"; local res
="$?"
50 vercomp
"$1" "$2"; local res
="$?"
51 [ "$res" -eq "0" ] ||
[ "$res" -eq "1" ]
55 vercomp
"$1" "$2"; local res
="$?"
60 vercomp
"$1" "$2"; local res
="$?"
71 message_len
="${#message}"
72 padding_len
=$
(( (80 - (message_len
)) / 2 ))
74 printf '\n'; printf -- '#%.0s' {1.
.80}; printf '\n'
75 printf -- '-%.0s' {1.
.80}; printf '\n'
76 printf -- '#%.0s' $
(seq 1 $padding_len); printf '%s' "$message"; printf -- '#%.0s' $
(seq 1 $padding_len); printf '\n'
77 printf -- '-%.0s' {1.
.80}; printf '\n'
78 printf -- '#%.0s' {1.
.80}; printf '\n\n'
84 # Assume we are in the configured build directory
85 print_header
"BEGIN config.log"
87 print_header
"END config.log"
89 # End the build with failure
93 print_header
"LTTng-UST build script starting"
96 WORKSPACE
=${WORKSPACE:-}
99 platform
=${platform:-}
104 # Build steps that can be overriden by the environment
105 LTTNG_UST_MAKE_INSTALL
="${LTTNG_UST_MAKE_INSTALL:-yes}"
106 LTTNG_UST_MAKE_CLEAN
="${LTTNG_UST_MAKE_CLEAN:-yes}"
107 LTTNG_UST_GEN_COMPILE_COMMANDS
="${LTTNG_UST_GEN_COMPILE_COMMANDS:-no}"
108 LTTNG_UST_RUN_TESTS
="${LTTNG_UST_RUN_TESTS:-yes}"
109 LTTNG_UST_CLANG_TIDY
="${LTTNG_UST_CLANG_TIDY:-no}"
111 SRCDIR
="$WORKSPACE/src/lttng-ust"
112 TMPDIR
="$WORKSPACE/tmp"
115 LIBDIR_ARCH
="$LIBDIR"
117 # RHEL and SLES both use lib64 but don't bother shipping a default autoconf
118 # site config that matches this.
119 if [[ ( -f /etc
/redhat-release ||
-f /etc
/products.d
/SLES.prod ||
-f /etc
/yocto-release
) ]]; then
120 # Detect the userspace bitness in a distro agnostic way
121 if file -L /bin
/bash |
grep '64-bit' >/dev
/null
2>&1; then
122 LIBDIR_ARCH
="${LIBDIR}64"
126 DEPS_INC
="$WORKSPACE/deps/build/include"
127 DEPS_LIB
="$WORKSPACE/deps/build/$LIBDIR_ARCH"
128 DEPS_PKGCONFIG
="$DEPS_LIB/pkgconfig"
129 #DEPS_BIN="$WORKSPACE/deps/build/bin"
130 #DEPS_JAVA="$WORKSPACE/deps/build/share/java"
132 export LD_LIBRARY_PATH
="$DEPS_LIB:${LD_LIBRARY_PATH:-}"
133 export PKG_CONFIG_PATH
="$DEPS_PKGCONFIG"
134 export CPPFLAGS
="-I$DEPS_INC"
135 export LDFLAGS
="-L$DEPS_LIB"
139 # Use bear to generate compile_commands.json when enabled
141 if [ "$LTTNG_UST_GEN_COMPILE_COMMANDS" = "yes" ]; then
145 # Create tmp directory
150 export CFLAGS
="-g -O2"
151 export CXXFLAGS
="-g -O2"
153 # Set compiler variables
160 export CC
=gcc-
${cc#gcc-}
161 export CXX
=g
++-${cc#gcc-}
168 export CC
=clang-
${cc#clang-}
169 export CXX
=clang
++-${cc#clang-}
172 if [ "x$cc" != "x" ]; then
178 # Set platform variables
183 export NPROC
="getconf _NPROCESSORS_ONLN"
184 export CPPFLAGS
="-I/usr/local/include $CPPFLAGS"
185 export LDFLAGS
="-L/usr/local/lib $LDFLAGS"
186 export PYTHON
="python3"
187 export PYTHON_CONFIG
="python3-config"
188 export CLASSPATH
='/usr/local/share/java/classes/*'
189 export JAVA_HOME
='/usr/local/openjdk17'
196 export PYTHON
="python3"
197 export PYTHON_CONFIG
="python3-config"
198 export CLASSPATH
='/usr/share/java/log4j-api.jar:/usr/share/java/log4j-core.jar:/usr/share/java/log4j-1.2.jar'
202 if [[ -f /etc
/products.d
/SLES.prod
]] ; then
203 export JAVA_HOME
="/usr/${LIBDIR_ARCH}/jvm/java-1.8.0-openjdk-1.8.0"
204 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}"
206 SLES_VERSION
="$(grep -E '</version>' /etc/products.d/SLES.prod | grep -E -o '[0-9]+\.[0-9]+')"
207 if vergte
"${SLES_VERSION}" "15.5" ; then
208 export CLASSPATH
='/usr/share/java/log4j/log4j-api.jar:/usr/share/java/log4j/log4j-core.jar:/usr/share/java/log4j12/log4j-12.jar'
212 # Print build env details
213 print_header
"Build environment details"
214 print_hardware || true
216 print_tooling || true
218 # Enter the source directory
221 # Run bootstrap in the source directory prior to configure
222 print_header
"Bootstrap autotools"
225 # Get source version from configure script
226 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
227 PACKAGE_VERSION
=${PACKAGE_VERSION//\-pre*/}
229 # Set configure options and environment variables for each build
231 CONF_OPTS
=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH" "--disable-maintainer-mode")
234 print_header
"Conf: Static lib only"
236 CONF_OPTS
+=("--enable-static" "--disable-shared")
238 # Unsupported! liblttng-ust can't pull in it's static (.a) dependencies.
243 print_header
"Conf: Java and Python agents"
245 CONF_OPTS
+=("--enable-java-agent-all" "--enable-jni-interface" "--enable-python-agent")
247 # Explicitly add '--enable-java-agent-log4j2', it's not part of '-all' in stable 2.12/2.13
248 if verlt
"$PACKAGE_VERSION" "2.14"; then
249 CONF_OPTS
+=("--enable-java-agent-log4j2")
254 print_header
"Conf: Enable RCU sanity checks for debugging"
256 export CPPFLAGS
="${CPPFLAGS} -DDEBUG_RCU"
260 print_header
"Conf: Standard"
262 # Something is broken in docbook-xml on yocto
263 if [[ "$platform" = yocto
* ]]; then
264 CONF_OPTS
+=("--disable-man-pages")
270 # oot : out-of-tree build
271 # dist : build via make dist
272 # oot-dist: build via make dist out-of-tree
273 # * : normal tree build
275 # Make sure to move to the build directory and run configure
279 print_header
"Build: Out of tree"
281 # Create and enter a temporary build directory
282 builddir
=$
(mktemp
-d)
285 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
289 print_header
"Build: Distribution In-tree"
291 # Run configure and generate the tar file
292 # in the source directory
293 .
/configure
--enable-jni-interface || failed_configure
296 # Create and enter a temporary build directory
297 builddir
=$
(mktemp
-d)
300 # Extract the distribution tar in the build directory,
301 # ignore the first directory level
302 $TAR xvf
"$SRCDIR"/*.
tar.
* --strip 1
304 # Build in extracted source tree
305 .
/configure
"${CONF_OPTS[@]}" || failed_configure
309 print_header
"Build: Distribution Out of tree"
311 # Create and enter a temporary build directory
312 builddir
=$
(mktemp
-d)
315 # Run configure out of tree and generate the tar file
316 "$SRCDIR/configure" --enable-jni-interface || failed_configure
319 dist_srcdir
="$(mktemp -d)"
322 # Extract the distribution tar in the new source directory,
323 # ignore the first directory level
324 $TAR xvf
"$builddir"/*.
tar.
* --strip 1
326 # Create and enter a second temporary build directory
327 builddir
="$(mktemp -d)"
330 # Run configure from the extracted distribution tar,
331 # out of the source tree
332 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
336 print_header
"Build: Standard In-tree"
338 .
/configure
"${CONF_OPTS[@]}" || failed_configure
342 # We are now inside a configured build directory
345 print_header
"BUILD!"
346 $BEAR ${BEAR:+--} $MAKE -j "$($NPROC)" V
=1
348 # Install in the workspace if enabled
349 if [ "$LTTNG_UST_MAKE_INSTALL" = "yes" ]; then
350 print_header
"Install"
352 $MAKE install V
=1 DESTDIR
="$WORKSPACE"
354 # Cleanup rpath in executables and shared libraries
355 #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
356 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath
--delete {} \
;
358 # Remove libtool .la files
359 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -delete
362 # Run clang-tidy on the topmost commit
363 if [ "$LTTNG_UST_CLANG_TIDY" = "yes" ]; then
364 print_header
"Run clang-tidy"
366 # This would be better by linting only the lines touched by a patch but it
367 # doesn't seem to work, the lines are always filtered and no error is
369 #git diff -U0 HEAD^ | clang-tidy-diff -p1 -j "$($NPROC)" -timeout 60 -fix
371 # Instead, run clan-tidy on all the files touched by the patch.
372 while read -r filepath
; do
373 if [[ "$filepath" =~
(\.cpp|\.hhp|\.c|\.h
)$
]]; then
374 clang-tidy
--fix-errors "$(realpath "$filepath")"
376 done < <(git diff-tree
--no-commit-id --diff-filter=d
--name-only -r HEAD
)
378 # If the tree has local changes, the formatting was incorrect
379 GIT_DIFF_OUTPUT
=$
(git
diff)
380 if [ -n "$GIT_DIFF_OUTPUT" ]; then
381 echo "Saving clang-tidy proposed fixes in clang-tidy-fixes.diff"
382 git
diff > "$WORKSPACE/clang-tidy-fixes.diff"
384 # Restore the unfixed files so they can be viewed in the warnings web
391 # Run tests, don't fail now, we want to run the archiving steps
392 if [ "$LTTNG_UST_RUN_TESTS" = "yes" ]; then
393 $MAKE --keep-going check || exit_status
=1
395 # Copy tap logs for the jenkins tap parser before cleaning the build dir
396 rsync
-a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests
/ "$WORKSPACE/tap"
398 # Copy the test suites top-level log which includes all tests failures
399 rsync
-a --include 'test-suite.log' --include '*/' --exclude='*' tests
/ "$WORKSPACE/log"
402 # Clean the build directory
403 if [ "$LTTNG_UST_MAKE_CLEAN" = "yes" ]; then
409 print_header
"LTTng-UST build script ended with: $(test $exit_status == 0 && echo SUCCESS || echo FAILURE)"
411 # Exit with failure if any of the tests failed
415 # vim: expandtab tabstop=4 shiftwidth=4