Commit | Line | Data |
---|---|---|
51c9c62d | 1 | #!/bin/bash |
e3022ad9 | 2 | # |
2c34ea14 MJ |
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 | |
e3022ad9 | 6 | |
51c9c62d MJ |
7 | set -exu |
8 | ||
5fd8db76 | 9 | # Version compare functions |
0a6e708b MJ |
10 | vercomp () { |
11 | set +u | |
12 | if [[ "$1" == "$2" ]]; then | |
13 | return 0 | |
14 | fi | |
15 | local IFS=. | |
4afa623f MJ |
16 | # Ignore the shellcheck warning, we want splitting to happen based on IFS. |
17 | # shellcheck disable=SC2206 | |
0a6e708b MJ |
18 | local i ver1=($1) ver2=($2) |
19 | # fill empty fields in ver1 with zeros | |
20 | for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do | |
21 | ver1[i]=0 | |
22 | done | |
23 | for ((i=0; i<${#ver1[@]}; i++)); do | |
24 | if [[ -z ${ver2[i]} ]]; then | |
25 | # fill empty fields in ver2 with zeros | |
26 | ver2[i]=0 | |
27 | fi | |
28 | if ((10#${ver1[i]} > 10#${ver2[i]})); then | |
29 | return 1 | |
30 | fi | |
31 | if ((10#${ver1[i]} < 10#${ver2[i]})); then | |
32 | return 2 | |
33 | fi | |
34 | done | |
35 | set -u | |
36 | return 0 | |
37 | } | |
38 | ||
5fd8db76 | 39 | verlte() { |
0a6e708b MJ |
40 | vercomp "$1" "$2"; local res="$?" |
41 | [ "$res" -eq "0" ] || [ "$res" -eq "2" ] | |
5fd8db76 MJ |
42 | } |
43 | ||
44 | verlt() { | |
0a6e708b MJ |
45 | vercomp "$1" "$2"; local res="$?" |
46 | [ "$res" -eq "2" ] | |
5fd8db76 MJ |
47 | } |
48 | ||
49 | vergte() { | |
0a6e708b MJ |
50 | vercomp "$1" "$2"; local res="$?" |
51 | [ "$res" -eq "0" ] || [ "$res" -eq "1" ] | |
5fd8db76 MJ |
52 | } |
53 | ||
54 | vergt() { | |
0a6e708b MJ |
55 | vercomp "$1" "$2"; local res="$?" |
56 | [ "$res" -eq "1" ] | |
57 | } | |
58 | ||
59 | verne() { | |
60 | vercomp "$1" "$2"; local res="$?" | |
61 | [ "$res" -ne "0" ] | |
5fd8db76 MJ |
62 | } |
63 | ||
52be5739 KS |
64 | mktemp_compat() { |
65 | case "$platform" in | |
66 | macos*) | |
67 | # On MacOSX, mktemp doesn't respect TMPDIR in the same way as many | |
68 | # other systems. Use the final positional argument to force the | |
69 | # tempfile or tempdir to be created inside $TMPDIR, which must | |
70 | # already exist. | |
71 | if [ -n "${TMPDIR}" ] ; then | |
72 | mktemp "${@}" "${TMPDIR}/tmp.XXXXXXXXXX" | |
73 | else | |
74 | mktemp "${@}" | |
75 | fi | |
76 | ;; | |
77 | *) | |
78 | mktemp "${@}" | |
79 | ;; | |
80 | esac | |
81 | } | |
82 | ||
2c34ea14 MJ |
83 | print_header() { |
84 | set +x | |
85 | ||
86 | local message=" $1 " | |
87 | local message_len | |
88 | local padding_len | |
89 | ||
90 | message_len="${#message}" | |
91 | padding_len=$(( (80 - (message_len)) / 2 )) | |
92 | ||
93 | printf '\n'; printf -- '#%.0s' {1..80}; printf '\n' | |
94 | printf -- '-%.0s' {1..80}; printf '\n' | |
95 | printf -- '#%.0s' $(seq 1 $padding_len); printf '%s' "$message"; printf -- '#%.0s' $(seq 1 $padding_len); printf '\n' | |
96 | printf -- '-%.0s' {1..80}; printf '\n' | |
97 | printf -- '#%.0s' {1..80}; printf '\n\n' | |
98 | ||
99 | set -x | |
100 | } | |
101 | ||
51c9c62d MJ |
102 | failed_configure() { |
103 | # Assume we are in the configured build directory | |
2c34ea14 | 104 | print_header "BEGIN config.log" |
51c9c62d | 105 | cat config.log |
2c34ea14 | 106 | print_header "END config.log" |
51c9c62d MJ |
107 | |
108 | # End the build with failure | |
109 | exit 1 | |
110 | } | |
111 | ||
2c34ea14 MJ |
112 | print_header "Liburcu build script starting" |
113 | ||
1d56e325 MJ |
114 | # Required variables |
115 | WORKSPACE=${WORKSPACE:-} | |
116 | ||
2c34ea14 | 117 | # Axis |
1794bc79 | 118 | platform=${platform:-} |
a57a60d9 MJ |
119 | conf=${conf:-} |
120 | build=${build:-} | |
1d56e325 | 121 | cc=${cc:-} |
a57a60d9 | 122 | |
2c34ea14 MJ |
123 | # Build steps that can be overriden by the environment |
124 | USERSPACE_RCU_MAKE_INSTALL="${USERSPACE_RCU_MAKE_INSTALL:-yes}" | |
125 | USERSPACE_RCU_MAKE_CLEAN="${USERSPACE_RCU_MAKE_CLEAN:-yes}" | |
126 | USERSPACE_RCU_GEN_COMPILE_COMMANDS="${USERSPACE_RCU_GEN_COMPILE_COMMANDS:-no}" | |
127 | USERSPACE_RCU_RUN_TESTS="${USERSPACE_RCU_RUN_TESTS:-yes}" | |
128 | USERSPACE_RCU_CLANG_TIDY="${USERSPACE_RCU_CLANG_TIDY:-no}" | |
e3022ad9 | 129 | |
6d35c326 MJ |
130 | SRCDIR="$WORKSPACE/src/liburcu" |
131 | TMPDIR="$WORKSPACE/tmp" | |
1d56e325 | 132 | PREFIX="/build" |
4afa623f | 133 | LIBDIR="lib" |
32dde2a3 | 134 | LIBDIR_ARCH="$LIBDIR" |
4afa623f | 135 | |
fe7cc0c9 MJ |
136 | CONF_OPTS=() |
137 | ||
4afa623f MJ |
138 | # RHEL and SLES both use lib64 but don't bother shipping a default autoconf |
139 | # site config that matches this. | |
47ca4354 | 140 | if [[ ( -f /etc/redhat-release || -f /etc/products.d/SLES.prod || -f /etc/yocto-release ) ]]; then |
85322e5d MJ |
141 | # Detect the userspace bitness in a distro agnostic way |
142 | if file -L /bin/bash | grep '64-bit' >/dev/null 2>&1; then | |
143 | LIBDIR_ARCH="${LIBDIR}64" | |
85322e5d | 144 | fi |
4afa623f | 145 | fi |
69d7af71 | 146 | |
2c34ea14 MJ |
147 | exit_status=0 |
148 | ||
149 | # Use bear to generate compile_commands.json when enabled | |
150 | BEAR="" | |
151 | if [ "$USERSPACE_RCU_GEN_COMPILE_COMMANDS" = "yes" ]; then | |
152 | BEAR="bear" | |
153 | fi | |
154 | ||
1d56e325 MJ |
155 | # Create tmp directory |
156 | rm -rf "$TMPDIR" | |
157 | mkdir -p "$TMPDIR" | |
6d35c326 MJ |
158 | |
159 | export TMPDIR | |
72d087d4 | 160 | export CFLAGS="-g -O2" |
2c34ea14 | 161 | export CXXFLAGS="-g -O2" |
6d35c326 | 162 | |
1d56e325 MJ |
163 | # Set compiler variables |
164 | case "$cc" in | |
165 | gcc) | |
166 | export CC=gcc | |
167 | export CXX=g++ | |
168 | ;; | |
d954b6a8 MJ |
169 | gcc-*) |
170 | export CC=gcc-${cc#gcc-} | |
171 | export CXX=g++-${cc#gcc-} | |
1d56e325 MJ |
172 | ;; |
173 | clang) | |
174 | export CC=clang | |
175 | export CXX=clang++ | |
176 | ;; | |
d954b6a8 MJ |
177 | clang-*) |
178 | export CC=clang-${cc#clang-} | |
179 | export CXX=clang++-${cc#clang-} | |
1d56e325 MJ |
180 | ;; |
181 | *) | |
182 | if [ "x$cc" != "x" ]; then | |
183 | export CC="$cc" | |
184 | fi | |
185 | ;; | |
186 | esac | |
187 | ||
72f4f0c1 | 188 | # Set platform variables |
1794bc79 | 189 | case "$platform" in |
f0d7e5b1 | 190 | macos*) |
995ac8f2 MJ |
191 | export MAKE=make |
192 | export TAR=tar | |
193 | export NPROC="getconf _NPROCESSORS_ONLN" | |
f7bf4d7a | 194 | export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" |
1d56e325 MJ |
195 | export CPPFLAGS="-I/opt/local/include" |
196 | export LDFLAGS="-L/opt/local/lib" | |
00f7bb3f MJ |
197 | export PYTHON="python3" |
198 | export PYTHON_CONFIG="python3-config" | |
f7bf4d7a MJ |
199 | ;; |
200 | ||
d954b6a8 | 201 | freebsd*) |
6ad0e7e6 MJ |
202 | export MAKE=gmake |
203 | export TAR=tar | |
204 | export NPROC="getconf _NPROCESSORS_ONLN" | |
205 | export CPPFLAGS="-I/usr/local/include" | |
206 | export LDFLAGS="-L/usr/local/lib" | |
207 | export PYTHON="python3" | |
208 | export PYTHON_CONFIG="python3-config" | |
209 | ;; | |
210 | ||
fe7cc0c9 MJ |
211 | cygwin*) |
212 | export MAKE=make | |
213 | export TAR=tar | |
214 | export NPROC=nproc | |
215 | ||
216 | # Work around a bug in GCC's emutls on cygwin which results in a deadlock | |
217 | # in test_perthreadlock | |
218 | CONF_OPTS+=("--disable-compiler-tls") | |
219 | ;; | |
220 | ||
7491c28d | 221 | *) |
995ac8f2 MJ |
222 | export MAKE=make |
223 | export TAR=tar | |
224 | export NPROC=nproc | |
1d56e325 MJ |
225 | export PYTHON="python3" |
226 | export PYTHON_CONFIG="python3-config" | |
7491c28d MJ |
227 | ;; |
228 | esac | |
229 | ||
51c9c62d | 230 | # Print build env details |
2c34ea14 | 231 | print_header "Build environment details" |
8c956c4b | 232 | print_hardware || true |
51c9c62d MJ |
233 | print_os || true |
234 | print_tooling || true | |
235 | ||
cd9733d5 JR |
236 | # Enter the source directory |
237 | cd "$SRCDIR" | |
238 | ||
239 | # Run bootstrap in the source directory prior to configure | |
2c34ea14 | 240 | print_header "Bootstrap autotools" |
cd9733d5 JR |
241 | ./bootstrap |
242 | ||
243 | # Get source version from configure script | |
244 | eval "$(grep '^PACKAGE_VERSION=' ./configure)" | |
1d56e325 | 245 | PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/} |
cd9733d5 JR |
246 | |
247 | # Set configure options and environment variables for each build | |
248 | # configuration. | |
fe7cc0c9 | 249 | CONF_OPTS+=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH" "--disable-maintainer-mode") |
56162e2a JRJ |
250 | case "$conf" in |
251 | static) | |
2c34ea14 | 252 | print_header "Conf: Static lib only" |
1d56e325 MJ |
253 | |
254 | CONF_OPTS+=("--enable-static" "--disable-shared") | |
56162e2a | 255 | ;; |
72f4f0c1 | 256 | |
a57a60d9 | 257 | tls_fallback) |
2c34ea14 MJ |
258 | print_header "Conf: Use pthread_getspecific() to emulate TLS" |
259 | ||
1d56e325 | 260 | CONF_OPTS+=("--disable-compiler-tls") |
56162e2a | 261 | ;; |
72f4f0c1 | 262 | |
cd9733d5 | 263 | debug-rcu) |
2c34ea14 MJ |
264 | print_header "Conf: Enable RCU sanity checks for debugging" |
265 | ||
a0493692 | 266 | if vergte "$PACKAGE_VERSION" "0.10"; then |
1d56e325 | 267 | CONF_OPTS+=("--enable-rcu-debug") |
cd9733d5 | 268 | else |
72d087d4 | 269 | export CFLAGS="$CFLAGS -DDEBUG_RCU" |
cd9733d5 | 270 | fi |
25e13783 JR |
271 | |
272 | echo "Enable iterator sanity validator" | |
273 | if vergte "$PACKAGE_VERSION" "0.11"; then | |
1d56e325 | 274 | CONF_OPTS+=("--enable-cds-lfht-iter-debug") |
25e13783 | 275 | fi |
cd9733d5 JR |
276 | ;; |
277 | ||
5e1966cf MJ |
278 | atomic-builtins) |
279 | print_header "Conf: Enable the use of compiler atomic builtins." | |
280 | ||
281 | CONF_OPTS+=("--enable-compiler-atomic-builtins") | |
282 | ;; | |
283 | ||
56162e2a | 284 | *) |
2c34ea14 | 285 | print_header "Conf: Standard" |
56162e2a JRJ |
286 | ;; |
287 | esac | |
288 | ||
595a34c7 | 289 | # Build type |
1d56e325 MJ |
290 | # oot : out-of-tree build |
291 | # dist : build via make dist | |
292 | # oot-dist: build via make dist out-of-tree | |
293 | # * : normal tree build | |
595a34c7 | 294 | # |
1d56e325 | 295 | # Make sure to move to the build directory and run configure |
69d7af71 | 296 | # before continuing. |
595a34c7 | 297 | case "$build" in |
72f4f0c1 | 298 | oot) |
2c34ea14 | 299 | print_header "Build: Out of tree" |
69d7af71 | 300 | |
1d56e325 | 301 | # Create and enter a temporary build directory |
52be5739 | 302 | builddir=$(mktemp_compat -d) |
1d56e325 | 303 | cd "$builddir" |
69d7af71 | 304 | |
51c9c62d | 305 | "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure |
72f4f0c1 MJ |
306 | ;; |
307 | ||
308 | dist) | |
2c34ea14 | 309 | print_header "Build: Distribution In-tree" |
1d56e325 MJ |
310 | |
311 | # Run configure and generate the tar file | |
312 | # in the source directory | |
51c9c62d | 313 | ./configure || failed_configure |
1d56e325 MJ |
314 | $MAKE dist |
315 | ||
316 | # Create and enter a temporary build directory | |
52be5739 | 317 | builddir=$(mktemp_compat -d) |
1d56e325 MJ |
318 | cd "$builddir" |
319 | ||
320 | # Extract the distribution tar in the build directory, | |
321 | # ignore the first directory level | |
322 | $TAR xvf "$SRCDIR"/*.tar.* --strip 1 | |
323 | ||
324 | # Build in extracted source tree | |
51c9c62d | 325 | ./configure "${CONF_OPTS[@]}" || failed_configure |
1d56e325 MJ |
326 | ;; |
327 | ||
328 | oot-dist) | |
2c34ea14 | 329 | print_header "Build: Distribution Out of tree" |
72f4f0c1 | 330 | |
1d56e325 | 331 | # Create and enter a temporary build directory |
52be5739 | 332 | builddir=$(mktemp_compat -d) |
1d56e325 | 333 | cd "$builddir" |
69d7af71 | 334 | |
1d56e325 | 335 | # Run configure out of tree and generate the tar file |
51c9c62d | 336 | "$SRCDIR/configure" || failed_configure |
72f4f0c1 MJ |
337 | $MAKE dist |
338 | ||
52be5739 | 339 | dist_srcdir="$(mktemp_compat -d)" |
1d56e325 | 340 | cd "$dist_srcdir" |
72f4f0c1 | 341 | |
1d56e325 MJ |
342 | # Extract the distribution tar in the new source directory, |
343 | # ignore the first directory level | |
344 | $TAR xvf "$builddir"/*.tar.* --strip 1 | |
72f4f0c1 | 345 | |
1d56e325 | 346 | # Create and enter a second temporary build directory |
52be5739 | 347 | builddir="$(mktemp_compat -d)" |
1d56e325 MJ |
348 | cd "$builddir" |
349 | ||
350 | # Run configure from the extracted distribution tar, | |
351 | # out of the source tree | |
51c9c62d | 352 | "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure |
72f4f0c1 | 353 | ;; |
1d56e325 | 354 | |
72f4f0c1 | 355 | *) |
2c34ea14 MJ |
356 | print_header "Build: Standard In-tree" |
357 | ||
51c9c62d | 358 | ./configure "${CONF_OPTS[@]}" || failed_configure |
72f4f0c1 | 359 | ;; |
595a34c7 JR |
360 | esac |
361 | ||
1d56e325 MJ |
362 | # We are now inside a configured build directory |
363 | ||
72f4f0c1 | 364 | # BUILD! |
2c34ea14 MJ |
365 | print_header "BUILD!" |
366 | $BEAR ${BEAR:+--} $MAKE -j "$($NPROC)" V=1 | |
367 | ||
368 | # Install in the workspace if enabled | |
369 | if [ "$USERSPACE_RCU_MAKE_INSTALL" = "yes" ]; then | |
370 | print_header "Install" | |
371 | ||
372 | $MAKE install V=1 DESTDIR="$WORKSPACE" | |
373 | ||
374 | # Cleanup rpath in executables and shared libraries | |
375 | #find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \; | |
376 | find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath --delete {} \; | |
377 | ||
378 | # Remove libtool .la files | |
379 | find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -delete | |
380 | fi | |
381 | ||
382 | # Run clang-tidy on the topmost commit | |
383 | if [ "$USERSPACE_RCU_CLANG_TIDY" = "yes" ]; then | |
384 | print_header "Run clang-tidy" | |
72f4f0c1 | 385 | |
2c34ea14 MJ |
386 | # This would be better by linting only the lines touched by a patch but it |
387 | # doesn't seem to work, the lines are always filtered and no error is | |
388 | # reported. | |
389 | #git diff -U0 HEAD^ | clang-tidy-diff -p1 -j "$($NPROC)" -timeout 60 -fix | |
1d56e325 | 390 | |
2c34ea14 MJ |
391 | # Instead, run clan-tidy on all the files touched by the patch. |
392 | while read -r filepath; do | |
d7d5a1ba | 393 | if [[ "$filepath" =~ (\.cpp|\.hpp|\.c|\.h)$ ]]; then |
2c34ea14 MJ |
394 | clang-tidy --fix-errors "$(realpath "$filepath")" |
395 | fi | |
396 | done < <(git diff-tree --no-commit-id --diff-filter=d --name-only -r HEAD) | |
397 | ||
398 | # If the tree has local changes, the formatting was incorrect | |
399 | GIT_DIFF_OUTPUT=$(git diff) | |
400 | if [ -n "$GIT_DIFF_OUTPUT" ]; then | |
401 | echo "Saving clang-tidy proposed fixes in clang-tidy-fixes.diff" | |
402 | git diff > "$WORKSPACE/clang-tidy-fixes.diff" | |
403 | ||
404 | # Restore the unfixed files so they can be viewed in the warnings web | |
405 | # interface | |
406 | git checkout . | |
407 | exit_status=1 | |
408 | fi | |
409 | fi | |
410 | ||
411 | # Run tests if enabled | |
aff4e3d1 | 412 | if [ "$USERSPACE_RCU_RUN_TESTS" = "yes" ]; then |
2c34ea14 MJ |
413 | print_header "Run test suite" |
414 | ||
415 | # Run tests, don't fail now, we want to run the archiving steps | |
416 | $MAKE --keep-going check || exit_status=1 | |
417 | ||
aff4e3d1 JR |
418 | # Only run regtest for 0.9 and up |
419 | if vergte "$PACKAGE_VERSION" "0.9"; then | |
2c34ea14 | 420 | $MAKE --keep-going regtest || exit_status=1 |
aff4e3d1 | 421 | fi |
72f4f0c1 | 422 | |
aff4e3d1 JR |
423 | # Copy tap logs for the jenkins tap parser before cleaning the build dir |
424 | rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap" | |
69d7af71 | 425 | |
4174b905 MJ |
426 | # Copy the test suites top-level log which includes all tests failures |
427 | rsync -a --include 'test-suite.log' --include '*/' --exclude='*' tests/ "$WORKSPACE/log" | |
428 | ||
aff4e3d1 JR |
429 | # The test suite prior to 0.11 did not produce TAP logs |
430 | if verlt "$PACKAGE_VERSION" "0.11"; then | |
431 | mkdir -p "$WORKSPACE/tap/no-log" | |
432 | echo "1..1" > "$WORKSPACE/tap/no-log/tests.log" | |
433 | echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log" | |
434 | fi | |
e5d878d8 MJ |
435 | fi |
436 | ||
1d56e325 | 437 | # Clean the build directory |
2c34ea14 MJ |
438 | if [ "$USERSPACE_RCU_MAKE_CLEAN" = "yes" ]; then |
439 | print_header "Clean" | |
440 | $MAKE clean | |
441 | fi | |
72f4f0c1 | 442 | |
2c34ea14 | 443 | print_header "Liburcu build script ended with: $(test $exit_status == 0 && echo SUCCESS || echo FAILURE)" |
595a34c7 | 444 | |
1d56e325 | 445 | # Exit with failure if any of the tests failed |
2c34ea14 | 446 | exit $exit_status |
7491c28d MJ |
447 | |
448 | # EOF | |
2c34ea14 | 449 | # vim: expandtab tabstop=4 shiftwidth=4 |