ci-build.sh 10.3 KB
Newer Older
1
#!/bin/bash
2

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# Copyright © 2015-2016 Collabora Ltd.
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

25
set -euo pipefail
26 27
set -x

28
NULL=
29 30 31

# ci_buildsys:
# Build system under test: autotools or cmake
32
: "${ci_buildsys:=autotools}"
33 34 35 36 37 38 39 40

# ci_docker:
# If non-empty, this is the name of a Docker image. ci-install.sh will
# fetch it with "docker pull" and use it as a base for a new Docker image
# named "ci-image" in which we will do our testing.
#
# If empty, we test on "bare metal".
# Typical values: ubuntu:xenial, debian:jessie-slim
41
: "${ci_docker:=}"
42 43 44

# ci_host:
# See ci-install.sh
45
: "${ci_host:=native}"
46 47 48

# ci_parallel:
# A number of parallel jobs, passed to make -j
49
: "${ci_parallel:=1}"
50 51 52

# ci_sudo:
# If yes, assume we can get root using sudo; if no, only use current user
53
: "${ci_sudo:=no}"
54 55 56

# ci_test:
# If yes, run tests; if no, just build
57
: "${ci_test:=yes}"
58 59 60

# ci_test_fatal:
# If yes, test failures break the build; if no, they are reported but ignored
61
: "${ci_test_fatal:=yes}"
62 63 64

# ci_variant:
# One of debug, reduced, legacy, production
65
: "${ci_variant:=production}"
66

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
if [ -n "$ci_docker" ]; then
    exec docker run \
        --env=ci_buildsys="${ci_buildsys}" \
        --env=ci_docker="" \
        --env=ci_host="${ci_host}" \
        --env=ci_parallel="${ci_parallel}" \
        --env=ci_sudo=yes \
        --env=ci_test="${ci_test}" \
        --env=ci_test_fatal="${ci_test_fatal}" \
        --env=ci_variant="${ci_variant}" \
        --privileged \
        ci-image \
        tools/ci-build.sh
fi

82 83 84 85 86 87
maybe_fail_tests () {
    if [ "$ci_test_fatal" = yes ]; then
        exit 1
    fi
}

88 89 90
# Generate config.h.in and configure. We do this for both Autotools and
# CMake builds, so that the CMake build can compare config.h.in with its
# own checks.
91 92 93
NOCONFIGURE=1 ./autogen.sh

srcdir="$(pwd)"
94 95
mkdir ci-build-${ci_variant}-${ci_host}
cd ci-build-${ci_variant}-${ci_host}
96

97
make="make -j${ci_parallel} V=1 VERBOSE=1"
98

99
case "$ci_host" in
100 101 102 103 104 105 106
    (*-w64-mingw32)
        mirror=http://repo.msys2.org/mingw/${ci_host%%-*}
        if [ "${ci_host%%-*}" = i686 ]; then
            mingw="$(pwd)/mingw32"
        else
            mingw="$(pwd)/mingw64"
        fi
107 108 109 110 111 112 113 114 115 116 117 118 119 120
        install -d "${mingw}"
        export PKG_CONFIG_LIBDIR="${mingw}/lib/pkgconfig"
        export PKG_CONFIG_PATH=
        export PKG_CONFIG="pkg-config --define-variable=prefix=${mingw}"
        unset CC
        unset CXX
        for pkg in \
            expat-2.1.0-6 \
            gcc-libs-5.2.0-4 \
            gettext-0.19.6-1 \
            glib2-2.46.1-1 \
            libffi-3.2.1-3 \
            zlib-1.2.8-9 \
            ; do
121 122
            wget ${mirror}/mingw-w64-${ci_host%%-*}-${pkg}-any.pkg.tar.xz
            tar -xvf mingw-w64-${ci_host%%-*}-${pkg}-any.pkg.tar.xz
123 124 125
        done
        export TMPDIR=/tmp
        ;;
126 127
esac

128
case "$ci_buildsys" in
129
    (autotools)
130
        case "$ci_variant" in
131 132 133 134
            (debug)
                # Full developer/debug build.
                set _ "$@"
                set "$@" --enable-developer --enable-tests
135
                # Enable optional features that are off by default
136 137 138 139 140 141 142 143
                case "$ci_host" in
                    *-w64-mingw32)
                        ;;
                    *)
                        set "$@" --enable-containers
                        set "$@" --enable-user-session
                        ;;
                esac
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
                shift
                # The test coverage for OOM-safety is too
                # verbose to be useful on travis-ci.
                export DBUS_TEST_MALLOC_FAILURES=0
                ;;

            (reduced)
                # A smaller configuration than normal, with
                # various features disabled; this emulates
                # an older system or one that does not have
                # all the optional libraries.
                set _ "$@"
                # No LSMs (the production build has both)
                set "$@" --disable-selinux --disable-apparmor
                # No inotify (we will use dnotify)
                set "$@" --disable-inotify
                # No epoll or kqueue (we will use poll)
                set "$@" --disable-epoll --disable-kqueue
                # No special init system support
                set "$@" --disable-launchd --disable-systemd
                # No libaudit or valgrind
                set "$@" --disable-libaudit --without-valgrind
166 167
                # Disable optional features, some of which are on by
                # default
168
                set "$@" --disable-containers
