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