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