lttng-tools: add babeltrace master as a babeltrace value
[lttng-ci.git] / scripts / lttng-tools / build.sh
1 #!/bin/bash -exu
2 # shellcheck disable=SC2103
3 #
4 # Copyright (C) 2016 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
5 # 2016-2019 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 # Version compare functions
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
48 verlte() {
49 vercomp "$1" "$2"; local res="$?"
50 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
51 }
52
53 verlt() {
54 vercomp "$1" "$2"; local res="$?"
55 [ "$res" -eq "2" ]
56 }
57
58 vergte() {
59 vercomp "$1" "$2"; local res="$?"
60 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
61 }
62
63 vergt() {
64 vercomp "$1" "$2"; local res="$?"
65 [ "$res" -eq "1" ]
66 }
67
68 verne() {
69 vercomp "$1" "$2"; local res="$?"
70 [ "$res" -ne "0" ]
71 }
72
73 # Required variables
74 WORKSPACE=${WORKSPACE:-}
75
76 arch=${arch:-}
77 conf=${conf:-}
78 build=${build:-}
79 cc=${cc:-}
80 test_type=${test_type:-}
81
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
92 SRCDIR="$WORKSPACE/src/lttng-tools"
93 TAPDIR="$WORKSPACE/tap"
94 PREFIX="/build"
95
96
97 # Create tmp directory
98 TMPDIR="$WORKSPACE/tmp"
99 mkdir -p "$TMPDIR"
100
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"
107
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
121 export CFLAGS="-g -O2"
122
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
179
180 if [ "x${CC:-}" != "x" ]; then
181 echo "Selected compiler:"
182 "$CC" -v
183 fi
184
185 # Set platform variables
186 case "$arch" in
187 sol10-i386)
188 export MAKE=gmake
189 export TAR=gtar
190 export NPROC=gnproc
191 export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH"
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"
197
198 RUN_TESTS="no"
199 ;;
200
201 sol11-i386)
202 export MAKE=gmake
203 export TAR=gtar
204 export NPROC=nproc
205 export PATH="$PATH:/usr/perl5/bin"
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"
212 ;;
213
214 macosx)
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"
223
224 RUN_TESTS="no"
225 ;;
226
227 cygwin|cygwin64|msys32|msys64)
228 export MAKE=make
229 export TAR=tar
230 export NPROC=nproc
231
232 RUN_TESTS="no"
233 ;;
234
235 *)
236 export MAKE=make
237 export TAR=tar
238 export NPROC=nproc
239
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
248 DEPS_PYTHON2="$WORKSPACE/deps/build/lib/python$P2_VERSION/site-packages"
249 DEPS_PYTHON3="$WORKSPACE/deps/build/lib/python$P3_VERSION/site-packages"
250 ;;
251 esac
252
253 case "$test_type" in
254 full)
255 RUN_TESTS_LONG_REGRESSION="yes"
256 ;;
257 *)
258 RUN_TESTS_LONG_REGRESSION="no"
259 ;;
260 esac
261
262 # Enter the source directory
263 cd "$SRCDIR"
264
265 # Run bootstrap in the source directory prior to configure
266 ./bootstrap
267
268 # Get source version from configure script
269 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
270 PACKAGE_VERSION=${PACKAGE_VERSION//\-pre*/}
271
272
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
279
280 # Most build configs require the python bindings
281 CONF_OPTS=("--prefix=$PREFIX" "--enable-python-bindings")
282
283 # Set configure options and environment variables for each build
284 # configuration.
285 case "$conf" in
286 static)
287 echo "Static lib only configuration"
288
289 CONF_OPTS+=("--enable-static" "--disable-shared")
290 ;;
291
292 no-ust)
293 echo "Build without UST support"
294 CONF_OPTS+=("$NO_UST")
295 ;;
296
297 agents)
298 echo "Java and Python agents configuration"
299
300 export JAVA_HOME="/usr/lib/jvm/default-java"
301 export CLASSPATH="$DEPS_JAVA/*:/usr/share/java/*"
302 export PYTHONPATH="$DEPS_PYTHON2:$DEPS_PYTHON3"
303
304 CONF_OPTS+=("--enable-test-java-agent-all" "--enable-test-python-agent-all")
305 ;;
306
307 relayd-only)
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")
311 ;;
312
313 debug-rcu)
314 echo "Enable RCU sanity checks for debugging"
315
316 export CPPFLAGS="$CPPFLAGS -DDEBUG_RCU"
317 ;;
318
319 *)
320 echo "Standard configuration"
321 ;;
322 esac
323
324 # Build type
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
329 #
330 # Make sure to move to the build directory and run configure
331 # before continuing.
332 case "$build" in
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 ;;
394 esac
395
396 # We are now inside a configured build directory
397
398 # BUILD!
399 $MAKE -j "$($NPROC)" V=1
400
401 # Install in the workspace
402 $MAKE install DESTDIR="$WORKSPACE"
403
404 # Run tests for all configs except 'no-ust'
405 failed_tests=0
406 if [ "$RUN_TESTS" = "yes" ] && [ "$conf" != "no-ust" ]; then
407 # Allow core dumps
408 ulimit -c unlimited
409
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
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"
418 else
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 ..
434 fi
435
436 # TAP plugin is having a hard time with .yml files.
437 find "$TAPDIR" -name "meta.yml" -exec rm -f {} \;
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"
443 fi
444
445 # Clean the build directory
446 $MAKE clean
447
448 # Cleanup rpath in executables and shared libraries
449 find "$WORKSPACE/$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
450 find "$WORKSPACE/$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
451
452 # Remove libtool .la files
453 find "$WORKSPACE/$PREFIX/lib" -name "*.la" -exec rm -f {} \;
454
455 # Exit with failure if any of the tests failed
456 exit $failed_tests
457
458 # EOF
This page took 0.039699 seconds and 5 git commands to generate.