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