jjb: extend 'libdir = lib64' to yocto
[lttng-ci.git] / scripts / lttng-tools / build.sh
CommitLineData
51c9c62d 1#!/bin/bash
09d45745 2# shellcheck disable=SC2103
b4005bbf 3#
09d45745 4# Copyright (C) 2016 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
7361d941 5# Copyright (C) 2016-2020 Michael Jeanson <mjeanson@efficios.com>
b4005bbf
MJ
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
51c9c62d
MJ
20set -exu
21
0cdaa21c 22# Version compare functions
b6e62a6a
MJ
23vercomp () {
24 set +u
25 if [[ "$1" == "$2" ]]; then
26 return 0
27 fi
28 local IFS=.
4afa623f
MJ
29 # Ignore the shellcheck warning, we want splitting to happen based on IFS.
30 # shellcheck disable=SC2206
b6e62a6a
MJ
31 local i ver1=($1) ver2=($2)
32 # fill empty fields in ver1 with zeros
33 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
34 ver1[i]=0
35 done
36 for ((i=0; i<${#ver1[@]}; i++)); do
37 if [[ -z ${ver2[i]} ]]; then
38 # fill empty fields in ver2 with zeros
39 ver2[i]=0
40 fi
41 if ((10#${ver1[i]} > 10#${ver2[i]})); then
42 return 1
43 fi
44 if ((10#${ver1[i]} < 10#${ver2[i]})); then
45 return 2
46 fi
47 done
48 set -u
49 return 0
50}
51
0cdaa21c 52verlte() {
b6e62a6a
MJ
53 vercomp "$1" "$2"; local res="$?"
54 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
0cdaa21c
MJ
55}
56
57verlt() {
b6e62a6a
MJ
58 vercomp "$1" "$2"; local res="$?"
59 [ "$res" -eq "2" ]
0cdaa21c
MJ
60}
61
62vergte() {
b6e62a6a
MJ
63 vercomp "$1" "$2"; local res="$?"
64 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
0cdaa21c
MJ
65}
66
67vergt() {
b6e62a6a
MJ
68 vercomp "$1" "$2"; local res="$?"
69 [ "$res" -eq "1" ]
70}
71
72verne() {
73 vercomp "$1" "$2"; local res="$?"
74 [ "$res" -ne "0" ]
0cdaa21c
MJ
75}
76
51c9c62d
MJ
77failed_configure() {
78 # Assume we are in the configured build directory
79 echo "#################### BEGIN config.log ####################"
80 cat config.log
81 echo "#################### END config.log ####################"
82
83 # End the build with failure
84 exit 1
85}
86
54c3c7ec
JR
87set_execute_traversal_bit()
88{
89 path=$1
90
91 level="$path"
92 if [ ! -d "$path" ]; then
93 fail "Path is not a directory"
94 fi
95 while level="$(dirname "$level")"
96 do
97 if [ "$level" = / ]; then
98 break
99 fi
100 chmod a+x "$level"
101 done
102 chmod a+x "$path"
103}
104
09d45745
MJ
105# Required variables
106WORKSPACE=${WORKSPACE:-}
107
5fcae288 108platform=${platform:-}
212d2afd
MJ
109conf=${conf:-}
110build=${build:-}
09d45745 111cc=${cc:-}
9699c0e7 112test_type=${test_type:-}
b4005bbf 113
4afa623f
MJ
114SRCDIR="$WORKSPACE/src/lttng-tools"
115TAPDIR="$WORKSPACE/tap"
116PREFIX="/build"
117LIBDIR="lib"
118
119# RHEL and SLES both use lib64 but don't bother shipping a default autoconf
120# site config that matches this.
85322e5d
MJ
121if [[ ( -f /etc/redhat-release || -f /etc/SuSE-release || -f /etc/yocto-release ) ]]; then
122 # Detect the userspace bitness in a distro agnostic way
123 if file -L /bin/bash | grep '64-bit' >/dev/null 2>&1; then
124 LIBDIR_ARCH="${LIBDIR}64"
125 else
126 LIBDIR_ARCH="$LIBDIR"
127 fi
4afa623f
MJ
128fi
129
09d45745 130DEPS_INC="$WORKSPACE/deps/build/include"
4afa623f 131DEPS_LIB="$WORKSPACE/deps/build/$LIBDIR_ARCH"
b8bdba8f 132DEPS_PKGCONFIG="$DEPS_LIB/pkgconfig"
09d45745
MJ
133DEPS_BIN="$WORKSPACE/deps/build/bin"
134DEPS_JAVA="$WORKSPACE/deps/build/share/java"
135
136export PATH="$DEPS_BIN:$PATH"
137export LD_LIBRARY_PATH="$DEPS_LIB:${LD_LIBRARY_PATH:-}"
b8bdba8f 138export PKG_CONFIG_PATH="$DEPS_PKGCONFIG"
09d45745
MJ
139export CPPFLAGS="-I$DEPS_INC"
140export LDFLAGS="-L$DEPS_LIB"
141
212d2afd 142
09d45745
MJ
143# Create tmp directory
144TMPDIR="$WORKSPACE/tmp"
145mkdir -p "$TMPDIR"
212d2afd 146
09d45745
MJ
147# Use a symlink in /tmp to point to the the tmp directory
148# inside the workspace, this is to work around the path length
149# limit of unix sockets which are created by the test suite.
150tmpdir="$(mktemp)"
151ln -sf "$TMPDIR" "$tmpdir"
152export TMPDIR="$tmpdir"
b4005bbf 153
481eadc8
JR
154# Create a symlink to "babeltrace" when the "babeltrace2" executable is found.
155# This is a temporary workaround until lttng-tools either allows the override of
156# the trace reader in its test suite or that we move to only supporting
157# babeltrace2
158if [ -x "$DEPS_BIN/babeltrace2" ]; then
65444f1c 159 ln -s "$DEPS_BIN/babeltrace2" "$DEPS_BIN/babeltrace"
481eadc8
JR
160fi
161
162# When using babeltrace2 make sure that it finds its plugins and
163# plugin-providers.
164export BABELTRACE_PLUGIN_PATH="$DEPS_LIB/babeltrace2/plugins/"
165export LIBBABELTRACE2_PLUGIN_PROVIDER_DIR="$DEPS_LIB/babeltrace2/plugin-providers/"
166
09d45745 167export CFLAGS="-g -O2"
fdb66460 168export CXXFLAGS="-g -O2"
b4005bbf 169
09d45745
MJ
170# Set compiler variables
171case "$cc" in
172gcc)
173 export CC=gcc
174 export CXX=g++
175 ;;
176gcc-4.8)
177 export CC=gcc-4.8
178 export CXX=g++-4.8
179 ;;
180gcc-5)
181 export CC=gcc-5
182 export CXX=g++-5
183 ;;
184gcc-6)
185 export CC=gcc-6
186 export CXX=g++-6
187 ;;
188gcc-7)
189 export CC=gcc-7
190 export CXX=g++-7
191 ;;
192gcc-8)
193 export CC=gcc-8
194 export CXX=g++-8
195 ;;
196clang)
197 export CC=clang
198 export CXX=clang++
199 ;;
200clang-3.9)
201 export CC=clang-3.9
202 export CXX=clang++-3.9
203 ;;
204clang-4.0)
205 export CC=clang-4.0
206 export CXX=clang++-4.0
207 ;;
208clang-5.0)
209 export CC=clang-5.0
210 export CXX=clang++-5.0
211 ;;
212clang-6.0)
213 export CC=clang-6.0
214 export CXX=clang++-6.0
215 ;;
216clang-7)
217 export CC=clang-7
218 export CXX=clang++-7
219 ;;
220*)
221 if [ "x$cc" != "x" ]; then
65444f1c 222 export CC="$cc"
09d45745
MJ
223 fi
224 ;;
225esac
b4005bbf 226
09d45745
MJ
227if [ "x${CC:-}" != "x" ]; then
228 echo "Selected compiler:"
229 "$CC" -v
230fi
b4005bbf 231
0cdaa21c 232# Set platform variables
5fcae288 233case "$platform" in
f0d7e5b1 234macos*)
09d45745
MJ
235 export MAKE=make
236 export TAR=tar
237 export NPROC="getconf _NPROCESSORS_ONLN"
238 export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
239 export CPPFLAGS="-I/opt/local/include $CPPFLAGS"
240 export LDFLAGS="-L/opt/local/lib $LDFLAGS"
00f7bb3f
MJ
241 export PYTHON="python3"
242 export PYTHON_CONFIG="python3-config"
b6e62a6a 243
aff4e3d1 244 LTTNG_TOOLS_RUN_TESTS="no"
b6e62a6a
MJ
245 ;;
246
61afb3c3 247cygwin|cygwin64|msys32|msys64)
09d45745
MJ
248 export MAKE=make
249 export TAR=tar
250 export NPROC=nproc
251
aff4e3d1 252 LTTNG_TOOLS_RUN_TESTS="no"
61afb3c3
MJ
253 ;;
254
0cdaa21c 255*)
09d45745
MJ
256 export MAKE=make
257 export TAR=tar
258 export NPROC=nproc
259
aff4e3d1 260 LTTNG_TOOLS_RUN_TESTS="yes"
0cdaa21c
MJ
261
262 PYTHON2=python2
263 PYTHON3=python3
264
b4c6a892
MJ
265 if command -v $PYTHON2 >/dev/null 2>&1; then
266 P2_VERSION=$($PYTHON2 -c 'import sys;v = sys.version.split()[0].split("."); print("{}.{}".format(v[0], v[1]))')
4afa623f
MJ
267 DEPS_PYTHON2="$WORKSPACE/deps/build/$LIBDIR/python$P2_VERSION/site-packages"
268 if [ "$LIBDIR" != "$LIBDIR_ARCH" ]; then
269 DEPS_PYTHON2="$DEPS_PYTHON2:$WORKSPACE/deps/build/$LIBDIR_ARCH/python$P2_VERSION/site-packages"
270 fi
b4c6a892 271 fi
0cdaa21c 272
b4c6a892 273 P3_VERSION=$($PYTHON3 -c 'import sys;v = sys.version.split()[0].split("."); print("{}.{}".format(v[0], v[1]))')
4afa623f
MJ
274 DEPS_PYTHON3="$WORKSPACE/deps/build/$LIBDIR/python$P3_VERSION/site-packages"
275 if [ "$LIBDIR" != "$LIBDIR_ARCH" ]; then
276 DEPS_PYTHON3="$DEPS_PYTHON3:$WORKSPACE/deps/build/$LIBDIR_ARCH/python$P3_VERSION/site-packages"
277 fi
de7e8d55
JG
278
279 # Most build configs require access to the babeltrace 2 python bindings.
280 # This also makes the lttngust python agent available for `agents` builds.
281 export PYTHONPATH="${DEPS_PYTHON2:-}${DEPS_PYTHON2:+:}$DEPS_PYTHON3"
0cdaa21c
MJ
282 ;;
283esac
284
fdb66460 285# The missing-field-initializers warning code is very dumb in GCC 4.8 on
29d9c2b2
MJ
286# SLES12 / EL7, disable it even if it's available.
287if [[ $platform = sles12sp5* ]] || [[ $platform = el7* ]]; then
65444f1c
MJ
288 CFLAGS="$CFLAGS -Wno-missing-field-initializers"
289 CXXFLAGS="$CXXFLAGS -Wno-missing-field-initializers"
fdb66460
MJ
290fi
291
9699c0e7 292case "$test_type" in
9699c0e7 293full)
aff4e3d1 294 LTTNG_TOOLS_RUN_TESTS_LONG_REGRESSION="yes"
09d45745 295 ;;
9699c0e7 296*)
aff4e3d1 297 LTTNG_TOOLS_RUN_TESTS_LONG_REGRESSION="no"
09d45745 298 ;;
9699c0e7 299esac
0cdaa21c 300
7361d941
MJ
301# If we have modules, build them
302if [ -d "$WORKSPACE/src/lttng-modules" ]; then
303 cd "$WORKSPACE/src/lttng-modules"
304 $MAKE -j"$($NPROC)" V=1
305 $MAKE modules_install V=1
306 depmod
307fi
308
51c9c62d
MJ
309# Print build env details
310print_os || true
311print_tooling || true
312
212d2afd
MJ
313# Enter the source directory
314cd "$SRCDIR"
315
316# Run bootstrap in the source directory prior to configure
0cdaa21c
MJ
317./bootstrap
318
319# Get source version from configure script
212d2afd 320eval "$(grep '^PACKAGE_VERSION=' ./configure)"
09d45745 321PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
0cdaa21c 322
b4005bbf 323
0cdaa21c
MJ
324# The switch to build without UST changed in 2.8
325if vergte "$PACKAGE_VERSION" "2.8"; then
326 NO_UST="--without-lttng-ust"
327else
328 NO_UST="--disable-lttng-ust"
329fi
b4005bbf 330
6c3ec80e 331# Most build configs require the python bindings
4afa623f 332CONF_OPTS=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH" "--enable-python-bindings")
6c3ec80e 333
edb933dd
MJ
334DIST_CONF_OPTS=()
335
09d45745
MJ
336# Set configure options and environment variables for each build
337# configuration.
b4005bbf 338case "$conf" in
0cdaa21c 339static)
09d45745
MJ
340 echo "Static lib only configuration"
341
342 CONF_OPTS+=("--enable-static" "--disable-shared")
0cdaa21c
MJ
343 ;;
344
0cdaa21c
MJ
345no-ust)
346 echo "Build without UST support"
09d45745 347 CONF_OPTS+=("$NO_UST")
edb933dd 348 DIST_CONF_OPTS+=("$NO_UST")
0cdaa21c
MJ
349 ;;
350
67122b96 351agents)
09d45745
MJ
352 echo "Java and Python agents configuration"
353
0cdaa21c 354 export JAVA_HOME="/usr/lib/jvm/default-java"
61c5ba32 355 export CLASSPATH="$DEPS_JAVA/lttng-ust-agent-all.jar:/usr/share/java/log4j-api.jar:/usr/share/java/log4j-core.jar:/usr/share/java/log4j-1.2.jar"
0cdaa21c 356
09d45745 357 CONF_OPTS+=("--enable-test-java-agent-all" "--enable-test-python-agent-all")
d51c467a
MJ
358
359 # Explicitly add '--enable-test-java-agent-log4j2', it's not part of '-all' in stable 2.12/2.13
360 if verlt "$PACKAGE_VERSION" "2.14"; then
361 CONF_OPTS+=("--enable-test-java-agent-log4j2")
362 fi
0cdaa21c
MJ
363 ;;
364
365relayd-only)
09d45745
MJ
366 echo "Relayd only configuration"
367
368 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")
0cdaa21c
MJ
369 ;;
370
22780fe6
JR
371debug-rcu)
372 echo "Enable RCU sanity checks for debugging"
09d45745
MJ
373
374 export CPPFLAGS="$CPPFLAGS -DDEBUG_RCU"
22780fe6
JR
375 ;;
376
0cdaa21c 377*)
09d45745 378 echo "Standard configuration"
6871000c
MJ
379
380 # Something is broken in docbook-xml on yocto
381 if [[ "$platform" = yocto* ]]; then
382 CONF_OPTS+=("--disable-man-pages")
383 fi
0cdaa21c 384 ;;
b4005bbf
MJ
385esac
386
387# Build type
67122b96
MJ
388# oot : out-of-tree build
389# dist : build via make dist
390# oot-dist: build via make dist out-of-tree
391# * : normal tree build
b4005bbf 392#
09d45745
MJ
393# Make sure to move to the build directory and run configure
394# before continuing.
b4005bbf 395case "$build" in
09d45745
MJ
396oot)
397 echo "Out of tree build"
398
399 # Create and enter a temporary build directory
400 builddir=$(mktemp -d)
401 cd "$builddir"
402
51c9c62d 403 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
09d45745
MJ
404 ;;
405
406dist)
407 echo "Distribution in-tree build"
408
409 # Run configure and generate the tar file
410 # in the source directory
51c9c62d 411 ./configure "${DIST_CONF_OPTS[@]}" || failed_configure
09d45745
MJ
412 $MAKE dist
413
414 # Create and enter a temporary build directory
415 builddir=$(mktemp -d)
416 cd "$builddir"
417
418 # Extract the distribution tar in the build directory,
419 # ignore the first directory level
420 $TAR xvf "$SRCDIR"/*.tar.* --strip 1
421
422 # Build in extracted source tree
51c9c62d 423 ./configure "${CONF_OPTS[@]}" || failed_configure
09d45745
MJ
424 ;;
425
426oot-dist)
427 echo "Distribution out of tree build"
428
429 # Create and enter a temporary build directory
430 builddir=$(mktemp -d)
431 cd "$builddir"
432
433 # Run configure out of tree and generate the tar file
51c9c62d 434 "$SRCDIR/configure" "${DIST_CONF_OPTS[@]}" || failed_configure
09d45745
MJ
435 $MAKE dist
436
437 dist_srcdir="$(mktemp -d)"
438 cd "$dist_srcdir"
439
440 # Extract the distribution tar in the new source directory,
441 # ignore the first directory level
442 $TAR xvf "$builddir"/*.tar.* --strip 1
443
444 # Create and enter a second temporary build directory
445 builddir="$(mktemp -d)"
446 cd "$builddir"
447
448 # Run configure from the extracted distribution tar,
449 # out of the source tree
51c9c62d 450 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
09d45745
MJ
451 ;;
452
453*)
454 echo "Standard in-tree build"
51c9c62d 455 ./configure "${CONF_OPTS[@]}" || failed_configure
09d45745 456 ;;
b4005bbf
MJ
457esac
458
09d45745
MJ
459# We are now inside a configured build directory
460
0cdaa21c 461# BUILD!
212d2afd 462$MAKE -j "$($NPROC)" V=1
b4005bbf 463
09d45745
MJ
464# Install in the workspace
465$MAKE install DESTDIR="$WORKSPACE"
7671741c 466
09d45745
MJ
467# Run tests for all configs except 'no-ust'
468failed_tests=0
aff4e3d1 469if [ "$LTTNG_TOOLS_RUN_TESTS" = "yes" ] && [ "$conf" != "no-ust" ]; then
0cdaa21c
MJ
470 # Allow core dumps
471 ulimit -c unlimited
472
a4e98cc0
JR
473 # Force the lttng-sessiond path to /bin/true to prevent the spawing of a
474 # lttng-sessiond --daemonize on "lttng create"
475 export LTTNG_SESSIOND_PATH="/bin/true"
476
09d45745
MJ
477 # Run 'unit_tests', 2.8 and up has a new test suite
478 if vergte "$PACKAGE_VERSION" "2.8"; then
65444f1c
MJ
479 # It is implied that tests depending on LTTNG_ENABLE_DESTRUCTIVE_TESTS
480 # only run for the root user. Note that here `destructive` means that
481 # operations are performed at the host level (add user etc.) that
482 # effectively modify the host. Running those tests are acceptable on our
483 # CI and root jobs since we always run root tests against a `snapshot`
484 # of the host.
485 if [ "$(id -u)" == "0" ]; then
486 # Allow the traversal of all directories leading to the
487 # DEPS_LIBS directory to enable test app run by temp users to
488 # access lttng-ust.
489 set_execute_traversal_bit "$DEPS_LIB"
490 # Allow `all` to interact with all deps libs.
491 chmod a+rwx -R "$DEPS_LIB"
492
493 export LTTNG_ENABLE_DESTRUCTIVE_TESTS="will-break-my-system"
494
495 # Some destructive tests play with the system clock, disable timesyncd
496 systemctl stop systemd-timesyncd.service || true
497 fi
498
09d45745
MJ
499 make --keep-going check || failed_tests=1
500 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$TAPDIR"
0cdaa21c 501 else
09d45745
MJ
502 cd tests
503 mkdir -p "$TAPDIR/unit"
504 mkdir -p "$TAPDIR/fast_regression"
505 mkdir -p "$TAPDIR/with_bindings_regression"
506 prove --merge -v --exec '' - < unit_tests --archive "$TAPDIR/unit/" || failed_tests=1
507 prove --merge -v --exec '' - < fast_regression --archive "$TAPDIR/fast_regression/" || failed_tests=1
508 prove --merge -v --exec '' - < with_bindings_regression --archive "$TAPDIR/with_bindings_regression/" || failed_tests=1
65444f1c 509 cd ..
09d45745
MJ
510 fi
511
aff4e3d1 512 if [ "$LTTNG_TOOLS_RUN_TESTS_LONG_REGRESSION" = "yes" ]; then
09d45745
MJ
513 cd tests
514 mkdir -p "$TAPDIR/long_regression"
515 prove --merge -v --exec '' - < long_regression --archive "$TAPDIR/long_regression/" || failed_tests=1
65444f1c 516 cd ..
0cdaa21c
MJ
517 fi
518
0cdaa21c 519 # TAP plugin is having a hard time with .yml files.
212d2afd 520 find "$TAPDIR" -name "meta.yml" -exec rm -f {} \;
09d45745
MJ
521else
522 # The TAP plugin will fail the job if no test logs are present
523 mkdir -p "$TAPDIR/no-tests"
524 echo "1..1" > "$TAPDIR/no-tests/tests.log"
525 echo "ok 1 - Test suite disabled" >> "$TAPDIR/no-tests/tests.log"
b4005bbf
MJ
526fi
527
09d45745 528# Clean the build directory
0cdaa21c 529$MAKE clean
b4005bbf 530
0a059dd4 531# Cleanup rpath in executables
09d45745 532find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
0cdaa21c 533
0a059dd4 534# Some configs don't build liblttng-ctl
4afa623f 535if [ -d "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" ]; then
0a059dd4 536 # Cleanup rpath in shared libraries
4afa623f 537 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath --delete {} \;
0a059dd4 538 # Remove libtool .la files
4afa623f 539 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -exec rm -f {} \;
0a059dd4 540fi
b4005bbf 541
09d45745
MJ
542# Exit with failure if any of the tests failed
543exit $failed_tests
95654431
MJ
544
545# EOF
This page took 0.056327 seconds and 4 git commands to generate.