Commit | Line | Data |
---|---|---|
3c85b52d | 1 | #!/bin/bash -exu |
09d45745 | 2 | # shellcheck disable=SC2103 |
b4005bbf | 3 | # |
09d45745 MJ |
4 | # Copyright (C) 2016 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com> |
5 | # 2016-2019 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 | ||
0cdaa21c | 20 | # Version compare functions |
b6e62a6a MJ |
21 | vercomp () { |
22 | set +u | |
23 | if [[ "$1" == "$2" ]]; then | |
24 | return 0 | |
25 | fi | |
26 | local IFS=. | |
27 | local i ver1=($1) ver2=($2) | |
28 | # fill empty fields in ver1 with zeros | |
29 | for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do | |
30 | ver1[i]=0 | |
31 | done | |
32 | for ((i=0; i<${#ver1[@]}; i++)); do | |
33 | if [[ -z ${ver2[i]} ]]; then | |
34 | # fill empty fields in ver2 with zeros | |
35 | ver2[i]=0 | |
36 | fi | |
37 | if ((10#${ver1[i]} > 10#${ver2[i]})); then | |
38 | return 1 | |
39 | fi | |
40 | if ((10#${ver1[i]} < 10#${ver2[i]})); then | |
41 | return 2 | |
42 | fi | |
43 | done | |
44 | set -u | |
45 | return 0 | |
46 | } | |
47 | ||
0cdaa21c | 48 | verlte() { |
b6e62a6a MJ |
49 | vercomp "$1" "$2"; local res="$?" |
50 | [ "$res" -eq "0" ] || [ "$res" -eq "2" ] | |
0cdaa21c MJ |
51 | } |
52 | ||
53 | verlt() { | |
b6e62a6a MJ |
54 | vercomp "$1" "$2"; local res="$?" |
55 | [ "$res" -eq "2" ] | |
0cdaa21c MJ |
56 | } |
57 | ||
58 | vergte() { | |
b6e62a6a MJ |
59 | vercomp "$1" "$2"; local res="$?" |
60 | [ "$res" -eq "0" ] || [ "$res" -eq "1" ] | |
0cdaa21c MJ |
61 | } |
62 | ||
63 | vergt() { | |
b6e62a6a MJ |
64 | vercomp "$1" "$2"; local res="$?" |
65 | [ "$res" -eq "1" ] | |
66 | } | |
67 | ||
68 | verne() { | |
69 | vercomp "$1" "$2"; local res="$?" | |
70 | [ "$res" -ne "0" ] | |
0cdaa21c MJ |
71 | } |
72 | ||
09d45745 MJ |
73 | # Required variables |
74 | WORKSPACE=${WORKSPACE:-} | |
75 | ||
212d2afd MJ |
76 | arch=${arch:-} |
77 | conf=${conf:-} | |
78 | build=${build:-} | |
09d45745 | 79 | cc=${cc:-} |
9699c0e7 | 80 | test_type=${test_type:-} |
b4005bbf | 81 | |
09d45745 MJ |
82 | DEPS_INC="$WORKSPACE/deps/build/include" |
83 | DEPS_LIB="$WORKSPACE/deps/build/lib" | |
b8bdba8f | 84 | DEPS_PKGCONFIG="$DEPS_LIB/pkgconfig" |
09d45745 MJ |
85 | DEPS_BIN="$WORKSPACE/deps/build/bin" |
86 | DEPS_JAVA="$WORKSPACE/deps/build/share/java" | |
87 | ||
88 | export PATH="$DEPS_BIN:$PATH" | |
89 | export LD_LIBRARY_PATH="$DEPS_LIB:${LD_LIBRARY_PATH:-}" | |
b8bdba8f | 90 | export PKG_CONFIG_PATH="$DEPS_PKGCONFIG" |
09d45745 MJ |
91 | export CPPFLAGS="-I$DEPS_INC" |
92 | export LDFLAGS="-L$DEPS_LIB" | |
93 | ||
212d2afd | 94 | SRCDIR="$WORKSPACE/src/lttng-tools" |
212d2afd | 95 | TAPDIR="$WORKSPACE/tap" |
09d45745 | 96 | PREFIX="/build" |
212d2afd MJ |
97 | |
98 | ||
09d45745 MJ |
99 | # Create tmp directory |
100 | TMPDIR="$WORKSPACE/tmp" | |
101 | mkdir -p "$TMPDIR" | |
212d2afd | 102 | |
09d45745 MJ |
103 | # Use a symlink in /tmp to point to the the tmp directory |
104 | # inside the workspace, this is to work around the path length | |
105 | # limit of unix sockets which are created by the test suite. | |
106 | tmpdir="$(mktemp)" | |
107 | ln -sf "$TMPDIR" "$tmpdir" | |
108 | export TMPDIR="$tmpdir" | |
b4005bbf | 109 | |
481eadc8 JR |
110 | # Create a symlink to "babeltrace" when the "babeltrace2" executable is found. |
111 | # This is a temporary workaround until lttng-tools either allows the override of | |
112 | # the trace reader in its test suite or that we move to only supporting | |
113 | # babeltrace2 | |
114 | if [ -x "$DEPS_BIN/babeltrace2" ]; then | |
115 | ln -s "$DEPS_BIN/babeltrace2" "$DEPS_BIN/babeltrace" | |
116 | fi | |
117 | ||
118 | # When using babeltrace2 make sure that it finds its plugins and | |
119 | # plugin-providers. | |
120 | export BABELTRACE_PLUGIN_PATH="$DEPS_LIB/babeltrace2/plugins/" | |
121 | export LIBBABELTRACE2_PLUGIN_PROVIDER_DIR="$DEPS_LIB/babeltrace2/plugin-providers/" | |
122 | ||
09d45745 | 123 | export CFLAGS="-g -O2" |
b4005bbf | 124 | |
09d45745 MJ |
125 | # Set compiler variables |
126 | case "$cc" in | |
127 | gcc) | |
128 | export CC=gcc | |
129 | export CXX=g++ | |
130 | ;; | |
131 | gcc-4.8) | |
132 | export CC=gcc-4.8 | |
133 | export CXX=g++-4.8 | |
134 | ;; | |
135 | gcc-5) | |
136 | export CC=gcc-5 | |
137 | export CXX=g++-5 | |
138 | ;; | |
139 | gcc-6) | |
140 | export CC=gcc-6 | |
141 | export CXX=g++-6 | |
142 | ;; | |
143 | gcc-7) | |
144 | export CC=gcc-7 | |
145 | export CXX=g++-7 | |
146 | ;; | |
147 | gcc-8) | |
148 | export CC=gcc-8 | |
149 | export CXX=g++-8 | |
150 | ;; | |
151 | clang) | |
152 | export CC=clang | |
153 | export CXX=clang++ | |
154 | ;; | |
155 | clang-3.9) | |
156 | export CC=clang-3.9 | |
157 | export CXX=clang++-3.9 | |
158 | ;; | |
159 | clang-4.0) | |
160 | export CC=clang-4.0 | |
161 | export CXX=clang++-4.0 | |
162 | ;; | |
163 | clang-5.0) | |
164 | export CC=clang-5.0 | |
165 | export CXX=clang++-5.0 | |
166 | ;; | |
167 | clang-6.0) | |
168 | export CC=clang-6.0 | |
169 | export CXX=clang++-6.0 | |
170 | ;; | |
171 | clang-7) | |
172 | export CC=clang-7 | |
173 | export CXX=clang++-7 | |
174 | ;; | |
175 | *) | |
176 | if [ "x$cc" != "x" ]; then | |
177 | export CC="$cc" | |
178 | fi | |
179 | ;; | |
180 | esac | |
b4005bbf | 181 | |
09d45745 MJ |
182 | if [ "x${CC:-}" != "x" ]; then |
183 | echo "Selected compiler:" | |
184 | "$CC" -v | |
185 | fi | |
b4005bbf | 186 | |
0cdaa21c MJ |
187 | # Set platform variables |
188 | case "$arch" in | |
995ac8f2 | 189 | sol10-i386) |
09d45745 MJ |
190 | export MAKE=gmake |
191 | export TAR=gtar | |
192 | export NPROC=gnproc | |
ad11244c | 193 | export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH" |
09d45745 MJ |
194 | export CPPFLAGS="-I/opt/csw/include -D_XOPEN_SOURCE=500 $CPPFLAGS" |
195 | export LDFLAGS="-L/opt/csw/lib -R/opt/csw/lib $LDFLAGS" | |
f2cd0939 | 196 | export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/opt/csw/lib/pkgconfig" |
09d45745 MJ |
197 | export PYTHON="python3" |
198 | export PYTHON_CONFIG="python3-config" | |
0cdaa21c | 199 | |
0cdaa21c | 200 | RUN_TESTS="no" |
09d45745 | 201 | ;; |
0cdaa21c | 202 | |
09d45745 MJ |
203 | sol11-i386) |
204 | export MAKE=gmake | |
205 | export TAR=gtar | |
206 | export NPROC=nproc | |
f2cd0939 MJ |
207 | export PATH="/opt/csw/bin:$PATH:/usr/perl5/bin" |
208 | export CPPFLAGS="-D_XOPEN_SOURCE=500 $CPPFLAGS" | |
09d45745 MJ |
209 | export PYTHON="python3" |
210 | export PYTHON_CONFIG="python3-config" | |
f2cd0939 | 211 | export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/lib/pkgconfig" |
09d45745 MJ |
212 | |
213 | RUN_TESTS="no" | |
0cdaa21c MJ |
214 | ;; |
215 | ||
b6e62a6a | 216 | macosx) |
09d45745 MJ |
217 | export MAKE=make |
218 | export TAR=tar | |
219 | export NPROC="getconf _NPROCESSORS_ONLN" | |
220 | export PATH="/opt/local/bin:/opt/local/sbin:$PATH" | |
221 | export CPPFLAGS="-I/opt/local/include $CPPFLAGS" | |
222 | export LDFLAGS="-L/opt/local/lib $LDFLAGS" | |
223 | export PYTHON="python3" | |
224 | export PYTHON_CONFIG="python3-config" | |
b6e62a6a | 225 | |
09d45745 | 226 | RUN_TESTS="no" |
b6e62a6a MJ |
227 | ;; |
228 | ||
61afb3c3 | 229 | cygwin|cygwin64|msys32|msys64) |
09d45745 MJ |
230 | export MAKE=make |
231 | export TAR=tar | |
232 | export NPROC=nproc | |
233 | ||
61afb3c3 MJ |
234 | RUN_TESTS="no" |
235 | ;; | |
236 | ||
0cdaa21c | 237 | *) |
09d45745 MJ |
238 | export MAKE=make |
239 | export TAR=tar | |
240 | export NPROC=nproc | |
241 | ||
0cdaa21c MJ |
242 | RUN_TESTS="yes" |
243 | ||
244 | PYTHON2=python2 | |
245 | PYTHON3=python3 | |
246 | ||
247 | P2_VERSION=$($PYTHON2 -c "import sys;print(sys.version[:3])") | |
248 | P3_VERSION=$($PYTHON3 -c "import sys;print(sys.version[:3])") | |
249 | ||
09d45745 MJ |
250 | DEPS_PYTHON2="$WORKSPACE/deps/build/lib/python$P2_VERSION/site-packages" |
251 | DEPS_PYTHON3="$WORKSPACE/deps/build/lib/python$P3_VERSION/site-packages" | |
0cdaa21c MJ |
252 | ;; |
253 | esac | |
254 | ||
9699c0e7 | 255 | case "$test_type" in |
9699c0e7 | 256 | full) |
09d45745 MJ |
257 | RUN_TESTS_LONG_REGRESSION="yes" |
258 | ;; | |
9699c0e7 | 259 | *) |
09d45745 MJ |
260 | RUN_TESTS_LONG_REGRESSION="no" |
261 | ;; | |
9699c0e7 | 262 | esac |
0cdaa21c | 263 | |
212d2afd MJ |
264 | # Enter the source directory |
265 | cd "$SRCDIR" | |
266 | ||
267 | # Run bootstrap in the source directory prior to configure | |
0cdaa21c MJ |
268 | ./bootstrap |
269 | ||
270 | # Get source version from configure script | |
212d2afd | 271 | eval "$(grep '^PACKAGE_VERSION=' ./configure)" |
09d45745 | 272 | PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/} |
0cdaa21c | 273 | |
b4005bbf | 274 | |
0cdaa21c MJ |
275 | # The switch to build without UST changed in 2.8 |
276 | if vergte "$PACKAGE_VERSION" "2.8"; then | |
277 | NO_UST="--without-lttng-ust" | |
278 | else | |
279 | NO_UST="--disable-lttng-ust" | |
280 | fi | |
b4005bbf | 281 | |
6c3ec80e | 282 | # Most build configs require the python bindings |
09d45745 | 283 | CONF_OPTS=("--prefix=$PREFIX" "--enable-python-bindings") |
6c3ec80e | 284 | |
09d45745 MJ |
285 | # Set configure options and environment variables for each build |
286 | # configuration. | |
b4005bbf | 287 | case "$conf" in |
0cdaa21c | 288 | static) |
09d45745 MJ |
289 | echo "Static lib only configuration" |
290 | ||
291 | CONF_OPTS+=("--enable-static" "--disable-shared") | |
0cdaa21c MJ |
292 | ;; |
293 | ||
0cdaa21c MJ |
294 | no-ust) |
295 | echo "Build without UST support" | |
09d45745 | 296 | CONF_OPTS+=("$NO_UST") |
0cdaa21c MJ |
297 | ;; |
298 | ||
67122b96 | 299 | agents) |
09d45745 MJ |
300 | echo "Java and Python agents configuration" |
301 | ||
0cdaa21c | 302 | export JAVA_HOME="/usr/lib/jvm/default-java" |
09d45745 MJ |
303 | export CLASSPATH="$DEPS_JAVA/*:/usr/share/java/*" |
304 | export PYTHONPATH="$DEPS_PYTHON2:$DEPS_PYTHON3" | |
0cdaa21c | 305 | |
09d45745 | 306 | CONF_OPTS+=("--enable-test-java-agent-all" "--enable-test-python-agent-all") |
0cdaa21c MJ |
307 | ;; |
308 | ||
309 | relayd-only) | |
09d45745 MJ |
310 | echo "Relayd only configuration" |
311 | ||
312 | 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 |
313 | ;; |
314 | ||
22780fe6 JR |
315 | debug-rcu) |
316 | echo "Enable RCU sanity checks for debugging" | |
09d45745 MJ |
317 | |
318 | export CPPFLAGS="$CPPFLAGS -DDEBUG_RCU" | |
22780fe6 JR |
319 | ;; |
320 | ||
0cdaa21c | 321 | *) |
09d45745 | 322 | echo "Standard configuration" |
0cdaa21c | 323 | ;; |
b4005bbf MJ |
324 | esac |
325 | ||
326 | # Build type | |
67122b96 MJ |
327 | # oot : out-of-tree build |
328 | # dist : build via make dist | |
329 | # oot-dist: build via make dist out-of-tree | |
330 | # * : normal tree build | |
b4005bbf | 331 | # |
09d45745 MJ |
332 | # Make sure to move to the build directory and run configure |
333 | # before continuing. | |
b4005bbf | 334 | case "$build" in |
09d45745 MJ |
335 | oot) |
336 | echo "Out of tree build" | |
337 | ||
338 | # Create and enter a temporary build directory | |
339 | builddir=$(mktemp -d) | |
340 | cd "$builddir" | |
341 | ||
342 | "$SRCDIR/configure" "${CONF_OPTS[@]}" | |
343 | ;; | |
344 | ||
345 | dist) | |
346 | echo "Distribution in-tree build" | |
347 | ||
348 | # Run configure and generate the tar file | |
349 | # in the source directory | |
350 | ./configure | |
351 | $MAKE dist | |
352 | ||
353 | # Create and enter a temporary build directory | |
354 | builddir=$(mktemp -d) | |
355 | cd "$builddir" | |
356 | ||
357 | # Extract the distribution tar in the build directory, | |
358 | # ignore the first directory level | |
359 | $TAR xvf "$SRCDIR"/*.tar.* --strip 1 | |
360 | ||
361 | # Build in extracted source tree | |
362 | ./configure "${CONF_OPTS[@]}" | |
363 | ;; | |
364 | ||
365 | oot-dist) | |
366 | echo "Distribution out of tree build" | |
367 | ||
368 | # Create and enter a temporary build directory | |
369 | builddir=$(mktemp -d) | |
370 | cd "$builddir" | |
371 | ||
372 | # Run configure out of tree and generate the tar file | |
373 | "$SRCDIR/configure" | |
374 | $MAKE dist | |
375 | ||
376 | dist_srcdir="$(mktemp -d)" | |
377 | cd "$dist_srcdir" | |
378 | ||
379 | # Extract the distribution tar in the new source directory, | |
380 | # ignore the first directory level | |
381 | $TAR xvf "$builddir"/*.tar.* --strip 1 | |
382 | ||
383 | # Create and enter a second temporary build directory | |
384 | builddir="$(mktemp -d)" | |
385 | cd "$builddir" | |
386 | ||
387 | # Run configure from the extracted distribution tar, | |
388 | # out of the source tree | |
389 | "$dist_srcdir/configure" "${CONF_OPTS[@]}" | |
390 | ;; | |
391 | ||
392 | *) | |
393 | echo "Standard in-tree build" | |
394 | ./configure "${CONF_OPTS[@]}" | |
395 | ;; | |
b4005bbf MJ |
396 | esac |
397 | ||
09d45745 MJ |
398 | # We are now inside a configured build directory |
399 | ||
0cdaa21c | 400 | # BUILD! |
212d2afd | 401 | $MAKE -j "$($NPROC)" V=1 |
b4005bbf | 402 | |
09d45745 MJ |
403 | # Install in the workspace |
404 | $MAKE install DESTDIR="$WORKSPACE" | |
7671741c | 405 | |
09d45745 MJ |
406 | # Run tests for all configs except 'no-ust' |
407 | failed_tests=0 | |
408 | if [ "$RUN_TESTS" = "yes" ] && [ "$conf" != "no-ust" ]; then | |
0cdaa21c MJ |
409 | # Allow core dumps |
410 | ulimit -c unlimited | |
411 | ||
a4e98cc0 JR |
412 | # Force the lttng-sessiond path to /bin/true to prevent the spawing of a |
413 | # lttng-sessiond --daemonize on "lttng create" | |
414 | export LTTNG_SESSIOND_PATH="/bin/true" | |
415 | ||
09d45745 MJ |
416 | # Run 'unit_tests', 2.8 and up has a new test suite |
417 | if vergte "$PACKAGE_VERSION" "2.8"; then | |
418 | make --keep-going check || failed_tests=1 | |
419 | rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*' tests/ "$TAPDIR" | |
0cdaa21c | 420 | else |
09d45745 MJ |
421 | cd tests |
422 | mkdir -p "$TAPDIR/unit" | |
423 | mkdir -p "$TAPDIR/fast_regression" | |
424 | mkdir -p "$TAPDIR/with_bindings_regression" | |
425 | prove --merge -v --exec '' - < unit_tests --archive "$TAPDIR/unit/" || failed_tests=1 | |
426 | prove --merge -v --exec '' - < fast_regression --archive "$TAPDIR/fast_regression/" || failed_tests=1 | |
427 | prove --merge -v --exec '' - < with_bindings_regression --archive "$TAPDIR/with_bindings_regression/" || failed_tests=1 | |
428 | cd .. | |
429 | fi | |
430 | ||
431 | if [ "$RUN_TESTS_LONG_REGRESSION" = "yes" ]; then | |
432 | cd tests | |
433 | mkdir -p "$TAPDIR/long_regression" | |
434 | prove --merge -v --exec '' - < long_regression --archive "$TAPDIR/long_regression/" || failed_tests=1 | |
435 | cd .. | |
0cdaa21c MJ |
436 | fi |
437 | ||
0cdaa21c | 438 | # TAP plugin is having a hard time with .yml files. |
212d2afd | 439 | find "$TAPDIR" -name "meta.yml" -exec rm -f {} \; |
09d45745 MJ |
440 | else |
441 | # The TAP plugin will fail the job if no test logs are present | |
442 | mkdir -p "$TAPDIR/no-tests" | |
443 | echo "1..1" > "$TAPDIR/no-tests/tests.log" | |
444 | echo "ok 1 - Test suite disabled" >> "$TAPDIR/no-tests/tests.log" | |
b4005bbf MJ |
445 | fi |
446 | ||
09d45745 | 447 | # Clean the build directory |
0cdaa21c | 448 | $MAKE clean |
b4005bbf | 449 | |
0cdaa21c | 450 | # Cleanup rpath in executables and shared libraries |
09d45745 MJ |
451 | find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \; |
452 | find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \; | |
0cdaa21c MJ |
453 | |
454 | # Remove libtool .la files | |
09d45745 | 455 | find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \; |
b4005bbf | 456 | |
09d45745 MJ |
457 | # Exit with failure if any of the tests failed |
458 | exit $failed_tests | |
95654431 MJ |
459 | |
460 | # EOF |