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
"Liburcu build script starting"
96 WORKSPACE
=${WORKSPACE:-}
99 platform
=${platform:-}
104 # Build steps that can be overriden by the environment
105 USERSPACE_RCU_MAKE_INSTALL
="${USERSPACE_RCU_MAKE_INSTALL:-yes}"
106 USERSPACE_RCU_MAKE_CLEAN
="${USERSPACE_RCU_MAKE_CLEAN:-yes}"
107 USERSPACE_RCU_GEN_COMPILE_COMMANDS
="${USERSPACE_RCU_GEN_COMPILE_COMMANDS:-no}"
108 USERSPACE_RCU_RUN_TESTS
="${USERSPACE_RCU_RUN_TESTS:-yes}"
109 USERSPACE_RCU_CLANG_TIDY
="${USERSPACE_RCU_CLANG_TIDY:-no}"
111 SRCDIR
="$WORKSPACE/src/liburcu"
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"
128 # Use bear to generate compile_commands.json when enabled
130 if [ "$USERSPACE_RCU_GEN_COMPILE_COMMANDS" = "yes" ]; then
134 # Create tmp directory
139 export CFLAGS
="-g -O2"
140 export CXXFLAGS
="-g -O2"
142 # Set compiler variables
149 export CC
=gcc-
${cc#gcc-}
150 export CXX
=g
++-${cc#gcc-}
157 export CC
=clang-
${cc#clang-}
158 export CXX
=clang
++-${cc#clang-}
161 if [ "x$cc" != "x" ]; then
167 # Set platform variables
172 export NPROC
="getconf _NPROCESSORS_ONLN"
173 export PATH
="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
174 export CPPFLAGS
="-I/opt/local/include"
175 export LDFLAGS
="-L/opt/local/lib"
176 export PYTHON
="python3"
177 export PYTHON_CONFIG
="python3-config"
183 export NPROC
="getconf _NPROCESSORS_ONLN"
184 export CPPFLAGS
="-I/usr/local/include"
185 export LDFLAGS
="-L/usr/local/lib"
186 export PYTHON
="python3"
187 export PYTHON_CONFIG
="python3-config"
194 export PYTHON
="python3"
195 export PYTHON_CONFIG
="python3-config"
199 # Print build env details
200 print_header
"Build environment details"
202 print_tooling || true
204 # Enter the source directory
207 # Run bootstrap in the source directory prior to configure
208 print_header
"Bootstrap autotools"
211 # Get source version from configure script
212 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
213 PACKAGE_VERSION
=${PACKAGE_VERSION//\-pre*/}
215 # Set configure options and environment variables for each build
217 CONF_OPTS
=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH" "--disable-maintainer-mode")
220 print_header
"Conf: Static lib only"
222 CONF_OPTS
+=("--enable-static" "--disable-shared")
226 print_header
"Conf: Use pthread_getspecific() to emulate TLS"
228 CONF_OPTS
+=("--disable-compiler-tls")
232 print_header
"Conf: Enable RCU sanity checks for debugging"
234 if vergte
"$PACKAGE_VERSION" "0.10"; then
235 CONF_OPTS
+=("--enable-rcu-debug")
237 export CFLAGS
="$CFLAGS -DDEBUG_RCU"
240 echo "Enable iterator sanity validator"
241 if vergte
"$PACKAGE_VERSION" "0.11"; then
242 CONF_OPTS
+=("--enable-cds-lfht-iter-debug")
247 print_header
"Conf: Enable the use of compiler atomic builtins."
249 CONF_OPTS
+=("--enable-compiler-atomic-builtins")
253 print_header
"Conf: Standard"
258 # oot : out-of-tree build
259 # dist : build via make dist
260 # oot-dist: build via make dist out-of-tree
261 # * : normal tree build
263 # Make sure to move to the build directory and run configure
267 print_header
"Build: Out of tree"
269 # Create and enter a temporary build directory
270 builddir
=$
(mktemp
-d)
273 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
277 print_header
"Build: Distribution In-tree"
279 # Run configure and generate the tar file
280 # in the source directory
281 .
/configure || failed_configure
284 # Create and enter a temporary build directory
285 builddir
=$
(mktemp
-d)
288 # Extract the distribution tar in the build directory,
289 # ignore the first directory level
290 $TAR xvf
"$SRCDIR"/*.
tar.
* --strip 1
292 # Build in extracted source tree
293 .
/configure
"${CONF_OPTS[@]}" || failed_configure
297 print_header
"Build: Distribution Out of tree"
299 # Create and enter a temporary build directory
300 builddir
=$
(mktemp
-d)
303 # Run configure out of tree and generate the tar file
304 "$SRCDIR/configure" || failed_configure
307 dist_srcdir
="$(mktemp -d)"
310 # Extract the distribution tar in the new source directory,
311 # ignore the first directory level
312 $TAR xvf
"$builddir"/*.
tar.
* --strip 1
314 # Create and enter a second temporary build directory
315 builddir
="$(mktemp -d)"
318 # Run configure from the extracted distribution tar,
319 # out of the source tree
320 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
324 print_header
"Build: Standard In-tree"
326 .
/configure
"${CONF_OPTS[@]}" || failed_configure
330 # We are now inside a configured build directory
333 print_header
"BUILD!"
334 $BEAR ${BEAR:+--} $MAKE -j "$($NPROC)" V
=1
336 # Install in the workspace if enabled
337 if [ "$USERSPACE_RCU_MAKE_INSTALL" = "yes" ]; then
338 print_header
"Install"
340 $MAKE install V
=1 DESTDIR
="$WORKSPACE"
342 # Cleanup rpath in executables and shared libraries
343 #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
344 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath
--delete {} \
;
346 # Remove libtool .la files
347 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -delete
350 # Run clang-tidy on the topmost commit
351 if [ "$USERSPACE_RCU_CLANG_TIDY" = "yes" ]; then
352 print_header
"Run clang-tidy"
354 # This would be better by linting only the lines touched by a patch but it
355 # doesn't seem to work, the lines are always filtered and no error is
357 #git diff -U0 HEAD^ | clang-tidy-diff -p1 -j "$($NPROC)" -timeout 60 -fix
359 # Instead, run clan-tidy on all the files touched by the patch.
360 while read -r filepath
; do
361 if [[ "$filepath" =~
(\.cpp|\.hhp|\.c|\.h
)$
]]; then
362 clang-tidy
--fix-errors "$(realpath "$filepath")"
364 done < <(git diff-tree
--no-commit-id --diff-filter=d
--name-only -r HEAD
)
366 # If the tree has local changes, the formatting was incorrect
367 GIT_DIFF_OUTPUT
=$
(git
diff)
368 if [ -n "$GIT_DIFF_OUTPUT" ]; then
369 echo "Saving clang-tidy proposed fixes in clang-tidy-fixes.diff"
370 git
diff > "$WORKSPACE/clang-tidy-fixes.diff"
372 # Restore the unfixed files so they can be viewed in the warnings web
379 # Run tests if enabled
380 if [ "$USERSPACE_RCU_RUN_TESTS" = "yes" ]; then
381 print_header
"Run test suite"
383 # Run tests, don't fail now, we want to run the archiving steps
384 $MAKE --keep-going check || exit_status
=1
386 # Only run regtest for 0.9 and up
387 if vergte
"$PACKAGE_VERSION" "0.9"; then
388 $MAKE --keep-going regtest || exit_status
=1
391 # Copy tap logs for the jenkins tap parser before cleaning the build dir
392 rsync
-a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests
/ "$WORKSPACE/tap"
394 # Copy the test suites top-level log which includes all tests failures
395 rsync
-a --include 'test-suite.log' --include '*/' --exclude='*' tests
/ "$WORKSPACE/log"
397 # The test suite prior to 0.11 did not produce TAP logs
398 if verlt
"$PACKAGE_VERSION" "0.11"; then
399 mkdir
-p "$WORKSPACE/tap/no-log"
400 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
401 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
405 # Clean the build directory
406 if [ "$USERSPACE_RCU_MAKE_CLEAN" = "yes" ]; then
411 print_header
"Liburcu build script ended with: $(test $exit_status == 0 && echo SUCCESS || echo FAILURE)"
413 # Exit with failure if any of the tests failed
417 # vim: expandtab tabstop=4 shiftwidth=4