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