jjb: extend 'libdir = lib64' to yocto
[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 # Ignore the shellcheck warning, we want splitting to happen based on IFS.
30 # shellcheck disable=SC2206
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
52 verlte() {
53 vercomp "$1" "$2"; local res="$?"
54 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
55 }
56
57 verlt() {
58 vercomp "$1" "$2"; local res="$?"
59 [ "$res" -eq "2" ]
60 }
61
62 vergte() {
63 vercomp "$1" "$2"; local res="$?"
64 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
65 }
66
67 vergt() {
68 vercomp "$1" "$2"; local res="$?"
69 [ "$res" -eq "1" ]
70 }
71
72 verne() {
73 vercomp "$1" "$2"; local res="$?"
74 [ "$res" -ne "0" ]
75 }
76
77 failed_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
87 set_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
105 # Required variables
106 WORKSPACE=${WORKSPACE:-}
107
108 platform=${platform:-}
109 conf=${conf:-}
110 build=${build:-}
111 cc=${cc:-}
112 test_type=${test_type:-}
113
114 SRCDIR="$WORKSPACE/src/lttng-tools"
115 TAPDIR="$WORKSPACE/tap"
116 PREFIX="/build"
117 LIBDIR="lib"
118
119 # RHEL and SLES both use lib64 but don't bother shipping a default autoconf
120 # site config that matches this.
121 if [[ ( -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
128 fi
129
130 DEPS_INC="$WORKSPACE/deps/build/include"
131 DEPS_LIB="$WORKSPACE/deps/build/$LIBDIR_ARCH"
132 DEPS_PKGCONFIG="$DEPS_LIB/pkgconfig"
133 DEPS_BIN="$WORKSPACE/deps/build/bin"
134 DEPS_JAVA="$WORKSPACE/deps/build/share/java"
135
136 export PATH="$DEPS_BIN:$PATH"
137 export LD_LIBRARY_PATH="$DEPS_LIB:${LD_LIBRARY_PATH:-}"
138 export PKG_CONFIG_PATH="$DEPS_PKGCONFIG"
139 export CPPFLAGS="-I$DEPS_INC"
140 export LDFLAGS="-L$DEPS_LIB"
141
142
143 # Create tmp directory
144 TMPDIR="$WORKSPACE/tmp"
145 mkdir -p "$TMPDIR"
146
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.
150 tmpdir="$(mktemp)"
151 ln -sf "$TMPDIR" "$tmpdir"
152 export TMPDIR="$tmpdir"
153
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
158 if [ -x "$DEPS_BIN/babeltrace2" ]; then
159 ln -s "$DEPS_BIN/babeltrace2" "$DEPS_BIN/babeltrace"
160 fi
161
162 # When using babeltrace2 make sure that it finds its plugins and
163 # plugin-providers.
164 export BABELTRACE_PLUGIN_PATH="$DEPS_LIB/babeltrace2/plugins/"
165 export LIBBABELTRACE2_PLUGIN_PROVIDER_DIR="$DEPS_LIB/babeltrace2/plugin-providers/"
166
167 export CFLAGS="-g -O2"
168 export CXXFLAGS="-g -O2"
169
170 # Set compiler variables
171 case "$cc" in
172 gcc)
173 export CC=gcc
174 export CXX=g++
175 ;;
176 gcc-4.8)
177 export CC=gcc-4.8
178 export CXX=g++-4.8
179 ;;
180 gcc-5)
181 export CC=gcc-5
182 export CXX=g++-5
183 ;;
184 gcc-6)
185 export CC=gcc-6
186 export CXX=g++-6
187 ;;
188 gcc-7)
189 export CC=gcc-7
190 export CXX=g++-7
191 ;;
192 gcc-8)
193 export CC=gcc-8
194 export CXX=g++-8
195 ;;
196 clang)
197 export CC=clang
198 export CXX=clang++
199 ;;
200 clang-3.9)
201 export CC=clang-3.9
202 export CXX=clang++-3.9
203 ;;
204 clang-4.0)
205 export CC=clang-4.0
206 export CXX=clang++-4.0
207 ;;
208 clang-5.0)
209 export CC=clang-5.0
210 export CXX=clang++-5.0
211 ;;
212 clang-6.0)
213 export CC=clang-6.0
214 export CXX=clang++-6.0
215 ;;
216 clang-7)
217 export CC=clang-7
218 export CXX=clang++-7
219 ;;
220 *)
221 if [ "x$cc" != "x" ]; then
222 export CC="$cc"
223 fi
224 ;;
225 esac
226
227 if [ "x${CC:-}" != "x" ]; then
228 echo "Selected compiler:"
229 "$CC" -v
230 fi
231
232 # Set platform variables
233 case "$platform" in
234 macos*)
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"
241 export PYTHON="python3"
242 export PYTHON_CONFIG="python3-config"
243
244 LTTNG_TOOLS_RUN_TESTS="no"
245 ;;
246
247 cygwin|cygwin64|msys32|msys64)
248 export MAKE=make
249 export TAR=tar
250 export NPROC=nproc
251
252 LTTNG_TOOLS_RUN_TESTS="no"
253 ;;
254
255 *)
256 export MAKE=make
257 export TAR=tar
258 export NPROC=nproc
259
260 LTTNG_TOOLS_RUN_TESTS="yes"
261
262 PYTHON2=python2
263 PYTHON3=python3
264
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]))')
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
271 fi
272
273 P3_VERSION=$($PYTHON3 -c 'import sys;v = sys.version.split()[0].split("."); print("{}.{}".format(v[0], v[1]))')
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
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"
282 ;;
283 esac
284
285 # The missing-field-initializers warning code is very dumb in GCC 4.8 on
286 # SLES12 / EL7, disable it even if it's available.
287 if [[ $platform = sles12sp5* ]] || [[ $platform = el7* ]]; then
288 CFLAGS="$CFLAGS -Wno-missing-field-initializers"
289 CXXFLAGS="$CXXFLAGS -Wno-missing-field-initializers"
290 fi
291
292 case "$test_type" in
293 full)
294 LTTNG_TOOLS_RUN_TESTS_LONG_REGRESSION="yes"
295 ;;
296 *)
297 LTTNG_TOOLS_RUN_TESTS_LONG_REGRESSION="no"
298 ;;
299 esac
300
301 # If we have modules, build them
302 if [ -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
307 fi
308
309 # Print build env details
310 print_os || true
311 print_tooling || true
312
313 # Enter the source directory
314 cd "$SRCDIR"
315
316 # Run bootstrap in the source directory prior to configure
317 ./bootstrap
318
319 # Get source version from configure script
320 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
321 PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
322
323
324 # The switch to build without UST changed in 2.8
325 if vergte "$PACKAGE_VERSION" "2.8"; then
326 NO_UST="--without-lttng-ust"
327 else
328 NO_UST="--disable-lttng-ust"
329 fi
330
331 # Most build configs require the python bindings
332 CONF_OPTS=("--prefix=$PREFIX" "--libdir=$PREFIX/$LIBDIR_ARCH" "--enable-python-bindings")
333
334 DIST_CONF_OPTS=()
335
336 # Set configure options and environment variables for each build
337 # configuration.
338 case "$conf" in
339 static)
340 echo "Static lib only configuration"
341
342 CONF_OPTS+=("--enable-static" "--disable-shared")
343 ;;
344
345 no-ust)
346 echo "Build without UST support"
347 CONF_OPTS+=("$NO_UST")
348 DIST_CONF_OPTS+=("$NO_UST")
349 ;;
350
351 agents)
352 echo "Java and Python agents configuration"
353
354 export JAVA_HOME="/usr/lib/jvm/default-java"
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"
356
357 CONF_OPTS+=("--enable-test-java-agent-all" "--enable-test-python-agent-all")
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
363 ;;
364
365 relayd-only)
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")
369 ;;
370
371 debug-rcu)
372 echo "Enable RCU sanity checks for debugging"
373
374 export CPPFLAGS="$CPPFLAGS -DDEBUG_RCU"
375 ;;
376
377 *)
378 echo "Standard configuration"
379
380 # Something is broken in docbook-xml on yocto
381 if [[ "$platform" = yocto* ]]; then
382 CONF_OPTS+=("--disable-man-pages")
383 fi
384 ;;
385 esac
386
387 # Build type
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
392 #
393 # Make sure to move to the build directory and run configure
394 # before continuing.
395 case "$build" in
396 oot)
397 echo "Out of tree build"
398
399 # Create and enter a temporary build directory
400 builddir=$(mktemp -d)
401 cd "$builddir"
402
403 "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure
404 ;;
405
406 dist)
407 echo "Distribution in-tree build"
408
409 # Run configure and generate the tar file
410 # in the source directory
411 ./configure "${DIST_CONF_OPTS[@]}" || failed_configure
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
423 ./configure "${CONF_OPTS[@]}" || failed_configure
424 ;;
425
426 oot-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
434 "$SRCDIR/configure" "${DIST_CONF_OPTS[@]}" || failed_configure
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
450 "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure
451 ;;
452
453 *)
454 echo "Standard in-tree build"
455 ./configure "${CONF_OPTS[@]}" || failed_configure
456 ;;
457 esac
458
459 # We are now inside a configured build directory
460
461 # BUILD!
462 $MAKE -j "$($NPROC)" V=1
463
464 # Install in the workspace
465 $MAKE install DESTDIR="$WORKSPACE"
466
467 # Run tests for all configs except 'no-ust'
468 failed_tests=0
469 if [ "$LTTNG_TOOLS_RUN_TESTS" = "yes" ] && [ "$conf" != "no-ust" ]; then
470 # Allow core dumps
471 ulimit -c unlimited
472
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
477 # Run 'unit_tests', 2.8 and up has a new test suite
478 if vergte "$PACKAGE_VERSION" "2.8"; then
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
499 make --keep-going check || failed_tests=1
500 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$TAPDIR"
501 else
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
509 cd ..
510 fi
511
512 if [ "$LTTNG_TOOLS_RUN_TESTS_LONG_REGRESSION" = "yes" ]; then
513 cd tests
514 mkdir -p "$TAPDIR/long_regression"
515 prove --merge -v --exec '' - < long_regression --archive "$TAPDIR/long_regression/" || failed_tests=1
516 cd ..
517 fi
518
519 # TAP plugin is having a hard time with .yml files.
520 find "$TAPDIR" -name "meta.yml" -exec rm -f {} \;
521 else
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"
526 fi
527
528 # Clean the build directory
529 $MAKE clean
530
531 # Cleanup rpath in executables
532 find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
533
534 # Some configs don't build liblttng-ctl
535 if [ -d "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" ]; then
536 # Cleanup rpath in shared libraries
537 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.so" -exec chrpath --delete {} \;
538 # Remove libtool .la files
539 find "$WORKSPACE/$PREFIX/$LIBDIR_ARCH" -name "*.la" -exec rm -f {} \;
540 fi
541
542 # Exit with failure if any of the tests failed
543 exit $failed_tests
544
545 # EOF
This page took 0.041543 seconds and 5 git commands to generate.