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