jjb: Add windows jobs to babeltrace
[lttng-ci.git] / scripts / lttng-tools / build.sh
1 #!/bin/bash -exu
2 #
3 # Copyright (C) 2016 - Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4 # Michael Jeanson <mjeanson@efficios.com>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19 # Version compare functions
20 vercomp () {
21 set +u
22 if [[ "$1" == "$2" ]]; then
23 return 0
24 fi
25 local IFS=.
26 local i ver1=($1) ver2=($2)
27 # fill empty fields in ver1 with zeros
28 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
29 ver1[i]=0
30 done
31 for ((i=0; i<${#ver1[@]}; i++)); do
32 if [[ -z ${ver2[i]} ]]; then
33 # fill empty fields in ver2 with zeros
34 ver2[i]=0
35 fi
36 if ((10#${ver1[i]} > 10#${ver2[i]})); then
37 return 1
38 fi
39 if ((10#${ver1[i]} < 10#${ver2[i]})); then
40 return 2
41 fi
42 done
43 set -u
44 return 0
45 }
46
47 verlte() {
48 vercomp "$1" "$2"; local res="$?"
49 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
50 }
51
52 verlt() {
53 vercomp "$1" "$2"; local res="$?"
54 [ "$res" -eq "2" ]
55 }
56
57 vergte() {
58 vercomp "$1" "$2"; local res="$?"
59 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
60 }
61
62 vergt() {
63 vercomp "$1" "$2"; local res="$?"
64 [ "$res" -eq "1" ]
65 }
66
67 verne() {
68 vercomp "$1" "$2"; local res="$?"
69 [ "$res" -ne "0" ]
70 }
71
72 # Required parameters
73 arch=${arch:-}
74 conf=${conf:-}
75 build=${build:-}
76
77 SRCDIR="$WORKSPACE/src/lttng-tools"
78 #TMPDIR="$WORKSPACE/tmp"
79 PREFIX="$WORKSPACE/build"
80 TAPDIR="$WORKSPACE/tap"
81
82
83 # Create build and tmp directories
84 rm -rf "$PREFIX" "$TAPDIR"
85 mkdir -p "$PREFIX" "$TAPDIR"
86
87 #export TMPDIR
88
89 # liburcu
90 URCU_INCS="$WORKSPACE/deps/liburcu/build/include/"
91 URCU_LIBS="$WORKSPACE/deps/liburcu/build/lib/"
92
93 # lttng-ust
94 UST_INCS="$WORKSPACE/deps/lttng-ust/build/include/"
95 UST_LIBS="$WORKSPACE/deps/lttng-ust/build/lib/"
96 UST_JAVA="$WORKSPACE/deps/lttng-ust/build/share/java/"
97
98 # babeltrace
99 #BABEL_INCS="$WORKSPACE/deps/babeltrace/build/include/"
100 BABEL_LIBS="$WORKSPACE/deps/babeltrace/build/lib/"
101 BABEL_BINS="$WORKSPACE/deps/babeltrace/build/bin/"
102
103
104 # Set platform variables
105 case "$arch" in
106 solaris10)
107 MAKE=gmake
108 TAR=gtar
109 NPROC=gnproc
110 BISON="bison"
111 YACC="$BISON -y"
112 CFLAGS="-D_XOPEN_SOURCE=1 -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__=1"
113 RUN_TESTS="no"
114 ;;
115
116 solaris11)
117 MAKE=gmake
118 TAR=gtar
119 NPROC=nproc
120 BISON="/opt/csw/bin/bison"
121 YACC="$BISON -y"
122 CFLAGS="-D_XOPEN_SOURCE=1 -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__=1"
123 RUN_TESTS="no"
124
125 export PATH="$PATH:/usr/perl5/bin"
126 ;;
127
128 macosx)
129 MAKE=make
130 TAR=tar
131 NPROC="getconf _NPROCESSORS_ONLN"
132 BISON="bison"
133 YACC="$BISON -y"
134 RUN_TESTS="no"
135
136 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
137 CFLAGS="-I/opt/local/include"
138 LDFLAGS="-L/opt/local/lib"
139 ;;
140
141 *)
142 MAKE=make
143 TAR=tar
144 NPROC=nproc
145 BISON="bison"
146 YACC="$BISON -y"
147 CFLAGS=""
148 RUN_TESTS="yes"
149
150 PYTHON2=python2
151 PYTHON3=python3
152
153 P2_VERSION=$($PYTHON2 -c "import sys;print(sys.version[:3])")
154 P3_VERSION=$($PYTHON3 -c "import sys;print(sys.version[:3])")
155
156 UST_PYTHON2="$WORKSPACE/deps/lttng-ust/build/lib/python$P2_VERSION/site-packages"
157 UST_PYTHON3="$WORKSPACE/deps/lttng-ust/build/lib/python$P3_VERSION/site-packages"
158 ;;
159 esac
160
161
162 # Enter the source directory
163 cd "$SRCDIR"
164
165 # Run bootstrap in the source directory prior to configure
166 ./bootstrap
167
168 # Get source version from configure script
169 eval "$(grep '^PACKAGE_VERSION=' ./configure)"
170 PACKAGE_VERSION=$(echo "$PACKAGE_VERSION"| sed 's/\-pre$//')
171
172
173 # Export build flags
174 case "$conf" in
175 no-ust)
176 CPPFLAGS="${CPPFLAGS:-} -I$URCU_INCS"
177 LDFLAGS="${LDFLAGS:-} -L$URCU_LIBS"
178 export LD_LIBRARY_PATH="$URCU_LIBS:$BABEL_LIBS:${LD_LIBRARY_PATH:-}"
179 ;;
180
181 *)
182 CPPFLAGS="${CPPFLAGS:-} -I$URCU_INCS -I$UST_INCS"
183 LDFLAGS="${LDFLAGS:-} -L$URCU_LIBS -L$UST_LIBS"
184 export LD_LIBRARY_PATH="$URCU_LIBS:$UST_LIBS:$BABEL_LIBS:${LD_LIBRARY_PATH:-}"
185 ;;
186 esac
187
188 # The switch to build without UST changed in 2.8
189 if vergte "$PACKAGE_VERSION" "2.8"; then
190 NO_UST="--without-lttng-ust"
191 else
192 NO_UST="--disable-lttng-ust"
193 fi
194
195 # Set configure options for each build configuration
196 CONF_OPTS=""
197 case "$conf" in
198 static)
199 echo "Static build"
200 CONF_OPTS="--enable-static --disable-shared"
201 ;;
202
203 no-ust)
204 echo "Build without UST support"
205 CONF_OPTS="$NO_UST"
206 ;;
207
208 agents)
209 echo "Enable Java Agents"
210 export JAVA_HOME="/usr/lib/jvm/default-java"
211 export CLASSPATH="$UST_JAVA/*:/usr/share/java/*"
212 CONF_OPTS+=" --enable-test-java-agent-all"
213
214 echo "Enable Python agents"
215 export PYTHONPATH="$UST_PYTHON2:$UST_PYTHON3"
216 CONF_OPTS+=" --enable-test-python-agent-all"
217
218 echo "Enable Python bindings"
219 # We only support bindings built with Python 3
220 export PYTHON="python3"
221 export PYTHON_CONFIG="/usr/bin/python3-config"
222 CONF_OPTS+=" --enable-python-bindings"
223 ;;
224
225 relayd-only)
226 echo "Build relayd only"
227 CONF_OPTS="--disable-bin-lttng --disable-bin-lttng-consumerd --disable-bin-lttng-crash --disable-bin-lttng-sessiond --disable-extras --disable-man-pages $NO_UST"
228 ;;
229
230 debug-rcu)
231 echo "Enable RCU sanity checks for debugging"
232 CPPFLAGS="${CPPFLAGS:-} -DDEBUG_RCU"
233 ;;
234
235 *)
236 echo "Standard build"
237 CONF_OPTS=""
238 ;;
239 esac
240
241
242 # Build type
243 # oot : out-of-tree build
244 # dist : build via make dist
245 # oot-dist: build via make dist out-of-tree
246 # * : normal tree build
247 #
248 # Make sure to move to the build_path and run configure
249 # before continuing
250 BUILD_PATH=$SRCDIR
251 case "$build" in
252 oot)
253 echo "Out of tree build"
254 BUILD_PATH=$WORKSPACE/oot
255 mkdir -p "$BUILD_PATH"
256 cd "$BUILD_PATH"
257 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS
258 ;;
259
260 dist)
261 echo "Distribution tarball in-tree build"
262
263 # Initial configure and generate tarball
264 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$SRCDIR/configure" $CONF_OPTS --enable-build-man-pages
265 $MAKE dist
266
267 BUILD_PATH="$(mktemp -d)"
268 cp ./*.tar.* "$BUILD_PATH/"
269 cd "$BUILD_PATH"
270
271 # Ignore level 1 of tar
272 $TAR xvf ./*.tar.* --strip 1
273
274 # Build in extracted source tree
275 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
276 ;;
277
278 oot-dist)
279 echo "Distribution tarball out of tree build"
280 BUILD_PATH="$(mktemp -d)"
281 cd "$BUILD_PATH"
282
283 # Initial configure and generate tarball
284 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$SRCDIR/configure" $CONF_OPTS --enable-build-man-pages
285 $MAKE dist
286
287 NEWSRC_PATH="$(mktemp -d)"
288 cp ./*.tar.* "$NEWSRC_PATH/"
289 cd "$NEWSRC_PATH"
290
291 # Ignore level 1 of tar
292 $TAR xvf ./*.tar.* --strip 1
293
294 BUILD_PATH="$(mktemp -d)"
295 cd "$BUILD_PATH"
296
297 # Build oot from extracted sources
298 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$NEWSRC_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
299 ;;
300
301 *)
302 echo "Standard tree build"
303 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
304 ;;
305 esac
306
307 # BUILD!
308 $MAKE -j "$($NPROC)" V=1
309 $MAKE install
310
311 # Run tests
312 if [ "$RUN_TESTS" = "yes" ]; then
313 cd tests || exit 1
314
315 # Allow core dumps
316 ulimit -c unlimited
317
318 # Add 'babeltrace' binary to PATH
319 chmod +x "$BABEL_BINS/babeltrace"
320 export PATH="$PATH:$BABEL_BINS"
321
322 # Prepare tap output dirs
323 rm -rf "$TAPDIR"
324 mkdir -p "$TAPDIR"
325 mkdir -p "$TAPDIR/unit"
326 mkdir -p "$TAPDIR/fast_regression"
327 mkdir -p "$TAPDIR/with_bindings_regression"
328
329 # Force the lttng-sessiond path to /bin/true to prevent the spawing of a
330 # lttng-sessiond --daemonize on "lttng create"
331 export LTTNG_SESSIOND_PATH="/bin/true"
332
333 # Run 'unit_tests' and 'fast_regression' test suites for all configs except 'no-ust'
334 if [ "$conf" != "no-ust" ]; then
335 # Run 'unit_tests', 2.8 and up has a new test suite
336 if vergte "$PACKAGE_VERSION" "2.8"; then
337 make check
338 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*'" $BUILD_PATH/tests/" "$TAPDIR"
339 else
340 prove --merge -v --exec '' - < "$BUILD_PATH/tests/unit_tests" --archive "$TAPDIR/unit/" || true
341 prove --merge -v --exec '' - < "$BUILD_PATH/tests/fast_regression" --archive "$TAPDIR/fast_regression/" || true
342 fi
343 else
344 # Regression is disabled for now, we need to adjust the testsuite for no ust builds.
345 echo "Tests disabled for 'no-ust'."
346 fi
347
348 # Run 'with_bindings_regression' test suite for 'python-bindings' config
349 if [ "$conf" = "python-bindings" ]; then
350 prove --merge -v --exec '' - < "$BUILD_PATH/tests/with_bindings_regression" --archive "$TAPDIR/with_bindings_regression/" || true
351 fi
352
353 # TAP plugin is having a hard time with .yml files.
354 find "$TAPDIR" -name "meta.yml" -exec rm -f {} \;
355
356 # And also with files without extension, so rename all result to *.tap
357 find "$TAPDIR/" -type f -exec mv {} {}.tap \;
358
359 cd -
360 fi
361
362 # Cleanup
363 $MAKE clean
364
365 # Cleanup rpath in executables and shared libraries
366 find "$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
367 find "$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
368
369 # Remove libtool .la files
370 find "$PREFIX/lib" -name "*.la" -exec rm -f {} \;
371
372 # Clean temp dir for dist build
373 if [ "$build" = "dist" ]; then
374 cd "$SRCDIR"
375 rm -rf "$BUILD_PATH"
376 fi
377
378 # EOF
This page took 0.057705 seconds and 5 git commands to generate.