Commit | Line | Data |
---|---|---|
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 |
20 | set -exu |
21 | ||
0cdaa21c | 22 | # Version compare functions |
b6e62a6a MJ |
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 | ||
0cdaa21c | 50 | verlte() { |
b6e62a6a MJ |
51 | vercomp "$1" "$2"; local res="$?" |
52 | [ "$res" -eq "0" ] || [ "$res" -eq "2" ] | |
0cdaa21c MJ |
53 | } |
54 | ||
55 | verlt() { | |
b6e62a6a MJ |
56 | vercomp "$1" "$2"; local res="$?" |
57 | [ "$res" -eq "2" ] | |
0cdaa21c MJ |
58 | } |
59 | ||
60 | vergte() { | |
b6e62a6a MJ |
61 | vercomp "$1" "$2"; local res="$?" |
62 | [ "$res" -eq "0" ] || [ "$res" -eq "1" ] | |
0cdaa21c MJ |
63 | } |
64 | ||
65 | vergt() { | |
b6e62a6a MJ |
66 | vercomp "$1" "$2"; local res="$?" |
67 | [ "$res" -eq "1" ] | |
68 | } | |
69 | ||
70 | verne() { | |
71 | vercomp "$1" "$2"; local res="$?" | |
72 | [ "$res" -ne "0" ] | |
0cdaa21c MJ |
73 | } |
74 | ||
51c9c62d MJ |
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 | ||
09d45745 MJ |
85 | # Required variables |
86 | WORKSPACE=${WORKSPACE:-} | |
87 | ||
212d2afd MJ |
88 | arch=${arch:-} |
89 | conf=${conf:-} | |
90 | build=${build:-} | |
09d45745 | 91 | cc=${cc:-} |
9699c0e7 | 92 | test_type=${test_type:-} |
b4005bbf | 93 | |
09d45745 MJ |
94 | DEPS_INC="$WORKSPACE/deps/build/include" |
95 | DEPS_LIB="$WORKSPACE/deps/build/lib" | |
b8bdba8f | 96 | DEPS_PKGCONFIG="$DEPS_LIB/pkgconfig" |
09d45745 MJ |
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:-}" | |
b8bdba8f | 102 | export PKG_CONFIG_PATH="$DEPS_PKGCONFIG" |
09d45745 MJ |
103 | export CPPFLAGS="-I$DEPS_INC" |
104 | export LDFLAGS="-L$DEPS_LIB" | |
105 | ||
212d2afd | 106 | SRCDIR="$WORKSPACE/src/lttng-tools" |
212d2afd | 107 | TAPDIR="$WORKSPACE/tap" |
09d45745 | 108 | PREFIX="/build" |
212d2afd MJ |
109 | |
110 | ||
09d45745 MJ |
111 | # Create tmp directory |
112 | TMPDIR="$WORKSPACE/tmp" | |
113 | mkdir -p "$TMPDIR" | |
212d2afd | 114 | |
09d45745 MJ |
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" | |
b4005bbf | 121 | |
481eadc8 JR |
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 | ||
09d45745 | 135 | export CFLAGS="-g -O2" |
b4005bbf | 136 | |
09d45745 MJ |
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 | |
b4005bbf | 193 | |
09d45745 MJ |
194 | if [ "x${CC:-}" != "x" ]; then |
195 | echo "Selected compiler:" | |
196 | "$CC" -v | |
197 | fi | |
b4005bbf | 198 | |
0cdaa21c MJ |
199 | # Set platform variables |
200 | case "$arch" in | |
995ac8f2 | 201 | sol10-i386) |
09d45745 MJ |
202 | export MAKE=gmake |
203 | export TAR=gtar | |
204 | export NPROC=gnproc | |
ad11244c | 205 | export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH" |
09d45745 MJ |
206 | export CPPFLAGS="-I/opt/csw/include -D_XOPEN_SOURCE=500 $CPPFLAGS" |
207 | export LDFLAGS="-L/opt/csw/lib -R/opt/csw/lib $LDFLAGS" | |
f2cd0939 | 208 | export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/opt/csw/lib/pkgconfig" |
09d45745 MJ |
209 | export PYTHON="python3" |
210 | export PYTHON_CONFIG="python3-config" | |
0cdaa21c | 211 | |
0cdaa21c | 212 | RUN_TESTS="no" |
09d45745 | 213 | ;; |
0cdaa21c | 214 | |
09d45745 MJ |
215 | sol11-i386) |
216 | export MAKE=gmake | |
217 | export TAR=gtar | |
218 | export NPROC=nproc | |
f2cd0939 MJ |
219 | export PATH="/opt/csw/bin:$PATH:/usr/perl5/bin" |
220 | export CPPFLAGS="-D_XOPEN_SOURCE=500 $CPPFLAGS" | |
09d45745 MJ |
221 | export PYTHON="python3" |
222 | export PYTHON_CONFIG="python3-config" | |
f2cd0939 | 223 | export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/lib/pkgconfig" |
09d45745 MJ |
224 | |
225 | RUN_TESTS="no" | |
0cdaa21c MJ |
226 | ;; |
227 | ||
b6e62a6a | 228 | macosx) |
09d45745 MJ |
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" | |
b6e62a6a | 237 | |
09d45745 | 238 | RUN_TESTS="no" |
b6e62a6a MJ |
239 | ;; |
240 | ||
61afb3c3 | 241 | cygwin|cygwin64|msys32|msys64) |
09d45745 MJ |
242 | export MAKE=make |
243 | export TAR=tar | |
244 | export NPROC=nproc | |
245 | ||
61afb3c3 MJ |
246 | RUN_TESTS="no" |
247 | ;; | |
248 | ||
0cdaa21c | 249 | *) |
09d45745 MJ |
250 | export MAKE=make |
251 | export TAR=tar | |
252 | export NPROC=nproc | |
253 | ||
0cdaa21c MJ |
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 | ||
09d45745 MJ |
262 | DEPS_PYTHON2="$WORKSPACE/deps/build/lib/python$P2_VERSION/site-packages" |
263 | DEPS_PYTHON3="$WORKSPACE/deps/build/lib/python$P3_VERSION/site-packages" | |
0cdaa21c MJ |
264 | ;; |
265 | esac | |
266 | ||
9699c0e7 | 267 | case "$test_type" in |
9699c0e7 | 268 | full) |
09d45745 MJ |
269 | RUN_TESTS_LONG_REGRESSION="yes" |
270 | ;; | |
9699c0e7 | 271 | *) |
09d45745 MJ |
272 | RUN_TESTS_LONG_REGRESSION="no" |
273 | ;; | |
9699c0e7 | 274 | esac |
0cdaa21c | 275 | |
7361d941 MJ |
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 | ||
51c9c62d MJ |
284 | # Print build env details |
285 | print_os || true | |
286 | print_tooling || true | |
287 | ||
212d2afd MJ |
288 | # Enter the source directory |
289 | cd "$SRCDIR" | |
290 | ||
291 | # Run bootstrap in the source directory prior to configure | |
0cdaa21c MJ |
292 | ./bootstrap |
293 | ||
294 | # Get source version from configure script | |
212d2afd | 295 | eval "$(grep '^PACKAGE_VERSION=' ./configure)" |
09d45745 | 296 | PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/} |
0cdaa21c | 297 | |
b4005bbf | 298 | |
0cdaa21c MJ |
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 | |
b4005bbf | 305 | |
6c3ec80e | 306 | # Most build configs require the python bindings |
09d45745 | 307 | CONF_OPTS=("--prefix=$PREFIX" "--enable-python-bindings") |
6c3ec80e | 308 | |
edb933dd MJ |
309 | DIST_CONF_OPTS=() |
310 | ||
09d45745 MJ |
311 | # Set configure options and environment variables for each build |
312 | # configuration. | |
b4005bbf | 313 | case "$conf" in |
0cdaa21c | 314 | static) |
09d45745 MJ |
315 | echo "Static lib only configuration" |
316 | ||
317 | CONF_OPTS+=("--enable-static" "--disable-shared") | |
0cdaa21c MJ |
318 | ;; |
319 | ||
0cdaa21c MJ |
320 | no-ust) |
321 | echo "Build without UST support" | |
09d45745 | 322 | CONF_OPTS+=("$NO_UST") |
edb933dd | 323 | DIST_CONF_OPTS+=("$NO_UST") |
0cdaa21c MJ |
324 | ;; |
325 | ||
67122b96 | 326 | agents) |
09d45745 MJ |
327 | echo "Java and Python agents configuration" |
328 | ||
0cdaa21c | 329 | export JAVA_HOME="/usr/lib/jvm/default-java" |
09d45745 MJ |
330 | export CLASSPATH="$DEPS_JAVA/*:/usr/share/java/*" |
331 | export PYTHONPATH="$DEPS_PYTHON2:$DEPS_PYTHON3" | |
0cdaa21c | 332 | |
09d45745 | 333 | CONF_OPTS+=("--enable-test-java-agent-all" "--enable-test-python-agent-all") |
0cdaa21c MJ |
334 | ;; |
335 | ||
336 | relayd-only) | |
09d45745 MJ |
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") | |
0cdaa21c MJ |
340 | ;; |
341 | ||
22780fe6 JR |
342 | debug-rcu) |
343 | echo "Enable RCU sanity checks for debugging" | |
09d45745 MJ |
344 | |
345 | export CPPFLAGS="$CPPFLAGS -DDEBUG_RCU" | |
22780fe6 JR |
346 | ;; |
347 | ||
0cdaa21c | 348 | *) |
09d45745 | 349 | echo "Standard configuration" |
0cdaa21c | 350 | ;; |
b4005bbf MJ |
351 | esac |
352 | ||
353 | # Build type | |
67122b96 MJ |
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 | |
b4005bbf | 358 | # |
09d45745 MJ |
359 | # Make sure to move to the build directory and run configure |
360 | # before continuing. | |
b4005bbf | 361 | case "$build" in |
09d45745 MJ |
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 | ||
51c9c62d | 369 | "$SRCDIR/configure" "${CONF_OPTS[@]}" || failed_configure |
09d45745 MJ |
370 | ;; |
371 | ||
372 | dist) | |
373 | echo "Distribution in-tree build" | |
374 | ||
375 | # Run configure and generate the tar file | |
376 | # in the source directory | |
51c9c62d | 377 | ./configure "${DIST_CONF_OPTS[@]}" || failed_configure |
09d45745 MJ |
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 | |
51c9c62d | 389 | ./configure "${CONF_OPTS[@]}" || failed_configure |
09d45745 MJ |
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 | |
51c9c62d | 400 | "$SRCDIR/configure" "${DIST_CONF_OPTS[@]}" || failed_configure |
09d45745 MJ |
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 | |
51c9c62d | 416 | "$dist_srcdir/configure" "${CONF_OPTS[@]}" || failed_configure |
09d45745 MJ |
417 | ;; |
418 | ||
419 | *) | |
420 | echo "Standard in-tree build" | |
51c9c62d | 421 | ./configure "${CONF_OPTS[@]}" || failed_configure |
09d45745 | 422 | ;; |
b4005bbf MJ |
423 | esac |
424 | ||
09d45745 MJ |
425 | # We are now inside a configured build directory |
426 | ||
0cdaa21c | 427 | # BUILD! |
212d2afd | 428 | $MAKE -j "$($NPROC)" V=1 |
b4005bbf | 429 | |
09d45745 MJ |
430 | # Install in the workspace |
431 | $MAKE install DESTDIR="$WORKSPACE" | |
7671741c | 432 | |
09d45745 MJ |
433 | # Run tests for all configs except 'no-ust' |
434 | failed_tests=0 | |
435 | if [ "$RUN_TESTS" = "yes" ] && [ "$conf" != "no-ust" ]; then | |
0cdaa21c MJ |
436 | # Allow core dumps |
437 | ulimit -c unlimited | |
438 | ||
a4e98cc0 JR |
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 | ||
09d45745 MJ |
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" | |
0cdaa21c | 447 | else |
09d45745 MJ |
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 .. | |
0cdaa21c MJ |
463 | fi |
464 | ||
0cdaa21c | 465 | # TAP plugin is having a hard time with .yml files. |
212d2afd | 466 | find "$TAPDIR" -name "meta.yml" -exec rm -f {} \; |
09d45745 MJ |
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" | |
b4005bbf MJ |
472 | fi |
473 | ||
09d45745 | 474 | # Clean the build directory |
0cdaa21c | 475 | $MAKE clean |
b4005bbf | 476 | |
0cdaa21c | 477 | # Cleanup rpath in executables and shared libraries |
09d45745 MJ |
478 | find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \; |
479 | find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \; | |
0cdaa21c MJ |
480 | |
481 | # Remove libtool .la files | |
09d45745 | 482 | find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \; |
b4005bbf | 483 | |
09d45745 MJ |
484 | # Exit with failure if any of the tests failed |
485 | exit $failed_tests | |
95654431 MJ |
486 | |
487 | # EOF |