jjb: babeltrace: cleanup yaml job definition
[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 # Controls if the tests are run
92 BABELTRACE_RUN_TESTS="${BABELTRACE_RUN_TESTS:=yes}"
93
94 SRCDIR="$WORKSPACE/src/babeltrace"
95 TMPDIR="$WORKSPACE/tmp"
96 PREFIX="/build"
97
98 # Create tmp directory
99 rm -rf "$TMPDIR"
100 mkdir -p "$TMPDIR"
101
102 export TMPDIR
103 export CFLAGS="-g -O2"
104
105 # Set compiler variables
106 case "$cc" in
107 gcc)
108 export CC=gcc
109 export CXX=g++
110 ;;
111 gcc-*)
112 export CC=gcc-${cc#gcc-}
113 export CXX=g++-${cc#gcc-}
114 ;;
115 clang)
116 export CC=clang
117 export CXX=clang++
118 ;;
119 clang-*)
120 export CC=clang-${cc#clang-}
121 export CXX=clang++-${cc#clang-}
122 ;;
123 *)
124 if [ "x$cc" != "x" ]; then
125 export CC="$cc"
126 fi
127 ;;
128 esac
129
130 if [ "x${CC:-}" != "x" ]; then
131 echo "Selected compiler:"
132 "$CC" -v
133 fi
134
135 # Set platform variables
136 case "$arch" in
137 macos*)
138 export MAKE=make
139 export TAR=tar
140 export NPROC="getconf _NPROCESSORS_ONLN"
141 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
142 export CPPFLAGS="-I/opt/local/include"
143 export LDFLAGS="-L/opt/local/lib"
144 export PYTHON="python3.9"
145 export PYTHON_CONFIG="python3.9-config"
146 ;;
147
148 freebsd*)
149 export MAKE=gmake
150 export TAR=tar
151 export NPROC="getconf _NPROCESSORS_ONLN"
152 export CPPFLAGS="-I/usr/local/include"
153 export LDFLAGS="-L/usr/local/lib"
154 export PYTHON="python3"
155 export PYTHON_CONFIG="python3-config"
156
157 # For bt 1.5
158 export YACC="bison -y"
159 ;;
160
161 *)
162 export MAKE=make
163 export TAR=tar
164 export NPROC=nproc
165 export PYTHON="python3"
166 export PYTHON_CONFIG="python3-config"
167 ;;
168 esac
169
170 # Print build env details
171 print_os || true
172 print_tooling || true
173
174 # Enter the source directory
175 cd "$SRCDIR"
176
177 # Run bootstrap in the source directory prior to configure
178 ./bootstrap
179
180 # Get source version from configure script
181 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
182 PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
183
184 # Enable dev mode by default for BT 2.0 builds
185 export BABELTRACE_DEBUG_MODE=1
186 export BABELTRACE_DEV_MODE=1
187 export BABELTRACE_MINIMAL_LOG_LEVEL=TRACE
188
189 # Set configure options and environment variables for each build
190 # configuration.
191 CONF_OPTS=("--prefix=$PREFIX")
192
193 # -Werror is enabled by default in stable-2.0 but won't be in 2.1
194 # Explicitly disable it for consistency.
195 if vergte "$PACKAGE_VERSION" "2.0"; then
196 CONF_OPTS+=("--disable-Werror")
197 fi
198
199 case "$conf" in
200 static)
201 echo "Static lib only configuration"
202
203 CONF_OPTS+=("--enable-static" "--disable-shared")
204
205 if vergte "$PACKAGE_VERSION" "2.0"; then
206 CONF_OPTS+=("--enable-built-in-plugins")
207 fi
208 ;;
209
210 python-bindings)
211 echo "Python bindings configuration"
212
213 CONF_OPTS+=("--enable-python-bindings")
214
215 if vergte "$PACKAGE_VERSION" "2.0"; then
216 CONF_OPTS+=("--enable-python-bindings-doc" "--enable-python-plugins")
217 fi
218 ;;
219
220 prod)
221 echo "Production configuration"
222
223 # Unset the developper variables
224 unset BABELTRACE_DEBUG_MODE
225 unset BABELTRACE_DEV_MODE
226 unset BABELTRACE_MINIMAL_LOG_LEVEL
227
228 # Enable the python bindings
229 CONF_OPTS+=("--enable-python-bindings" "--enable-python-bindings-doc" "--enable-python-plugins")
230 ;;
231
232 min)
233 echo "Minimal configuration"
234 ;;
235
236 *)
237 echo "Standard configuration"
238
239 # Enable the python bindings / plugins by default with babeltrace2,
240 # the test suite is mostly useless without it.
241 if vergte "$PACKAGE_VERSION" "2.0"; then
242 CONF_OPTS+=("--enable-python-bindings" "--enable-python-plugins")
243 fi
244 ;;
245 esac
246
247 # Build type
248 # oot : out-of-tree build
249 # dist : build via make dist
250 # oot-dist: build via make dist out-of-tree
251 # * : normal tree build
252 #
253 # Make sure to move to the build directory and run configure
254 # before continuing.
255 case "$build" in
256 oot)
257 echo "Out of tree build"
258
259 # Create and enter a temporary build directory
260 builddir=$(mktemp -d)
261 cd "$builddir"
262
263 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
264 ;;
265
266 dist)
267 echo "Distribution in-tree build"
268
269 # Run configure and generate the tar file
270 # in the source directory
271 ./configure || failed_configure
272 $MAKE dist
273
274 # Create and enter a temporary build directory
275 builddir=$(mktemp -d)
276 cd "$builddir"
277
278 # Extract the distribution tar in the build directory,
279 # ignore the first directory level
280 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
281
282 # Build in extracted source tree
283 ./configure "${CONF_OPTS[@]}" || failed_configure
284 ;;
285
286 oot-dist)
287 echo "Distribution out of tree build"
288
289 # Create and enter a temporary build directory
290 builddir=$(mktemp -d)
291 cd "$builddir"
292
293 # Run configure out of tree and generate the tar file
294 "$SRCDIR/configure" || failed_configure
295 $MAKE dist
296
297 dist_srcdir="$(mktemp -d)"
298 cd "$dist_srcdir"
299
300 # Extract the distribution tar in the new source directory,
301 # ignore the first directory level
302 $TAR xvf "$builddir"/*.tar.* --strip 1
303
304 # Create and enter a second temporary build directory
305 builddir="$(mktemp -d)"
306 cd "$builddir"
307
308 # Run configure from the extracted distribution tar,
309 # out of the source tree
310 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
311 ;;
312
313 *)
314 echo "Standard in-tree build"
315 ./configure "${CONF_OPTS[@]}" || failed_configure
316 ;;
317 esac
318
319 # We are now inside a configured build directory
320
321 # BUILD!
322 $MAKE -j "$($NPROC)" V=1
323
324 # Install in the workspace
325 $MAKE install DESTDIR="$WORKSPACE"
326
327 # Run tests, don't fail now, we want to run the archiving steps
328 failed_tests=0
329 if [ "$BABELTRACE_RUN_TESTS" = "yes" ]; then
330 $MAKE --keep-going check || failed_tests=1
331
332 # Copy tap logs for the jenkins tap parser before cleaning the build dir
333 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$WORKSPACE/tap"
334
335 # The test suite prior to 1.5 did not produce TAP logs
336 if verlt "$PACKAGE_VERSION" "1.5"; then
337 mkdir -p "$WORKSPACE/tap/no-log"
338 echo "1..1" > "$WORKSPACE/tap/no-log/tests.log"
339 echo "ok 1 - Test suite doesn't support logging" >> "$WORKSPACE/tap/no-log/tests.log"
340 fi
341 fi
342
343 # Clean the build directory
344 $MAKE clean
345
346 # Cleanup rpath in executables and shared libraries
347 find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
348 find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
349
350 # Remove libtool .la files
351 find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
352
353 # Exit with failure if any of the tests failed
354 exit $failed_tests
355
356 # EOF
This page took 0.037077 seconds and 4 git commands to generate.