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