ci: Use ccache to speed up repeated builds
[platform/upstream/dbus.git] / tools / ci-install.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_distro:
31 # OS distribution in which we are testing
32 # Typical values: ubuntu, debian; maybe fedora in future
33 : "${ci_distro:=ubuntu}"
34
35 # ci_docker:
36 # If non-empty, this is the name of a Docker image. ci-install.sh will
37 # fetch it with "docker pull" and use it as a base for a new Docker image
38 # named "ci-image" in which we will do our testing.
39 : "${ci_docker:=}"
40
41 # ci_host:
42 # Either "native", or an Autoconf --host argument to cross-compile
43 # the package
44 : "${ci_host:=native}"
45
46 # ci_in_docker:
47 # Used internally by ci-install.sh. If yes, we are inside the Docker image
48 # (ci_docker is empty in this case).
49 : "${ci_in_docker:=no}"
50
51 # ci_suite:
52 # OS suite (release, branch) in which we are testing.
53 # Typical values for ci_distro=debian: sid, jessie
54 # Typical values for ci_distro=fedora might be 25, rawhide
55 : "${ci_suite:=trusty}"
56
57 if [ $(id -u) = 0 ]; then
58     sudo=
59 else
60     sudo=sudo
61 fi
62
63 if [ -n "$ci_docker" ]; then
64     sed \
65         -e "s/@ci_distro@/${ci_distro}/" \
66         -e "s/@ci_docker@/${ci_docker}/" \
67         -e "s/@ci_suite@/${ci_suite}/" \
68         < tools/ci-Dockerfile.in > Dockerfile
69     exec docker build -t ci-image .
70 fi
71
72 case "$ci_distro" in
73     (debian|ubuntu)
74         # Don't ask questions, just do it
75         sudo="$sudo env DEBIAN_FRONTEND=noninteractive"
76
77         # Debian Docker images use httpredir.debian.org but it seems to be
78         # unreliable; use a CDN instead
79         $sudo sed -i -e 's/httpredir\.debian\.org/deb.debian.org/g' \
80             /etc/apt/sources.list
81
82         # travis-ci has a sources list for Chrome which doesn't support i386
83         : | $sudo tee /etc/apt/sources.list.d/google-chrome.list
84
85         case "$ci_suite" in
86             (trusty)
87                 # Ubuntu 14.04 didn't have the wine32, wine64 packages
88                 wine32=wine:i386
89                 wine64=wine:amd64
90                 ;;
91             (*)
92                 wine32=wine32
93                 wine64=wine64
94                 ;;
95         esac
96
97         case "$ci_host" in
98             (i686-w64-mingw32)
99                 $sudo dpkg --add-architecture i386
100                 ;;
101             (x86_64-w64-mingw32)
102                 # assume the host or container is x86_64 already
103                 ;;
104         esac
105
106         $sudo apt-get -qq -y update
107
108         case "$ci_host" in
109             (i686-w64-mingw32)
110                 $sudo apt-get -qq -y install \
111                     binutils-mingw-w64-i686 \
112                     g++-mingw-w64-i686 \
113                     $wine32 \
114                     ${NULL}
115                 ;;
116             (x86_64-w64-mingw32)
117                 $sudo apt-get -qq -y install \
118                     binutils-mingw-w64-x86-64\
119                     g++-mingw-w64-x86-64 \
120                     $wine64 \
121                     ${NULL}
122                 ;;
123         esac
124
125         $sudo apt-get -qq -y install \
126             autoconf-archive \
127             automake \
128             autotools-dev \
129             ccache \
130             cmake \
131             debhelper \
132             dh-autoreconf \
133             dh-exec \
134             doxygen \
135             dpkg-dev \
136             gnome-desktop-testing \
137             libapparmor-dev \
138             libaudit-dev \
139             libcap-ng-dev \
140             libexpat-dev \
141             libglib2.0-dev \
142             libselinux1-dev \
143             libx11-dev \
144             python \
145             python-dbus \
146             python-gi \
147             valgrind \
148             wget \
149             xauth \
150             xmlto \
151             xsltproc \
152             xvfb \
153             ${NULL}
154
155         case "$ci_suite" in
156             (trusty)
157                 $sudo apt-get -qq -y install libsystemd-daemon-dev
158                 ;;
159             (*)
160                 $sudo apt-get -qq -y install libsystemd-dev
161                 ;;
162         esac
163
164         if [ "$ci_in_docker" = yes ]; then
165             # Add the user that we will use to do the build inside the
166             # Docker container, and let them use sudo
167             adduser --disabled-password user </dev/null
168             apt-get -y install sudo
169             echo "user ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/nopasswd
170             chmod 0440 /etc/sudoers.d/nopasswd
171         fi
172
173         case "$ci_suite" in
174             (trusty|jessie)
175                 # Ubuntu 14.04's autoconf-archive is too old
176                 wget http://deb.debian.org/debian/pool/main/a/autoconf-archive/autoconf-archive_20160916-1_all.deb
177                 $sudo dpkg -i autoconf-archive_*_all.deb
178                 rm autoconf-archive_*_all.deb
179                 ;;
180         esac
181         ;;
182
183     (*)
184         echo "Don't know how to set up ${ci_distro}" >&2
185         exit 1
186         ;;
187 esac
188
189 # vim:set sw=4 sts=4 et: