jjb: tools: mark build as aborted on timeout.
[lttng-ci.git] / scripts / liburcu / build.sh
... / ...
CommitLineData
1#!/bin/bash
2#
3# Copyright (C) 2015 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4# Copyright (C) 2016-2020 Michael Jeanson <mjeanson@efficios.com>
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19set -exu
20
21# Version compare functions
22vercomp () {
23 set +u
24 if [[ "$1" == "$2" ]]; then
25 return 0
26 fi
27 local IFS=.
28 local i ver1=($1) ver2=($2)
29 # fill empty fields in ver1 with zeros
30 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
31 ver1[i]=0
32 done
33 for ((i=0; i<${#ver1[@]}; i++)); do
34 if [[ -z ${ver2[i]} ]]; then
35 # fill empty fields in ver2 with zeros
36 ver2[i]=0
37 fi
38 if ((10#${ver1[i]} > 10#${ver2[i]})); then
39 return 1
40 fi
41 if ((10#${ver1[i]} < 10#${ver2[i]})); then
42 return 2
43 fi
44 done
45 set -u
46 return 0
47}
48
49verlte() {
50 vercomp "$1" "$2"; local res="$?"
51 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
52}
53
54verlt() {
55 vercomp "$1" "$2"; local res="$?"
56 [ "$res" -eq "2" ]
57}
58
59vergte() {
60 vercomp "$1" "$2"; local res="$?"
61 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
62}
63
64vergt() {
65 vercomp "$1" "$2"; local res="$?"
66 [ "$res" -eq "1" ]
67}
68
69verne() {
70 vercomp "$1" "$2"; local res="$?"
71 [ "$res" -ne "0" ]
72}
73
74failed_configure() {
75 # Assume we are in the configured build directory
76 echo "#################### BEGIN config.log ####################"
77 cat config.log
78 echo "#################### END config.log ####################"
79
80 # End the build with failure
81 exit 1
82}
83
84# Required variables
85WORKSPACE=${WORKSPACE:-}
86
87arch=${arch:-}
88conf=${conf:-}
89build=${build:-}
90cc=${cc:-}
91
92
93SRCDIR="$WORKSPACE/src/liburcu"
94TMPDIR="$WORKSPACE/tmp"
95PREFIX="/build"
96
97# Create tmp directory
98rm -rf "$TMPDIR"
99mkdir -p "$TMPDIR"
100
101export TMPDIR
102export CFLAGS="-g -O2"
103
104# Set compiler variables
105case "$cc" in
106gcc)
107 export CC=gcc
108 export CXX=g++
109 ;;
110gcc-4.8)
111 export CC=gcc-4.8
112 export CXX=g++-4.8
113 ;;
114gcc-5)
115 export CC=gcc-5
116 export CXX=g++-5
117 ;;
118gcc-6)
119 export CC=gcc-6
120 export CXX=g++-6
121 ;;
122gcc-7)
123 export CC=gcc-7
124 export CXX=g++-7
125 ;;
126gcc-8)
127 export CC=gcc-8
128 export CXX=g++-8
129 ;;
130clang)
131 export CC=clang
132 export CXX=clang++
133 ;;
134clang-3.9)
135 export CC=clang-3.9
136 export CXX=clang++-3.9
137 ;;
138clang-4.0)
139 export CC=clang-4.0
140 export CXX=clang++-4.0
141 ;;
142clang-5.0)
143 export CC=clang-5.0
144 export CXX=clang++-5.0
145 ;;
146clang-6.0)
147 export CC=clang-6.0
148 export CXX=clang++-6.0
149 ;;
150clang-7)
151 export CC=clang-7
152 export CXX=clang++-7
153 ;;
154*)
155 if [ "x$cc" != "x" ]; then
156 export CC="$cc"
157 fi
158 ;;
159esac
160
161if [ "x${CC:-}" != "x" ]; then
162 echo "Selected compiler:"
163 "$CC" -v
164fi
165
166# Set platform variables
167case "$arch" in
168sol10-i386)
169 export MAKE=gmake
170 export TAR=gtar
171 export NPROC=gnproc
172 export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH"
173 export CPPFLAGS="-I/opt/csw/include"
174 export LDFLAGS="-L/opt/csw/lib -R/opt/csw/lib"
175 export PKG_CONFIG_PATH="/opt/csw/lib/pkgconfig"
176 export PYTHON="python3"
177 export PYTHON_CONFIG="python3-config"
178 ;;
179
180sol11-i386)
181 export MAKE=gmake
182 export TAR=gtar
183 export NPROC=nproc
184 export PATH="/opt/csw/bin:$PATH:/usr/perl5/bin"
185 export LD_ALTEXEC=/usr/bin/gld
186 export LD=/usr/bin/gld
187 export PYTHON="python3"
188 export PYTHON_CONFIG="python3-config"
189 export PKG_CONFIG_PATH="/usr/lib/pkgconfig"
190 ;;
191
192macos*)
193 export MAKE=make
194 export TAR=tar
195 export NPROC="getconf _NPROCESSORS_ONLN"
196 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
197 export CPPFLAGS="-I/opt/local/include"
198 export LDFLAGS="-L/opt/local/lib"
199 export PYTHON="python3"
200 export PYTHON_CONFIG="python3-config"
201 ;;
202
203freebsd)
204 export MAKE=gmake
205 export TAR=tar
206 export NPROC="getconf _NPROCESSORS_ONLN"
207 export CPPFLAGS="-I/usr/local/include"
208 export LDFLAGS="-L/usr/local/lib"
209 export PYTHON="python3"
210 export PYTHON_CONFIG="python3-config"
211 ;;
212
213*)
214 export MAKE=make
215 export TAR=tar
216 export NPROC=nproc
217 export PYTHON="python3"
218 export PYTHON_CONFIG="python3-config"
219 ;;
220esac
221
222# Print build env details
223print_os || true
224print_tooling || true
225
226# Enter the source directory
227cd "$SRCDIR"
228
229# Run bootstrap in the source directory prior to configure
230./bootstrap
231
232# Get source version from configure script
233eval "$(grep '^PACKAGE_VERSION=' ./configure)"
234PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
235
236# Set configure options and environment variables for each build
237# configuration.
238CONF_OPTS=("--prefix=$PREFIX")
239case "$conf" in
240static)
241 echo "Static lib only configuration"
242
243 CONF_OPTS+=("--enable-static" "--disable-shared")
244 ;;
245
246tls_fallback)
247 echo "Using pthread_getspecific() to emulate TLS"
248 CONF_OPTS+=("--disable-compiler-tls")
249 ;;
250
251debug-rcu)
252 echo "Enable RCU sanity checks for debugging"
253 if vergte "$PACKAGE_VERSION" "0.10"; then
254 CONF_OPTS+=("--enable-rcu-debug")
255 else
256 export CFLAGS="$CFLAGS -DDEBUG_RCU"
257 fi
258
259 echo "Enable iterator sanity validator"
260 if vergte "$PACKAGE_VERSION" "0.11"; then
261 CONF_OPTS+=("--enable-cds-lfht-iter-debug")
262 fi
263 ;;
264
265*)
266 echo "Standard configuration"
267 ;;
268esac
269
270# Build type
271# oot : out-of-tree build
272# dist : build via make dist
273# oot-dist: build via make dist out-of-tree
274# * : normal tree build
275#
276# Make sure to move to the build directory and run configure
277# before continuing.
278case "$build" in
279oot)
280 echo "Out of tree build"
281
282 # Create and enter a temporary build directory
283 builddir=$(mktemp -d)
284 cd "$builddir"
285
286 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
287 ;;
288
289dist)
290 echo "Distribution in-tree build"
291
292 # Run configure and generate the tar file
293 # in the source directory
294 ./configure || failed_configure
295 $MAKE dist
296
297 # Create and enter a temporary build directory
298 builddir=$(mktemp -d)
299 cd "$builddir"
300
301 # Extract the distribution tar in the build directory,
302 # ignore the first directory level
303 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
304
305 # Build in extracted source tree
306 ./configure "${CONF_OPTS[@]}" || failed_configure
307 ;;
308
309oot-dist)
310 echo "Distribution out of tree build"
311
312 # Create and enter a temporary build directory
313 builddir=$(mktemp -d)
314 cd "$builddir"
315
316 # Run configure out of tree and generate the tar file
317 "$SRCDIR/configure" || failed_configure
318 $MAKE dist
319
320 dist_srcdir="$(mktemp -d)"
321 cd "$dist_srcdir"
322
323 # Extract the distribution tar in the new source directory,
324 # ignore the first directory level
325 $TAR xvf "$builddir"/*.tar.* --strip 1
326
327 # Create and enter a second temporary build directory
328 builddir="$(mktemp -d)"
329 cd "$builddir"
330
331 # Run configure from the extracted distribution tar,
332 # out of the source tree
333 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
334 ;;
335
336*)
337 echo "Standard in-tree build"
338 ./configure "${CONF_OPTS[@]}" || failed_configure
339 ;;
340esac
341
342# We are now inside a configured build directory
343
344# BUILD!
345$MAKE -j "$($NPROC)" V=1
346
347# Install in the workspace
348$MAKE install DESTDIR="$WORKSPACE"
349
350# Run tests, don't fail now, we want to run the archiving steps
351failed_tests=0
352$MAKE --keep-going check || failed_tests=1
353# Only run regtest for 0.9 and up
354if vergte "$PACKAGE_VERSION" "0.9"; then
355 $MAKE --keep-going regtest || failed_tests=1
356fi
357
358# Copy tap logs for the jenkins tap parser before cleaning the build dir
359rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
360
361# The test suite prior to 0.11 did not produce TAP logs
362if verlt "$PACKAGE_VERSION" "0.11"; then
363 mkdir -p "$WORKSPACE/tap/no-log"
364 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
365 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
366fi
367
368# Clean the build directory
369$MAKE clean
370
371# Cleanup rpath in executables and shared libraries
372#find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
373find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
374
375# Remove libtool .la files
376find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
377
378# Exit with failure if any of the tests failed
379exit $failed_tests
380
381# EOF
This page took 0.02301 seconds and 4 git commands to generate.