jjb: Add macosxbuild and solarisbuild to lttng-tools
[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
73 # Create build directory
74 rm -rf "$WORKSPACE/build"
75 mkdir -p "$WORKSPACE/build"
76
77 # liburcu
78 URCU_INCS="$WORKSPACE/deps/liburcu/build/include/"
79 URCU_LIBS="$WORKSPACE/deps/liburcu/build/lib/"
80
81 # lttng-ust
82 UST_INCS="$WORKSPACE/deps/lttng-ust/build/include/"
83 UST_LIBS="$WORKSPACE/deps/lttng-ust/build/lib/"
84 UST_JAVA="$WORKSPACE/deps/lttng-ust/build/share/java/"
85
86 # babeltrace
87 BABEL_INCS="$WORKSPACE/deps/babeltrace/build/include/"
88 BABEL_LIBS="$WORKSPACE/deps/babeltrace/build/lib/"
89 BABEL_BINS="$WORKSPACE/deps/babeltrace/build/bin/"
90
91 PREFIX="$WORKSPACE/build"
92
93 # Set platform variables
94 case "$arch" in
95 solaris10)
96 MAKE=gmake
97 TAR=gtar
98 NPROC=gnproc
99 BISON="bison"
100 YACC="$BISON -y"
101 CFLAGS="-D_XOPEN_SOURCE=1 -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__=1"
102 RUN_TESTS="no"
103 ;;
104
105 solaris11)
106 MAKE=gmake
107 TAR=gtar
108 NPROC=nproc
109 BISON="/opt/csw/bin/bison"
110 YACC="$BISON -y"
111 CFLAGS="-D_XOPEN_SOURCE=1 -D_XOPEN_SOURCE_EXTENDED=1 -D__EXTENSIONS__=1"
112 RUN_TESTS="no"
113
114 export PATH="$PATH:/usr/perl5/bin"
115 ;;
116
117 macosx)
118 MAKE=make
119 TAR=tar
120 NPROC="getconf _NPROCESSORS_ONLN"
121 BISON="bison"
122 YACC="$BISON -y"
123 RUN_TESTS="no"
124
125 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
126 export CFLAGS="-I/opt/local/include"
127 export LDFLAGS="-L/opt/local/lib"
128 ;;
129
130 *)
131 MAKE=make
132 TAR=tar
133 NPROC=nproc
134 BISON="bison"
135 YACC="$BISON -y"
136 CFLAGS=""
137 RUN_TESTS="yes"
138
139 PYTHON2=python2
140 PYTHON3=python3
141
142 P2_VERSION=$($PYTHON2 -c "import sys;print(sys.version[:3])")
143 P3_VERSION=$($PYTHON3 -c "import sys;print(sys.version[:3])")
144
145 UST_PYTHON2="$WORKSPACE/deps/lttng-ust/build/lib/python$P2_VERSION/site-packages"
146 UST_PYTHON3="$WORKSPACE/deps/lttng-ust/build/lib/python$P3_VERSION/site-packages"
147 ;;
148 esac
149
150
151 # Run bootstrap prior to configure
152 ./bootstrap
153
154 # Get source version from configure script
155 eval `grep '^PACKAGE_VERSION=' ./configure`
156 PACKAGE_VERSION=`echo "$PACKAGE_VERSION"| sed 's/\-pre$//'`
157
158
159 # Export build flags
160 case "$conf" in
161 no-ust)
162 export CPPFLAGS="-I$URCU_INCS"
163 export LDFLAGS="-L$URCU_LIBS"
164 export LD_LIBRARY_PATH="$URCU_LIBS:$BABEL_LIBS:${LD_LIBRARY_PATH:-}"
165 ;;
166
167 *)
168 export CPPFLAGS="-I$URCU_INCS -I$UST_INCS"
169 export LDFLAGS="-L$URCU_LIBS -L$UST_LIBS"
170 export LD_LIBRARY_PATH="$URCU_LIBS:$UST_LIBS:$BABEL_LIBS:${LD_LIBRARY_PATH:-}"
171 ;;
172 esac
173
174 # The switch to build without UST changed in 2.8
175 if vergte "$PACKAGE_VERSION" "2.8"; then
176 NO_UST="--without-lttng-ust"
177 else
178 NO_UST="--disable-lttng-ust"
179 fi
180
181 # Set configure options for each build configuration
182 CONF_OPTS=""
183 case "$conf" in
184 static)
185 echo "Static build"
186 CONF_OPTS="--enable-static --disable-shared"
187 ;;
188
189 python-bindings)
190 echo "Build with python bindings"
191 # We only support bindings built with Python 3
192 export PYTHON="python3"
193 export PYTHON_CONFIG="/usr/bin/python3-config"
194 CONF_OPTS="--enable-python-bindings"
195 ;;
196
197 no-ust)
198 echo "Build without UST support"
199 CONF_OPTS="$NO_UST"
200 ;;
201
202 java-agent)
203 echo "Build with Java Agents"
204 export JAVA_HOME="/usr/lib/jvm/default-java"
205 export CLASSPATH="$UST_JAVA/*:/usr/share/java/*"
206 CONF_OPTS="--enable-test-java-agent-all"
207 ;;
208
209 python-agent)
210 echo "Build with python agents"
211 export PYTHONPATH="$UST_PYTHON2:$UST_PYTHON3"
212 CONF_OPTS="--enable-test-python-agent-all"
213 ;;
214
215 relayd-only)
216 echo "Build relayd only"
217 CONF_OPTS="--disable-bin-lttng --disable-bin-lttng-consumerd --disable-bin-lttng-crash --disable-bin-lttng-sessiond --disable-extras --disable-man-pages $NO_UST"
218 ;;
219
220 *)
221 echo "Standard build"
222 CONF_OPTS=""
223 ;;
224 esac
225
226
227 # Build type
228 # oot : out-of-tree build
229 # dist: build via make dist
230 # * : normal tree build
231 #
232 # Make sure to move to the build_path and run configure
233 # before continuing
234 BUILD_PATH=$WORKSPACE
235 case "$build" in
236 oot)
237 echo "Out of tree build"
238 BUILD_PATH=$WORKSPACE/oot
239 mkdir -p "$BUILD_PATH"
240 cd "$BUILD_PATH"
241 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" "$WORKSPACE/configure" --prefix="$PREFIX" $CONF_OPTS
242 ;;
243
244 dist)
245 echo "Distribution out of tree build"
246 BUILD_PATH="`mktemp -d`"
247
248 # Initial configure and generate tarball
249 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" ./configure $CONF_OPTS --enable-build-man-pages
250 $MAKE dist
251
252 mkdir -p "$BUILD_PATH"
253 cp ./*.tar.* "$BUILD_PATH/"
254 cd "$BUILD_PATH"
255
256 # Ignore level 1 of tar
257 $TAR xvf ./*.tar.* --strip 1
258
259 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
260 ;;
261
262 *)
263 BUILD_PATH=$WORKSPACE
264 echo "Standard tree build"
265 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" "$WORKSPACE/configure" --prefix="$PREFIX" $CONF_OPTS
266 ;;
267 esac
268
269 # BUILD!
270 $MAKE -j "`$NPROC`" V=1
271 $MAKE install
272
273 # Run tests
274 if [ "$RUN_TESTS" = "yes" ]; then
275 cd tests
276
277 # Allow core dumps
278 ulimit -c unlimited
279
280 # Add 'babeltrace' binary to PATH
281 chmod +x "$BABEL_BINS/babeltrace"
282 export PATH="$PATH:$BABEL_BINS"
283
284 # Prepare tap output dirs
285 rm -rf "$WORKSPACE/tap"
286 mkdir -p "$WORKSPACE/tap"
287 mkdir -p "$WORKSPACE/tap/unit"
288 mkdir -p "$WORKSPACE/tap/fast_regression"
289 mkdir -p "$WORKSPACE/tap/with_bindings_regression"
290
291 # Force the lttng-sessiond path to /bin/true to prevent the spawing of a
292 # lttng-sessiond --daemonize on "lttng create"
293 export LTTNG_SESSIOND_PATH="/bin/true"
294
295 # Run 'unit_tests' and 'fast_regression' test suites for all configs except 'no-ust'
296 if [ "$conf" != "no-ust" ]; then
297 # Run 'unit_tests', 2.8 and up has a new test suite
298 if vergte "$PACKAGE_VERSION" "2.8"; then
299 make check
300 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*'" $BUILD_PATH/tests/" "$WORKSPACE/tap"
301 else
302 prove --merge -v --exec '' - < "$BUILD_PATH/tests/unit_tests" --archive "$WORKSPACE/tap/unit/" || true
303 prove --merge -v --exec '' - < "$BUILD_PATH/tests/fast_regression" --archive "$WORKSPACE/tap/fast_regression/" || true
304 fi
305 else
306 # Regression is disabled for now, we need to adjust the testsuite for no ust builds.
307 echo "Tests disabled for 'no-ust'."
308 fi
309
310 # Run 'with_bindings_regression' test suite for 'python-bindings' config
311 if [ "$conf" = "python-bindings" ]; then
312 prove --merge -v --exec '' - < "$WORKSPACE/tests/with_bindings_regression" --archive "$WORKSPACE/tap/with_bindings_regression/" || true
313 fi
314
315 # TAP plugin is having a hard time with .yml files.
316 find "$WORKSPACE/tap" -name "meta.yml" -exec rm -f {} \;
317
318 # And also with files without extension, so rename all result to *.tap
319 find "$WORKSPACE/tap/" -type f -exec mv {} {}.tap \;
320
321 cd -
322 fi
323
324 # Cleanup
325 $MAKE clean
326
327 # Cleanup rpath in executables and shared libraries
328 find "$WORKSPACE/build/bin" -type f -perm -0500 -exec chrpath --delete {} \;
329 find "$WORKSPACE/build/lib" -name "*.so" -exec chrpath --delete {} \;
330
331 # Remove libtool .la files
332 find "$WORKSPACE/build/lib" -name "*.la" -exec rm -f {} \;
333
334 # Clean temp dir for dist build
335 if [ "$build" = "dist" ]; then
336 cd "$WORKSPACE"
337 rm -rf "$BUILD_PATH"
338 fi
339
340 # EOF
This page took 0.037288 seconds and 5 git commands to generate.