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