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
39 # Shellcheck flags the following functions that are unused as "unreachable",
42 # shellcheck disable=SC2317
46 [ "$res" -eq "0" ] ||
[ "$res" -eq "2" ]
49 # shellcheck disable=SC2317
51 vercomp
"$1" "$2"; local res
="$?"
55 # shellcheck disable=SC2317
57 vercomp
"$1" "$2"; local res
="$?"
58 [ "$res" -eq "0" ] ||
[ "$res" -eq "1" ]
61 # shellcheck disable=SC2317
63 vercomp
"$1" "$2"; local res
="$?"
67 # shellcheck disable=SC2317
69 vercomp
"$1" "$2"; local res
="$?"
76 # On MacOSX, mktemp doesn't respect TMPDIR in the same way as many
77 # other systems. Use the final positional argument to force the
78 # tempfile or tempdir to be created inside $TMPDIR, which must
80 if [ -n "${TMPDIR}" ] ; then
81 mktemp
"${@}" "${TMPDIR}/tmp.XXXXXXXXXX"
99 message_len
="${#message}"
100 padding_len
=$
(( (80 - (message_len
)) / 2 ))
102 printf '\n'; printf -- '#%.0s' {1.
.80}; printf '\n'
103 printf -- '-%.0s' {1.
.80}; printf '\n'
104 printf -- '#%.0s' $
(seq 1 $padding_len); printf '%s' "$message"; printf -- '#%.0s' $
(seq 1 $padding_len); printf '\n'
105 printf -- '-%.0s' {1.
.80}; printf '\n'
106 printf -- '#%.0s' {1.
.80}; printf '\n\n'
112 # Assume we are in the configured build directory
113 print_header
"BEGIN config.log"
115 print_header
"END config.log"
119 print_header
"Babeltrace build script starting"
122 WORKSPACE
=${WORKSPACE:-}
125 platform
=${platform:-}
130 # Build steps that can be overriden by the environment
131 BABELTRACE_MAKE_INSTALL
="${BABELTRACE_MAKE_INSTALL:-yes}"
132 BABELTRACE_MAKE_CLEAN
="${BABELTRACE_MAKE_CLEAN:-yes}"
133 BABELTRACE_GEN_COMPILE_COMMANDS
="${BABELTRACE_GEN_COMPILE_COMMANDS:-no}"
134 BABELTRACE_RUN_TESTS
="${BABELTRACE_RUN_TESTS:-yes}"
135 BABELTRACE_CLANG_TIDY
="${BABELTRACE_CLANG_TIDY:-no}"
137 SRCDIR
="$WORKSPACE/src/babeltrace"
138 TMPDIR
="$WORKSPACE/tmp"
141 LIBDIR_ARCH
="$LIBDIR"
143 # RHEL and SLES both use lib64 but don't bother shipping a default autoconf
144 # site config that matches this.
145 if [[ ( -f /etc
/redhat-release ||
-f /etc
/products.d
/SLES.prod ||
-f /etc
/yocto-release
) ]]; then
146 # Detect the userspace bitness in a distro agnostic way
147 if file -L /bin
/bash |
grep '64-bit' >/dev
/null
2>&1; then
148 LIBDIR_ARCH
="${LIBDIR}64"
154 # Use bear to generate compile_commands.json when enabled
156 if [ "$BABELTRACE_GEN_COMPILE_COMMANDS" = "yes" ]; then
160 # Create tmp directory
165 export CFLAGS
="-g -O2"
166 export CXXFLAGS
="-g -O2"
168 # Set compiler variables
175 export CC
=gcc-
${cc#gcc-}
176 export CXX
=g
++-${cc#gcc-}
183 export CC
=clang-
${cc#clang-}
184 export CXX
=clang
++-${cc#clang-}
187 if [ "x$cc" != "x" ]; then
194 # Set platform variables
199 export NPROC
="getconf _NPROCESSORS_ONLN"
200 export PATH
="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
201 export CFLAGS
="$CFLAGS -Wno-\#pragma-messages" # Fix warnings with clang14
202 export CPPFLAGS
="-I/opt/local/include"
203 export LDFLAGS
="-L/opt/local/lib"
204 export PYTHON
="python3"
205 export PYTHON_CONFIG
="python3-config"
211 export NPROC
="getconf _NPROCESSORS_ONLN"
212 export CPPFLAGS
="-I/usr/local/include"
213 export LDFLAGS
="-L/usr/local/lib"
214 export PYTHON
="python3"
215 export PYTHON_CONFIG
="python3-config"
218 export YACC
="bison -y"
225 export PYTHON
="python3"
226 export PYTHON_CONFIG
="python3-config"
230 # Some warning flags are very dumb in GCC 4.8 on SLES12 / EL7, disable them
231 # even if they are available.
232 if [[ $platform = sles12sp5
* ]] ||
[[ $platform = el7
* ]]; then
233 CFLAGS
="$CFLAGS -Wno-missing-field-initializers -Wno-shadow"
234 CXXFLAGS
="$CXXFLAGS -Wno-missing-field-initializers -Wno-shadow"
237 # Print build env details
238 print_header
"Build environment details"
239 print_hardware || true
241 print_tooling || true
243 # Enter the source directory
246 # Run bootstrap in the source directory prior to configure
247 print_header
"Bootstrap autotools"
250 # Get source version from configure script
251 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
252 PACKAGE_VERSION
=${PACKAGE_VERSION//\-pre*/}
254 # Enable dev mode by default for BT 2.0 builds
255 export BABELTRACE_DEBUG_MODE
=1
256 export BABELTRACE_DEV_MODE
=1
257 export BABELTRACE_MINIMAL_LOG_LEVEL
=TRACE
259 # Set configure options and environment variables for each build
261 CONF_OPTS
=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH" "--disable-maintainer-mode")
263 # -Werror is enabled by default in stable-2.0 but won't be in 2.1
264 # Explicitly disable it for consistency.
265 if vergte
"$PACKAGE_VERSION" "2.0"; then
266 CONF_OPTS
+=("--disable-Werror")
271 print_header
"Conf: Static lib only"
273 CONF_OPTS
+=("--enable-static" "--disable-shared")
275 if vergte
"$PACKAGE_VERSION" "2.0"; then
276 CONF_OPTS
+=("--enable-built-in-plugins")
281 print_header
"Conf: Python bindings"
283 CONF_OPTS
+=("--enable-python-bindings")
285 if vergte
"$PACKAGE_VERSION" "2.0"; then
286 CONF_OPTS
+=("--enable-python-bindings-doc" "--enable-python-plugins")
291 print_header
"Conf: Production"
293 # Unset the developper variables
294 unset BABELTRACE_DEBUG_MODE
295 unset BABELTRACE_DEV_MODE
296 unset BABELTRACE_MINIMAL_LOG_LEVEL
298 # Enable the python bindings
299 CONF_OPTS
+=("--enable-python-bindings" "--enable-python-plugins")
303 print_header
"Conf: Documentation"
305 CONF_OPTS
+=("--enable-python-bindings" "--enable-python-bindings-doc" "--enable-python-plugins" "--enable-api-doc")
309 print_header
"Conf: Address Sanitizer"
311 # --enable-asan was introduced after 2.0 but don't check the version, we
312 # want this configuration to fail if ASAN is unavailable.
313 CONF_OPTS
+=("--enable-asan" "--enable-python-bindings" "--enable-python-plugins")
317 print_header
"Conf: Minimal"
321 print_header
"Conf: Standard"
323 # Enable the python bindings / plugins by default with babeltrace2,
324 # the test suite is mostly useless without it.
325 if vergte
"$PACKAGE_VERSION" "2.0"; then
326 CONF_OPTS
+=("--enable-python-bindings" "--enable-python-plugins")
329 # Something is broken in docbook-xml on yocto
330 if [[ "$platform" = yocto
* ]]; then
331 CONF_OPTS
+=("--disable-man-pages")
337 # oot : out-of-tree build
338 # dist : build via make dist
339 # oot-dist: build via make dist out-of-tree
340 # * : normal tree build
342 # Make sure to move to the build directory and run configure
346 print_header
"Build: Out of tree"
348 # Create and enter a temporary build directory
349 builddir
=$
(mktemp_compat
-d)
352 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
356 print_header
"Build: Distribution In-tree"
358 # Run configure and generate the tar file
359 # in the source directory
360 .
/configure || failed_configure
363 # Create and enter a temporary build directory
364 builddir
=$
(mktemp_compat
-d)
367 # Extract the distribution tar in the build directory,
368 # ignore the first directory level
369 $TAR xvf
"$SRCDIR"/*.
tar.
* --strip 1
371 # Build in extracted source tree
372 .
/configure
"${CONF_OPTS[@]}" || failed_configure
376 print_header
"Build: Distribution Out of tree"
378 # Create and enter a temporary build directory
379 builddir
=$
(mktemp_compat
-d)
382 # Run configure out of tree and generate the tar file
383 "$SRCDIR/configure" || failed_configure
386 dist_srcdir
="$(mktemp_compat -d)"
389 # Extract the distribution tar in the new source directory,
390 # ignore the first directory level
391 $TAR xvf
"$builddir"/*.
tar.
* --strip 1
393 # Create and enter a second temporary build directory
394 builddir
="$(mktemp_compat -d)"
397 # Run configure from the extracted distribution tar,
398 # out of the source tree
399 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
403 print_header
"Build: Standard In-tree"
404 .
/configure
"${CONF_OPTS[@]}" || failed_configure
408 # We are now inside a configured build directory
411 print_header
"BUILD!"
412 $BEAR ${BEAR:+--} $MAKE -j "$($NPROC)" V
=1
414 # Install in the workspace if enabled
415 if [ "$BABELTRACE_MAKE_INSTALL" = "yes" ]; then
416 print_header
"Install"
418 $MAKE install V
=1 DESTDIR
="$WORKSPACE"
420 # Cleanup rpath in executables and shared libraries
421 find "$WORKSPACE/$PREFIX/bin" -type f
-perm -0500 -exec chrpath
--delete {} \
;
422 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath
--delete {} \
;
424 # Remove libtool .la files
425 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -delete
428 # Run clang-tidy on the topmost commit
429 if [ "$BABELTRACE_CLANG_TIDY" = "yes" ]; then
430 print_header
"Run clang-tidy"
432 # This would be better by linting only the lines touched by a patch but it
433 # doesn't seem to work, the lines are always filtered and no error is
435 #git diff -U0 HEAD^ | clang-tidy-diff -p1 -j "$($NPROC)" -timeout 60 -fix
437 # Instead, run clan-tidy on all the files touched by the patch.
438 while read -r filepath
; do
439 if [[ "$filepath" =~
(\.cpp|\.hhp|\.c|\.h
)$
]]; then
440 clang-tidy
--fix-errors "$(realpath "$filepath")"
442 done < <(git diff-tree
--no-commit-id --diff-filter=d
--name-only -r HEAD
)
444 # If the tree has local changes, the formatting was incorrect
445 GIT_DIFF_OUTPUT
=$
(git
diff)
446 if [ -n "$GIT_DIFF_OUTPUT" ]; then
447 echo "Saving clang-tidy proposed fixes in clang-tidy-fixes.diff"
448 git
diff > "$WORKSPACE/clang-tidy-fixes.diff"
450 # Restore the unfixed files so they can be viewed in the warnings web
457 # Run tests if enabled
458 if [ "$BABELTRACE_RUN_TESTS" = "yes" ]; then
459 print_header
"Run test suite"
461 # Run tests, don't fail now, we want to run the archiving steps
462 $MAKE --keep-going check || exit_status
=1
464 # Copy tap logs for the jenkins tap parser before cleaning the build dir
465 rsync
-a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests
/ "$WORKSPACE/tap"
467 # Copy the test suites top-level log which includes all tests failures
468 rsync
-a --include 'test-suite.log' --include '*/' --exclude='*' tests
/ "$WORKSPACE/log"
471 # Clean the build directory
472 if [ "$BABELTRACE_MAKE_CLEAN" = "yes" ]; then
477 print_header
"Babeltrace build script ended with: $(test $exit_status == 0 && echo SUCCESS || echo FAILURE)"
479 # Exit with failure if any of the tests failed
483 # vim: expandtab tabstop=4 shiftwidth=4