BUS_RESULT: fix missed changes of TRUE/FALSE to BUS_RESULT
[platform/upstream/dbus.git] / tools / ci-build.sh
1 #!/bin/bash
2
3 # Copyright © 2015-2016 Collabora Ltd.
4 #
5 # Permission is hereby granted, free of charge, to any person
6 # obtaining a copy of this software and associated documentation files
7 # (the "Software"), to deal in the Software without restriction,
8 # including without limitation the rights to use, copy, modify, merge,
9 # publish, distribute, sublicense, and/or sell copies of the Software,
10 # and to permit persons to whom the Software is furnished to do so,
11 # subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 # SOFTWARE.
24
25 set -euo pipefail
26 set -x
27
28 NULL=
29
30 # ci_buildsys:
31 # Build system under test: autotools or cmake
32 : "${ci_buildsys:=autotools}"
33
34 # ci_distro:
35 # OS distribution in which we are testing
36 # Typical values: ubuntu, debian; maybe fedora in future
37 : "${ci_distro:=ubuntu}"
38
39 # ci_docker:
40 # If non-empty, this is the name of a Docker image. ci-install.sh will
41 # fetch it with "docker pull" and use it as a base for a new Docker image
42 # named "ci-image" in which we will do our testing.
43 #
44 # If empty, we test on "bare metal".
45 # Typical values: ubuntu:xenial, debian:jessie-slim
46 : "${ci_docker:=}"
47
48 # ci_host:
49 # See ci-install.sh
50 : "${ci_host:=native}"
51
52 # ci_parallel:
53 # A number of parallel jobs, passed to make -j
54 : "${ci_parallel:=1}"
55
56 # ci_sudo:
57 # If yes, assume we can get root using sudo; if no, only use current user
58 : "${ci_sudo:=no}"
59
60 # ci_suite:
61 # OS suite (release, branch) in which we are testing.
62 # Typical values for ci_distro=debian: sid, jessie
63 # Typical values for ci_distro=fedora might be 25, rawhide
64 : "${ci_suite:=xenial}"
65
66 # ci_test:
67 # If yes, run tests; if no, just build
68 : "${ci_test:=yes}"
69
70 # ci_test_fatal:
71 # If yes, test failures break the build; if no, they are reported but ignored
72 : "${ci_test_fatal:=yes}"
73
74 # ci_variant:
75 # One of debug, reduced, legacy, production
76 : "${ci_variant:=production}"
77
78 if [ -n "$ci_docker" ]; then
79     exec docker run \
80         --env=ci_buildsys="${ci_buildsys}" \
81         --env=ci_docker="" \
82         --env=ci_host="${ci_host}" \
83         --env=ci_parallel="${ci_parallel}" \
84         --env=ci_sudo=yes \
85         --env=ci_test="${ci_test}" \
86         --env=ci_test_fatal="${ci_test_fatal}" \
87         --env=ci_variant="${ci_variant}" \
88         --privileged \
89         ci-image \
90         tools/ci-build.sh
91 fi
92
93 maybe_fail_tests () {
94     if [ "$ci_test_fatal" = yes ]; then
95         exit 1
96     fi
97 }
98
99 NOCONFIGURE=1 ./autogen.sh
100
101 srcdir="$(pwd)"
102 mkdir ci-build-${ci_variant}-${ci_host}
103 cd ci-build-${ci_variant}-${ci_host}
104
105 make="make -j${ci_parallel} V=1 VERBOSE=1"
106
107 case "$ci_host" in
108     (*-w64-mingw32)
109         mirror=http://repo.msys2.org/mingw/${ci_host%%-*}
110         if [ "${ci_host%%-*}" = i686 ]; then
111             mingw="$(pwd)/mingw32"
112         else
113             mingw="$(pwd)/mingw64"
114         fi
115         install -d "${mingw}"
116         export PKG_CONFIG_LIBDIR="${mingw}/lib/pkgconfig"
117         export PKG_CONFIG_PATH=
118         export PKG_CONFIG="pkg-config --define-variable=prefix=${mingw}"
119         unset CC
120         unset CXX
121         for pkg in \
122             expat-2.1.0-6 \
123             gcc-libs-5.2.0-4 \
124             gettext-0.19.6-1 \
125             glib2-2.46.1-1 \
126             libffi-3.2.1-3 \
127             zlib-1.2.8-9 \
128             ; do
129             wget ${mirror}/mingw-w64-${ci_host%%-*}-${pkg}-any.pkg.tar.xz
130             tar -xvf mingw-w64-${ci_host%%-*}-${pkg}-any.pkg.tar.xz
131         done
132         export TMPDIR=/tmp
133         ;;
134 esac
135
136 case "$ci_buildsys" in
137     (autotools)
138         case "$ci_variant" in
139             (debug)
140                 # Full developer/debug build.
141                 set _ "$@"
142                 set "$@" --enable-developer --enable-tests
143                 # Enable optional features that are off by default
144                 case "$ci_host" in
145                     *-w64-mingw32)
146                         ;;
147                     *)
148                         set "$@" --enable-user-session
149                         ;;
150                 esac
151                 shift
152                 # The test coverage for OOM-safety is too
153                 # verbose to be useful on travis-ci.
154                 export DBUS_TEST_MALLOC_FAILURES=0
155                 ;;
156
157             (reduced)
158                 # A smaller configuration than normal, with
159                 # various features disabled; this emulates
160                 # an older system or one that does not have
161                 # all the optional libraries.
162                 set _ "$@"
163                 # No LSMs (the production build has both)
164                 set "$@" --disable-selinux --disable-apparmor
165                 # No inotify (we will use dnotify)
166                 set "$@" --disable-inotify
167                 # No epoll or kqueue (we will use poll)
168                 set "$@" --disable-epoll --disable-kqueue
169                 # No special init system support
170                 set "$@" --disable-launchd --disable-systemd
171                 # No libaudit or valgrind
172                 set "$@" --disable-libaudit --without-valgrind
173                 # Disable optional features, some of which are on by
174                 # default
175                 set "$@" --disable-stats
176                 set "$@" --disable-user-session
177                 shift
178                 ;;
179
180             (legacy)
181                 # An unrealistically cut-down configuration,
182                 # to check that it compiles and works.
183                 set _ "$@"
184                 # Disable native atomic operations on Unix
185                 # (armv4, as used as the baseline for Debian
186                 # armel, is one architecture that really
187                 # doesn't have them)
188                 set "$@" dbus_cv_sync_sub_and_fetch=no
189                 # No epoll, kqueue or poll (we will fall back
190                 # to select, even on Unix where we would
191                 # usually at least have poll)
192                 set "$@" --disable-epoll --disable-kqueue
193                 set "$@" CPPFLAGS=-DBROKEN_POLL=1
194                 # Enable SELinux and AppArmor but not
195                 # libaudit - that configuration has sometimes
196                 # failed
197                 set "$@" --enable-selinux --enable-apparmor
198                 set "$@" --disable-libaudit --without-valgrind
199                 # No directory monitoring at all
200                 set "$@" --disable-inotify --disable-dnotify
201                 # No special init system support
202                 set "$@" --disable-launchd --disable-systemd
203                 # No X11 autolaunching
204                 set "$@" --disable-x11-autolaunch
205                 # Re-enable the deprecated pam_console support to make
206                 # sure it still builds
207                 set "$@" --with-console-auth-dir=/var/run/console
208                 # Leave stats, user-session, etc. at default settings
209                 # to check that the defaults can compile on an old OS
210                 shift
211                 ;;
212
213             (*)
214                 ;;
215         esac
216
217         case "$ci_host" in
218             (*-w64-mingw32)
219                 set _ "$@"
220                 set "$@" --build="$(build-aux/config.guess)"
221                 set "$@" --host="${ci_host}"
222                 set "$@" CFLAGS=-static-libgcc
223                 set "$@" CXXFLAGS=-static-libgcc
224                 # don't run tests yet, Wine needs Xvfb and
225                 # more msys2 libraries
226                 ci_test=no
227                 # don't "make install" system-wide
228                 ci_sudo=no
229                 shift
230                 ;;
231         esac
232
233         ../configure \
234             --enable-installed-tests \
235             --enable-maintainer-mode \
236             --enable-modular-tests \
237             "$@"
238
239         ${make}
240         [ "$ci_test" = no ] || ${make} check || maybe_fail_tests
241         cat test/test-suite.log || :
242         [ "$ci_test" = no ] || ${make} distcheck || maybe_fail_tests
243
244         ${make} install DESTDIR=$(pwd)/DESTDIR
245         ( cd DESTDIR && find . -ls )
246
247         case "$ci_suite" in
248             (jessie|xenial|stretch)
249                 # these are too old for maintainer-upload-docs
250                 ;;
251
252             (*)
253                 # assume Ubuntu 18.04 'bionic', Debian 10 'buster' or newer
254                 ${make} -C doc dbus-docs.tar.xz
255                 tar -C $(pwd)/DESTDIR -xf doc/dbus-docs.tar.xz
256                 ( cd DESTDIR/dbus-docs && find . -ls )
257                 ;;
258         esac
259
260         if [ "$ci_sudo" = yes ] && [ "$ci_test" = yes ]; then
261             sudo ${make} install
262             sudo env LD_LIBRARY_PATH=/usr/local/lib \
263                 /usr/local/bin/dbus-uuidgen --ensure
264             LD_LIBRARY_PATH=/usr/local/lib ${make} installcheck || \
265                 maybe_fail_tests
266             cat test/test-suite.log || :
267
268             # re-run them with gnome-desktop-testing
269             env LD_LIBRARY_PATH=/usr/local/lib \
270             gnome-desktop-testing-runner -d /usr/local/share dbus/ || \
271                 maybe_fail_tests
272
273             # these tests benefit from being re-run as root, and one
274             # test needs a finite fd limit to be useful
275             sudo env LD_LIBRARY_PATH=/usr/local/lib \
276             bash -c 'ulimit -S -n 1024; ulimit -H -n 4096; exec "$@"' bash \
277                 gnome-desktop-testing-runner -d /usr/local/share \
278                 dbus/test-dbus-daemon_with_config.test \
279                 dbus/test-uid-permissions_with_config.test || \
280                 maybe_fail_tests
281         fi
282         ;;
283
284     (cmake)
285         case "$ci_host" in
286             (*-w64-mingw32)
287                 set _ "$@"
288                 set "$@" -D CMAKE_TOOLCHAIN_FILE="${srcdir}/cmake/${ci_host}.cmake"
289                 set "$@" -D CMAKE_PREFIX_PATH="${mingw}"
290                 set "$@" -D CMAKE_INCLUDE_PATH="${mingw}/include"
291                 set "$@" -D CMAKE_LIBRARY_PATH="${mingw}/lib"
292                 set "$@" -D EXPAT_LIBRARY="${mingw}/lib/libexpat.dll.a"
293                 set "$@" -D GLIB2_LIBRARIES="${mingw}/lib/libglib-2.0.dll.a"
294                 set "$@" -D GOBJECT_LIBRARIES="${mingw}/lib/libgobject-2.0.dll.a"
295                 set "$@" -D GIO_LIBRARIES="${mingw}/lib/libgio-2.0.dll.a"
296                 shift
297                 # don't run tests yet, Wine needs Xvfb and more
298                 # msys2 libraries
299                 ci_test=no
300                 ;;
301         esac
302
303         cmake "$@" ../cmake
304
305         ${make}
306         # The test coverage for OOM-safety is too verbose to be useful on
307         # travis-ci.
308         export DBUS_TEST_MALLOC_FAILURES=0
309         [ "$ci_test" = no ] || ctest -VV || maybe_fail_tests
310         ${make} install DESTDIR=$(pwd)/DESTDIR
311         ( cd DESTDIR && find . -ls)
312         ;;
313 esac
314
315 # vim:set sw=4 sts=4 et: