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