jjb: Update MacOS jobs for Big Sur and arm64
[lttng-ci.git] / scripts / lttng-tools / build.sh
1 #!/bin/bash
2 # shellcheck disable=SC2103
3 #
4 # Copyright (C) 2016 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
5 # Copyright (C) 2016-2020 Michael Jeanson <mjeanson@efficios.com>
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 set -exu
21
22 # Version compare functions
23 vercomp () {
24 set +u
25 if [[ "$1" == "$2" ]]; then
26 return 0
27 fi
28 local IFS=.
29 local i ver1=($1) ver2=($2)
30 # fill empty fields in ver1 with zeros
31 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
32 ver1[i]=0
33 done
34 for ((i=0; i<${#ver1[@]}; i++)); do
35 if [[ -z ${ver2[i]} ]]; then
36 # fill empty fields in ver2 with zeros
37 ver2[i]=0
38 fi
39 if ((10#${ver1[i]} > 10#${ver2[i]})); then
40 return 1
41 fi
42 if ((10#${ver1[i]} < 10#${ver2[i]})); then
43 return 2
44 fi
45 done
46 set -u
47 return 0
48 }
49
50 verlte() {
51 vercomp "$1" "$2"; local res="$?"
52 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
53 }
54
55 verlt() {
56 vercomp "$1" "$2"; local res="$?"
57 [ "$res" -eq "2" ]
58 }
59
60 vergte() {
61 vercomp "$1" "$2"; local res="$?"
62 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
63 }
64
65 vergt() {
66 vercomp "$1" "$2"; local res="$?"
67 [ "$res" -eq "1" ]
68 }
69
70 verne() {
71 vercomp "$1" "$2"; local res="$?"
72 [ "$res" -ne "0" ]
73 }
74
75 failed_configure() {
76 # Assume we are in the configured build directory
77 echo "#################### BEGIN config.log ####################"
78 cat config.log
79 echo "#################### END config.log ####################"
80
81 # End the build with failure
82 exit 1
83 }
84
85 # Required variables
86 WORKSPACE=${WORKSPACE:-}
87
88 arch=${arch:-}
89 conf=${conf:-}
90 build=${build:-}
91 cc=${cc:-}
92 test_type=${test_type:-}
93
94 DEPS_INC="$WORKSPACE/deps/build/include"
95 DEPS_LIB="$WORKSPACE/deps/build/lib"
96 DEPS_PKGCONFIG="$DEPS_LIB/pkgconfig"
97 DEPS_BIN="$WORKSPACE/deps/build/bin"
98 DEPS_JAVA="$WORKSPACE/deps/build/share/java"
99
100 export PATH="$DEPS_BIN:$PATH"
101 export LD_LIBRARY_PATH="$DEPS_LIB:${LD_LIBRARY_PATH:-}"
102 export PKG_CONFIG_PATH="$DEPS_PKGCONFIG"
103 export CPPFLAGS="-I$DEPS_INC"
104 export LDFLAGS="-L$DEPS_LIB"
105
106 SRCDIR="$WORKSPACE/src/lttng-tools"
107 TAPDIR="$WORKSPACE/tap"
108 PREFIX="/build"
109
110
111 # Create tmp directory
112 TMPDIR="$WORKSPACE/tmp"
113 mkdir -p "$TMPDIR"
114
115 # Use a symlink in /tmp to point to the the tmp directory
116 # inside the workspace, this is to work around the path length
117 # limit of unix sockets which are created by the test suite.
118 tmpdir="$(mktemp)"
119 ln -sf "$TMPDIR" "$tmpdir"
120 export TMPDIR="$tmpdir"
121
122 # Create a symlink to "babeltrace" when the "babeltrace2" executable is found.
123 # This is a temporary workaround until lttng-tools either allows the override of
124 # the trace reader in its test suite or that we move to only supporting
125 # babeltrace2
126 if [ -x "$DEPS_BIN/babeltrace2" ]; then
127 ln -s "$DEPS_BIN/babeltrace2" "$DEPS_BIN/babeltrace"
128 fi
129
130 # When using babeltrace2 make sure that it finds its plugins and
131 # plugin-providers.
132 export BABELTRACE_PLUGIN_PATH="$DEPS_LIB/babeltrace2/plugins/"
133 export LIBBABELTRACE2_PLUGIN_PROVIDER_DIR="$DEPS_LIB/babeltrace2/plugin-providers/"
134
135 export CFLAGS="-g -O2"
136
137 # Set compiler variables
138 case "$cc" in
139 gcc)
140 export CC=gcc
141 export CXX=g++
142 ;;
143 gcc-4.8)
144 export CC=gcc-4.8
145 export CXX=g++-4.8
146 ;;
147 gcc-5)
148 export CC=gcc-5
149 export CXX=g++-5
150 ;;
151 gcc-6)
152 export CC=gcc-6
153 export CXX=g++-6
154 ;;
155 gcc-7)
156 export CC=gcc-7
157 export CXX=g++-7
158 ;;
159 gcc-8)
160 export CC=gcc-8
161 export CXX=g++-8
162 ;;
163 clang)
164 export CC=clang
165 export CXX=clang++
166 ;;
167 clang-3.9)
168 export CC=clang-3.9
169 export CXX=clang++-3.9
170 ;;
171 clang-4.0)
172 export CC=clang-4.0
173 export CXX=clang++-4.0
174 ;;
175 clang-5.0)
176 export CC=clang-5.0
177 export CXX=clang++-5.0
178 ;;
179 clang-6.0)
180 export CC=clang-6.0
181 export CXX=clang++-6.0
182 ;;
183 clang-7)
184 export CC=clang-7
185 export CXX=clang++-7
186 ;;
187 *)
188 if [ "x$cc" != "x" ]; then
189 export CC="$cc"
190 fi
191 ;;
192 esac
193
194 if [ "x${CC:-}" != "x" ]; then
195 echo "Selected compiler:"
196 "$CC" -v
197 fi
198
199 # Set platform variables
200 case "$arch" in
201 sol10-i386)
202 export MAKE=gmake
203 export TAR=gtar
204 export NPROC=gnproc
205 export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH"
206 export CPPFLAGS="-I/opt/csw/include -D_XOPEN_SOURCE=500 $CPPFLAGS"
207 export LDFLAGS="-L/opt/csw/lib -R/opt/csw/lib $LDFLAGS"
208 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/opt/csw/lib/pkgconfig"
209 export PYTHON="python3"
210 export PYTHON_CONFIG="python3-config"
211
212 RUN_TESTS="no"
213 ;;
214
215 sol11-i386)
216 export MAKE=gmake
217 export TAR=gtar
218 export NPROC=nproc
219 export PATH="/opt/csw/bin:$PATH:/usr/perl5/bin"
220 export CPPFLAGS="-D_XOPEN_SOURCE=500 $CPPFLAGS"
221 export PYTHON="python3"
222 export PYTHON_CONFIG="python3-config"
223 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/lib/pkgconfig"
224
225 RUN_TESTS="no"
226 ;;
227
228 macos*)
229 export MAKE=make
230 export TAR=tar
231 export NPROC="getconf _NPROCESSORS_ONLN"
232 export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
233 export CPPFLAGS="-I/opt/local/include $CPPFLAGS"
234 export LDFLAGS="-L/opt/local/lib $LDFLAGS"
235 export PYTHON="python3"
236 export PYTHON_CONFIG="python3-config"
237
238 RUN_TESTS="no"
239 ;;
240
241 cygwin|cygwin64|msys32|msys64)
242 export MAKE=make
243 export TAR=tar
244 export NPROC=nproc
245
246 RUN_TESTS="no"
247 ;;
248
249 *)
250 export MAKE=make
251 export TAR=tar
252 export NPROC=nproc
253
254 RUN_TESTS="yes"
255
256 PYTHON2=python2
257 PYTHON3=python3
258
259 P2_VERSION=$($PYTHON2 -c "import sys;print(sys.version[:3])")
260 P3_VERSION=$($PYTHON3 -c "import sys;print(sys.version[:3])")
261
262 DEPS_PYTHON2="$WORKSPACE/deps/build/lib/python$P2_VERSION/site-packages"
263 DEPS_PYTHON3="$WORKSPACE/deps/build/lib/python$P3_VERSION/site-packages"
264 ;;
265 esac
266
267 case "$test_type" in
268 full)
269 RUN_TESTS_LONG_REGRESSION="yes"
270 ;;
271 *)
272 RUN_TESTS_LONG_REGRESSION="no"
273 ;;
274 esac
275
276 # If we have modules, build them
277 if [ -d "$WORKSPACE/src/lttng-modules" ]; then
278 cd "$WORKSPACE/src/lttng-modules"
279 $MAKE -j"$($NPROC)" V=1
280 $MAKE modules_install V=1
281 depmod
282 fi
283
284 # Print build env details
285 print_os || true
286 print_tooling || true
287
288 # Enter the source directory
289 cd "$SRCDIR"
290
291 # Run bootstrap in the source directory prior to configure
292 ./bootstrap
293
294 # Get source version from configure script
295 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
296 PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
297
298
299 # The switch to build without UST changed in 2.8
300 if vergte "$PACKAGE_VERSION" "2.8"; then
301 NO_UST="--without-lttng-ust"
302 else
303 NO_UST="--disable-lttng-ust"
304 fi
305
306 # Most build configs require the python bindings
307 CONF_OPTS=("--prefix=$PREFIX" "--enable-python-bindings")
308
309 DIST_CONF_OPTS=()
310
311 # Set configure options and environment variables for each build
312 # configuration.
313 case "$conf" in
314 static)
315 echo "Static lib only configuration"
316
317 CONF_OPTS+=("--enable-static" "--disable-shared")
318 ;;
319
320 no-ust)
321 echo "Build without UST support"
322 CONF_OPTS+=("$NO_UST")
323 DIST_CONF_OPTS+=("$NO_UST")
324 ;;
325
326 agents)
327 echo "Java and Python agents configuration"
328
329 export JAVA_HOME="/usr/lib/jvm/default-java"
330 export CLASSPATH="$DEPS_JAVA/*:/usr/share/java/*"
331 export PYTHONPATH="$DEPS_PYTHON2:$DEPS_PYTHON3"
332
333 CONF_OPTS+=("--enable-test-java-agent-all" "--enable-test-python-agent-all")
334 ;;
335
336 relayd-only)
337 echo "Relayd only configuration"
338
339 CONF_OPTS=("--prefix=$PREFIX" "--disable-bin-lttng" "--disable-bin-lttng-consumerd" "--disable-bin-lttng-crash" "--disable-bin-lttng-sessiond" "--disable-extras" "--disable-man-pages" "$NO_UST")
340 ;;
341
342 debug-rcu)
343 echo "Enable RCU sanity checks for debugging"
344
345 export CPPFLAGS="$CPPFLAGS -DDEBUG_RCU"
346 ;;
347
348 *)
349 echo "Standard configuration"
350 ;;
351 esac
352
353 # Build type
354 # oot : out-of-tree build
355 # dist : build via make dist
356 # oot-dist: build via make dist out-of-tree
357 # * : normal tree build
358 #
359 # Make sure to move to the build directory and run configure
360 # before continuing.
361 case "$build" in
362 oot)
363 echo "Out of tree build"
364
365 # Create and enter a temporary build directory
366 builddir=$(mktemp -d)
367 cd "$builddir"
368
369 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
370 ;;
371
372 dist)
373 echo "Distribution in-tree build"
374
375 # Run configure and generate the tar file
376 # in the source directory
377 ./configure "${DIST_CONF_OPTS[@]}" || failed_configure
378 $MAKE dist
379
380 # Create and enter a temporary build directory
381 builddir=$(mktemp -d)
382 cd "$builddir"
383
384 # Extract the distribution tar in the build directory,
385 # ignore the first directory level
386 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
387
388 # Build in extracted source tree
389 ./configure "${CONF_OPTS[@]}" || failed_configure
390 ;;
391
392 oot-dist)
393 echo "Distribution out of tree build"
394
395 # Create and enter a temporary build directory
396 builddir=$(mktemp -d)
397 cd "$builddir"
398
399 # Run configure out of tree and generate the tar file
400 "$SRCDIR/configure" "${DIST_CONF_OPTS[@]}" || failed_configure
401 $MAKE dist
402
403 dist_srcdir="$(mktemp -d)"
404 cd "$dist_srcdir"
405
406 # Extract the distribution tar in the new source directory,
407 # ignore the first directory level
408 $TAR xvf "$builddir"/*.tar.* --strip 1
409
410 # Create and enter a second temporary build directory
411 builddir="$(mktemp -d)"
412 cd "$builddir"
413
414 # Run configure from the extracted distribution tar,
415 # out of the source tree
416 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
417 ;;
418
419 *)
420 echo "Standard in-tree build"
421 ./configure "${CONF_OPTS[@]}" || failed_configure
422 ;;
423 esac
424
425 # We are now inside a configured build directory
426
427 # BUILD!
428 $MAKE -j "$($NPROC)" V=1
429
430 # Install in the workspace
431 $MAKE install DESTDIR="$WORKSPACE"
432
433 # Run tests for all configs except 'no-ust'
434 failed_tests=0
435 if [ "$RUN_TESTS" = "yes" ] && [ "$conf" != "no-ust" ]; then
436 # Allow core dumps
437 ulimit -c unlimited
438
439 # Force the lttng-sessiond path to /bin/true to prevent the spawing of a
440 # lttng-sessiond --daemonize on "lttng create"
441 export LTTNG_SESSIOND_PATH="/bin/true"
442
443 # Run 'unit_tests', 2.8 and up has a new test suite
444 if vergte "$PACKAGE_VERSION" "2.8"; then
445 make --keep-going check || failed_tests=1
446 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$TAPDIR"
447 else
448 cd tests
449 mkdir -p "$TAPDIR/unit"
450 mkdir -p "$TAPDIR/fast_regression"
451 mkdir -p "$TAPDIR/with_bindings_regression"
452 prove --merge -v --exec '' - < unit_tests --archive "$TAPDIR/unit/" || failed_tests=1
453 prove --merge -v --exec '' - < fast_regression --archive "$TAPDIR/fast_regression/" || failed_tests=1
454 prove --merge -v --exec '' - < with_bindings_regression --archive "$TAPDIR/with_bindings_regression/" || failed_tests=1
455 cd ..
456 fi
457
458 if [ "$RUN_TESTS_LONG_REGRESSION" = "yes" ]; then
459 cd tests
460 mkdir -p "$TAPDIR/long_regression"
461 prove --merge -v --exec '' - < long_regression --archive "$TAPDIR/long_regression/" || failed_tests=1
462 cd ..
463 fi
464
465 # TAP plugin is having a hard time with .yml files.
466 find "$TAPDIR" -name "meta.yml" -exec rm -f {} \;
467 else
468 # The TAP plugin will fail the job if no test logs are present
469 mkdir -p "$TAPDIR/no-tests"
470 echo "1..1" > "$TAPDIR/no-tests/tests.log"
471 echo "ok 1 - Test suite disabled" >> "$TAPDIR/no-tests/tests.log"
472 fi
473
474 # Clean the build directory
475 $MAKE clean
476
477 # Cleanup rpath in executables and shared libraries
478 find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
479 find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
480
481 # Remove libtool .la files
482 find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
483
484 # Exit with failure if any of the tests failed
485 exit $failed_tests
486
487 # EOF
This page took 0.04481 seconds and 5 git commands to generate.