169 170
                set "$@" --disable-stats
                set "$@" --disable-user-session
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
                shift
                ;;

            (legacy)
                # An unrealistically cut-down configuration,
                # to check that it compiles and works.
                set _ "$@"
                # Disable native atomic operations on Unix
                # (armv4, as used as the baseline for Debian
                # armel, is one architecture that really
                # doesn't have them)
                set "$@" dbus_cv_sync_sub_and_fetch=no
                # No epoll, kqueue or poll (we will fall back
                # to select, even on Unix where we would
                # usually at least have poll)
                set "$@" --disable-epoll --disable-kqueue
                set "$@" CPPFLAGS=-DBROKEN_POLL=1
                # Enable SELinux and AppArmor but not
                # libaudit - that configuration has sometimes
                # failed
                set "$@" --enable-selinux --enable-apparmor
                set "$@" --disable-libaudit --without-valgrind
                # No directory monitoring at all
                set "$@" --disable-inotify --disable-dnotify
                # No special init system support
                set "$@" --disable-launchd --disable-systemd
                # No X11 autolaunching
                set "$@" --disable-x11-autolaunch
199 200 201
                # Re-enable the deprecated pam_console support to make
                # sure it still builds
                set "$@" --with-console-auth-dir=/var/run/console
202 203
                # Leave stats, user-session, etc. at default settings
                # to check that the defaults can compile on an old OS
204 205 206 207 208 209 210
                shift
                ;;

            (*)
                ;;
        esac

211
        case "$ci_host" in
212
            (*-w64-mingw32)
213 214
                set _ "$@"
                set "$@" --build="$(build-aux/config.guess)"
215
                set "$@" --host="${ci_host}"
216 217 218 219
                set "$@" CFLAGS=-static-libgcc
                set "$@" CXXFLAGS=-static-libgcc
                # don't run tests yet, Wine needs Xvfb and
                # more msys2 libraries
220
                ci_test=no
221
                # don't "make install" system-wide
222
                ci_sudo=no
223 224 225 226 227 228 229 230 231 232 233 234
                shift
                ;;
        esac

        ../configure \
            --enable-installed-tests \
            --enable-maintainer-mode \
            --enable-modular-tests \
            --with-glib \
            "$@"

        ${make}
235
        [ "$ci_test" = no ] || ${make} check || maybe_fail_tests
236
        cat test/test-suite.log || :
237
        [ "$ci_test" = no ] || ${make} distcheck || maybe_fail_tests
238 239

        ${make} install DESTDIR=$(pwd)/DESTDIR
240
        ( cd DESTDIR && find . -ls )
241

242
        if [ "$ci_sudo" = yes ] && [ "$ci_test" = yes ]; then
243
            sudo ${make} install
244 245
            sudo env LD_LIBRARY_PATH=/usr/local/lib \
                /usr/local/bin/dbus-uuidgen --ensure
246
            LD_LIBRARY_PATH=/usr/local/lib ${make} installcheck || \
247
                maybe_fail_tests
248 249 250 251 252
            cat test/test-suite.log || :

            # re-run them with gnome-desktop-testing
            env LD_LIBRARY_PATH=/usr/local/lib \
            gnome-desktop-testing-runner -d /usr/local/share dbus/ || \
253
                maybe_fail_tests
254

255 256
            # these tests benefit from being re-run as root, and one
            # test needs a finite fd limit to be useful
257
            sudo env LD_LIBRARY_PATH=/usr/local/lib \
258 259 260
            bash -c 'ulimit -S -n 1024; ulimit -H -n 4096; exec "$@"' bash \
                gnome-desktop-testing-runner -d /usr/local/share \
                dbus/test-dbus-daemon_with_config.test \
261
                dbus/test-uid-permissions_with_config.test || \
262
                maybe_fail_tests
263 264 265 266
        fi
        ;;

    (cmake)
267
        case "$ci_host" in
268
            (*-w64-mingw32)
269
                set _ "$@"
270
                set "$@" -D CMAKE_TOOLCHAIN_FILE="${srcdir}/cmake/${ci_host}.cmake"
271 272 273 274
                set "$@" -D CMAKE_PREFIX_PATH="${mingw}"
                set "$@" -D CMAKE_INCLUDE_PATH="${mingw}/include"
                set "$@" -D CMAKE_LIBRARY_PATH="${mingw}/lib"
                set "$@" -D EXPAT_LIBRARY="${mingw}/lib/libexpat.dll.a"
275
                set "$@" -D GLIB2_LIBRARIES="${mingw}/lib/libglib-2.0.dll.a ${mingw}/lib/libgobject-2.0.dll.a ${mingw}/lib/libgio-2.0.dll.a"
276 277 278
                shift
                # don't run tests yet, Wine needs Xvfb and more
                # msys2 libraries
279
                ci_test=no
280 281 282 283 284 285 286 287 288
                ;;
        esac

        cmake "$@" ../cmake

        ${make}
        # The test coverage for OOM-safety is too verbose to be useful on
        # travis-ci.
        export DBUS_TEST_MALLOC_FAILURES=0
289
        [ "$ci_test" = no ] || ctest -VV || maybe_fail_tests
290
        ${make} install DESTDIR=$(pwd)/DESTDIR
291
        ( cd DESTDIR && find . -ls)
292
        ;;
293
esac
294 295

# vim:set sw=4 sts=4 et: