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
="$?"
80 message_len
="${#message}"
81 padding_len
=$
(( (80 - (message_len
)) / 2 ))
83 printf '\n'; printf -- '#%.0s' {1.
.80}; printf '\n'
84 printf -- '-%.0s' {1.
.80}; printf '\n'
85 printf -- '#%.0s' $
(seq 1 $padding_len); printf '%s' "$message"; printf -- '#%.0s' $
(seq 1 $padding_len); printf '\n'
86 printf -- '-%.0s' {1.
.80}; printf '\n'
87 printf -- '#%.0s' {1.
.80}; printf '\n\n'
93 # Assume we are in the configured build directory
94 print_header
"BEGIN config.log"
96 print_header
"END config.log"
100 print_header
"Babeltrace build script starting"
103 WORKSPACE
=${WORKSPACE:-}
106 platform
=${platform:-}
111 # Build steps that can be overriden by the environment
112 BABELTRACE_MAKE_INSTALL
="${BABELTRACE_MAKE_INSTALL:-yes}"
113 BABELTRACE_MAKE_CLEAN
="${BABELTRACE_MAKE_CLEAN:-yes}"
114 BABELTRACE_GEN_COMPILE_COMMANDS
="${BABELTRACE_GEN_COMPILE_COMMANDS:-no}"
115 BABELTRACE_RUN_TESTS
="${BABELTRACE_RUN_TESTS:-yes}"
116 BABELTRACE_CLANG_TIDY
="${BABELTRACE_CLANG_TIDY:-no}"
118 SRCDIR
="$WORKSPACE/src/babeltrace"
119 TMPDIR
="$WORKSPACE/tmp"
122 LIBDIR_ARCH
="$LIBDIR"
124 # RHEL and SLES both use lib64 but don't bother shipping a default autoconf
125 # site config that matches this.
126 if [[ ( -f /etc
/redhat-release ||
-f /etc
/products.d
/SLES.prod ||
-f /etc
/yocto-release
) ]]; then
127 # Detect the userspace bitness in a distro agnostic way
128 if file -L /bin
/bash |
grep '64-bit' >/dev
/null
2>&1; then
129 LIBDIR_ARCH
="${LIBDIR}64"
135 # Use bear to generate compile_commands.json when enabled
137 if [ "$BABELTRACE_GEN_COMPILE_COMMANDS" = "yes" ]; then
141 # Create tmp directory
146 export CFLAGS
="-g -O2"
147 export CXXFLAGS
="-g -O2"
149 # Set compiler variables
156 export CC
=gcc-
${cc#gcc-}
157 export CXX
=g
++-${cc#gcc-}
164 export CC
=clang-
${cc#clang-}
165 export CXX
=clang
++-${cc#clang-}
168 if [ "x$cc" != "x" ]; then
175 # Set platform variables
180 export NPROC
="getconf _NPROCESSORS_ONLN"
181 export PATH
="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
182 export CFLAGS
="$CFLAGS -Wno-\#pragma-messages" # Fix warnings with clang14
183 export CPPFLAGS
="-I/opt/local/include"
184 export LDFLAGS
="-L/opt/local/lib"
185 export PYTHON
="python3"
186 export PYTHON_CONFIG
="python3-config"
192 export NPROC
="getconf _NPROCESSORS_ONLN"
193 export CPPFLAGS
="-I/usr/local/include"
194 export LDFLAGS
="-L/usr/local/lib"
195 export PYTHON
="python3"
196 export PYTHON_CONFIG
="python3-config"
199 export YACC
="bison -y"
206 export PYTHON
="python3"
207 export PYTHON_CONFIG
="python3-config"
211 # Print build env details
212 print_header
"Build environment details"
213 print_hardware || true
215 print_tooling || true
217 # Enter the source directory
220 # Run bootstrap in the source directory prior to configure
221 print_header
"Bootstrap autotools"
224 # Get source version from configure script
225 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
226 PACKAGE_VERSION
=${PACKAGE_VERSION//\-pre*/}
228 # Enable dev mode by default for BT 2.0 builds
229 export BABELTRACE_DEBUG_MODE
=1
230 export BABELTRACE_DEV_MODE
=1
231 export BABELTRACE_MINIMAL_LOG_LEVEL
=TRACE
233 # Set configure options and environment variables for each build
235 CONF_OPTS
=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH" "--disable-maintainer-mode")
237 # -Werror is enabled by default in stable-2.0 but won't be in 2.1
238 # Explicitly disable it for consistency.
239 if vergte
"$PACKAGE_VERSION" "2.0"; then
240 CONF_OPTS
+=("--disable-Werror")
245 print_header
"Conf: Static lib only"
247 CONF_OPTS
+=("--enable-static" "--disable-shared")
249 if vergte
"$PACKAGE_VERSION" "2.0"; then
250 CONF_OPTS
+=("--enable-built-in-plugins")
255 print_header
"Conf: Python bindings"
257 CONF_OPTS
+=("--enable-python-bindings")
259 if vergte
"$PACKAGE_VERSION" "2.0"; then
260 CONF_OPTS
+=("--enable-python-bindings-doc" "--enable-python-plugins")
265 print_header
"Conf: Production"
267 # Unset the developper variables
268 unset BABELTRACE_DEBUG_MODE
269 unset BABELTRACE_DEV_MODE
270 unset BABELTRACE_MINIMAL_LOG_LEVEL
272 # Enable the python bindings
273 CONF_OPTS
+=("--enable-python-bindings" "--enable-python-plugins")
277 print_header
"Conf: Documentation"
279 CONF_OPTS
+=("--enable-python-bindings" "--enable-python-bindings-doc" "--enable-python-plugins" "--enable-api-doc")
283 print_header
"Conf: Address Sanitizer"
285 # --enable-asan was introduced after 2.0 but don't check the version, we
286 # want this configuration to fail if ASAN is unavailable.
287 CONF_OPTS
+=("--enable-asan" "--enable-python-bindings" "--enable-python-plugins")
291 print_header
"Conf: Minimal"
295 print_header
"Conf: Standard"
297 # Enable the python bindings / plugins by default with babeltrace2,
298 # the test suite is mostly useless without it.
299 if vergte
"$PACKAGE_VERSION" "2.0"; then
300 CONF_OPTS
+=("--enable-python-bindings" "--enable-python-plugins")
303 # Something is broken in docbook-xml on yocto
304 if [[ "$platform" = yocto
* ]]; then
305 CONF_OPTS
+=("--disable-man-pages")
311 # oot : out-of-tree build
312 # dist : build via make dist
313 # oot-dist: build via make dist out-of-tree
314 # * : normal tree build
316 # Make sure to move to the build directory and run configure
320 print_header
"Build: Out of tree"
322 # Create and enter a temporary build directory
323 builddir
=$
(mktemp
-d)
326 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
330 print_header
"Build: Distribution In-tree"
332 # Run configure and generate the tar file
333 # in the source directory
334 .
/configure || failed_configure
337 # Create and enter a temporary build directory
338 builddir
=$
(mktemp
-d)
341 # Extract the distribution tar in the build directory,
342 # ignore the first directory level
343 $TAR xvf
"$SRCDIR"/*.
tar.
* --strip 1
345 # Build in extracted source tree
346 .
/configure
"${CONF_OPTS[@]}" || failed_configure
350 print_header
"Build: Distribution Out of tree"
352 # Create and enter a temporary build directory
353 builddir
=$
(mktemp
-d)
356 # Run configure out of tree and generate the tar file
357 "$SRCDIR/configure" || failed_configure
360 dist_srcdir
="$(mktemp -d)"
363 # Extract the distribution tar in the new source directory,
364 # ignore the first directory level
365 $TAR xvf
"$builddir"/*.
tar.
* --strip 1
367 # Create and enter a second temporary build directory
368 builddir
="$(mktemp -d)"
371 # Run configure from the extracted distribution tar,
372 # out of the source tree
373 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
377 print_header
"Build: Standard In-tree"
378 .
/configure
"${CONF_OPTS[@]}" || failed_configure
382 # We are now inside a configured build directory
385 print_header
"BUILD!"
386 $BEAR ${BEAR:+--} $MAKE -j "$($NPROC)" V
=1
388 # Install in the workspace if enabled
389 if [ "$BABELTRACE_MAKE_INSTALL" = "yes" ]; then
390 print_header
"Install"
392 $MAKE install V
=1 DESTDIR
="$WORKSPACE"
394 # Cleanup rpath in executables and shared libraries
395 find "$WORKSPACE/$PREFIX/bin" -type f
-perm -0500 -exec chrpath
--delete {} \
;
396 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath
--delete {} \
;
398 # Remove libtool .la files
399 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -delete
402 # Run clang-tidy on the topmost commit
403 if [ "$BABELTRACE_CLANG_TIDY" = "yes" ]; then
404 print_header
"Run clang-tidy"
406 # This would be better by linting only the lines touched by a patch but it
407 # doesn't seem to work, the lines are always filtered and no error is
409 #git diff -U0 HEAD^ | clang-tidy-diff -p1 -j "$($NPROC)" -timeout 60 -fix
411 # Instead, run clan-tidy on all the files touched by the patch.
412 while read -r filepath
; do
413 if [[ "$filepath" =~
(\.cpp|\.hhp|\.c|\.h
)$
]]; then
414 clang-tidy
--fix-errors "$(realpath "$filepath")"
416 done < <(git diff-tree
--no-commit-id --diff-filter=d
--name-only -r HEAD
)
418 # If the tree has local changes, the formatting was incorrect
419 GIT_DIFF_OUTPUT
=$
(git
diff)
420 if [ -n "$GIT_DIFF_OUTPUT" ]; then
421 echo "Saving clang-tidy proposed fixes in clang-tidy-fixes.diff"
422 git
diff > "$WORKSPACE/clang-tidy-fixes.diff"
424 # Restore the unfixed files so they can be viewed in the warnings web
431 # Run tests if enabled
432 if [ "$BABELTRACE_RUN_TESTS" = "yes" ]; then
433 print_header
"Run test suite"
435 # Run tests, don't fail now, we want to run the archiving steps
436 $MAKE --keep-going check || exit_status
=1
438 # Copy tap logs for the jenkins tap parser before cleaning the build dir
439 rsync
-a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests
/ "$WORKSPACE/tap"
441 # Copy the test suites top-level log which includes all tests failures
442 rsync
-a --include 'test-suite.log' --include '*/' --exclude='*' tests
/ "$WORKSPACE/log"
445 # Clean the build directory
446 if [ "$BABELTRACE_MAKE_CLEAN" = "yes" ]; then
451 print_header
"Babeltrace build script ended with: $(test $exit_status == 0 && echo SUCCESS || echo FAILURE)"
453 # Exit with failure if any of the tests failed
457 # vim: expandtab tabstop=4 shiftwidth=4