]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | #!/usr/bin/env bash |
2 | # -*- mode:sh; tab-width:8; indent-tabs-mode:t -*- | |
7c673cae FG |
3 | # |
4 | # Ceph distributed storage system | |
5 | # | |
6 | # Copyright (C) 2014, 2015 Red Hat <contact@redhat.com> | |
7 | # | |
8 | # Author: Loic Dachary <loic@dachary.org> | |
9 | # | |
10 | # This library is free software; you can redistribute it and/or | |
11 | # modify it under the terms of the GNU Lesser General Public | |
12 | # License as published by the Free Software Foundation; either | |
13 | # version 2.1 of the License, or (at your option) any later version. | |
14 | # | |
11fdf7f2 | 15 | set -e |
7c673cae FG |
16 | DIR=/tmp/install-deps.$$ |
17 | trap "rm -fr $DIR" EXIT | |
18 | mkdir -p $DIR | |
19 | if test $(id -u) != 0 ; then | |
20 | SUDO=sudo | |
21 | fi | |
22 | export LC_ALL=C # the following is vulnerable to i18n | |
23 | ||
11fdf7f2 TL |
24 | ARCH=$(uname -m) |
25 | ||
c07f9fc5 | 26 | function munge_ceph_spec_in { |
9f95a23c TL |
27 | local with_seastar=$1 |
28 | shift | |
11fdf7f2 TL |
29 | local for_make_check=$1 |
30 | shift | |
c07f9fc5 | 31 | local OUTFILE=$1 |
11fdf7f2 TL |
32 | sed -e 's/@//g' < ceph.spec.in > $OUTFILE |
33 | # http://rpm.org/user_doc/conditional_builds.html | |
9f95a23c | 34 | if $with_seastar; then |
11fdf7f2 TL |
35 | sed -i -e 's/%bcond_with seastar/%bcond_without seastar/g' $OUTFILE |
36 | fi | |
37 | if $for_make_check; then | |
38 | sed -i -e 's/%bcond_with make_check/%bcond_without make_check/g' $OUTFILE | |
39 | fi | |
c07f9fc5 FG |
40 | } |
41 | ||
11fdf7f2 TL |
42 | function munge_debian_control { |
43 | local version=$1 | |
44 | shift | |
9f95a23c TL |
45 | local with_seastar=$1 |
46 | shift | |
11fdf7f2 TL |
47 | local for_make_check=$1 |
48 | shift | |
49 | local control=$1 | |
50 | case "$version" in | |
51 | *squeeze*|*wheezy*) | |
52 | control="/tmp/control.$$" | |
53 | grep -v babeltrace debian/control > $control | |
54 | ;; | |
55 | esac | |
9f95a23c TL |
56 | if $with_seastar; then |
57 | sed -i -e 's/^# Crimson[[:space:]]//g' $control | |
58 | fi | |
11fdf7f2 TL |
59 | if $for_make_check; then |
60 | sed -i 's/^# Make-Check[[:space:]]/ /g' $control | |
61 | fi | |
62 | echo $control | |
63 | } | |
64 | ||
65 | function ensure_decent_gcc_on_ubuntu { | |
66 | # point gcc to the one offered by g++-7 if the used one is not | |
67 | # new enough | |
68 | local old=$(gcc -dumpfullversion -dumpversion) | |
b32b8144 | 69 | local new=$1 |
11fdf7f2 | 70 | local codename=$2 |
eafe8130 | 71 | if dpkg --compare-versions $old ge ${new}.0; then |
11fdf7f2 TL |
72 | return |
73 | fi | |
74 | ||
75 | if [ ! -f /usr/bin/g++-${new} ]; then | |
76 | $SUDO tee /etc/apt/sources.list.d/ubuntu-toolchain-r.list <<EOF | |
77 | deb [lang=none] http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu $codename main | |
9f95a23c TL |
78 | deb [arch=amd64 lang=none] http://mirror.nullivex.com/ppa/ubuntu-toolchain-r-test $codename main |
79 | deb [arch=amd64 lang=none] http://deb.rug.nl/ppa/mirror/ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu $codename main | |
11fdf7f2 TL |
80 | EOF |
81 | # import PPA's signing key into APT's keyring | |
82 | cat << ENDOFKEY | $SUDO apt-key add - | |
83 | -----BEGIN PGP PUBLIC KEY BLOCK----- | |
84 | Version: SKS 1.1.6 | |
85 | Comment: Hostname: keyserver.ubuntu.com | |
86 | ||
87 | mI0ESuBvRwEEAMi4cDba7xlKaaoXjO1n1HX8RKrkW+HEIl79nSOSJyvzysajs7zUow/OzCQp | |
88 | 9NswqrDmNuH1+lPTTRNAGtK8r2ouq2rnXT1mTl23dpgHZ9spseR73s4ZBGw/ag4bpU5dNUSt | |
89 | vfmHhIjVCuiSpNn7cyy1JSSvSs3N2mxteKjXLBf7ABEBAAG0GkxhdW5jaHBhZCBUb29sY2hh | |
90 | aW4gYnVpbGRziLYEEwECACAFAkrgb0cCGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAAKCRAe | |
91 | k3eiup7yfzGKA/4xzUqNACSlB+k+DxFFHqkwKa/ziFiAlkLQyyhm+iqz80htRZr7Ls/ZRYZl | |
92 | 0aSU56/hLe0V+TviJ1s8qdN2lamkKdXIAFfavA04nOnTzyIBJ82EAUT3Nh45skMxo4z4iZMN | |
93 | msyaQpNl/m/lNtOLhR64v5ZybofB2EWkMxUzX8D/FQ== | |
94 | =LcUQ | |
95 | -----END PGP PUBLIC KEY BLOCK----- | |
96 | ENDOFKEY | |
97 | $SUDO env DEBIAN_FRONTEND=noninteractive apt-get update -y || true | |
eafe8130 | 98 | $SUDO env DEBIAN_FRONTEND=noninteractive apt-get install -y g++-${new} |
b32b8144 FG |
99 | fi |
100 | ||
eafe8130 | 101 | case "$codename" in |
11fdf7f2 | 102 | trusty) |
b32b8144 | 103 | old=4.8;; |
11fdf7f2 | 104 | xenial) |
b32b8144 | 105 | old=5;; |
9f95a23c TL |
106 | bionic) |
107 | old=7;; | |
b32b8144 | 108 | esac |
b32b8144 FG |
109 | $SUDO update-alternatives --remove-all gcc || true |
110 | $SUDO update-alternatives \ | |
111 | --install /usr/bin/gcc gcc /usr/bin/gcc-${new} 20 \ | |
112 | --slave /usr/bin/g++ g++ /usr/bin/g++-${new} | |
113 | ||
11fdf7f2 TL |
114 | if [ -f /usr/bin/g++-${old} ]; then |
115 | $SUDO update-alternatives \ | |
116 | --install /usr/bin/gcc gcc /usr/bin/gcc-${old} 10 \ | |
117 | --slave /usr/bin/g++ g++ /usr/bin/g++-${old} | |
118 | fi | |
b32b8144 FG |
119 | |
120 | $SUDO update-alternatives --auto gcc | |
121 | ||
122 | # cmake uses the latter by default | |
eafe8130 TL |
123 | $SUDO ln -nsf /usr/bin/gcc /usr/bin/${ARCH}-linux-gnu-gcc |
124 | $SUDO ln -nsf /usr/bin/g++ /usr/bin/${ARCH}-linux-gnu-g++ | |
11fdf7f2 TL |
125 | } |
126 | ||
127 | function install_pkg_on_ubuntu { | |
128 | local project=$1 | |
129 | shift | |
130 | local sha1=$1 | |
131 | shift | |
132 | local codename=$1 | |
133 | shift | |
9f95a23c TL |
134 | local force=$1 |
135 | shift | |
11fdf7f2 TL |
136 | local pkgs=$@ |
137 | local missing_pkgs | |
9f95a23c TL |
138 | if [ $force = "force" ]; then |
139 | missing_pkgs="$@" | |
140 | else | |
141 | for pkg in $pkgs; do | |
142 | if ! apt -qq list $pkg 2>/dev/null | grep -q installed; then | |
143 | missing_pkgs+=" $pkg" | |
144 | fi | |
145 | done | |
146 | fi | |
11fdf7f2 TL |
147 | if test -n "$missing_pkgs"; then |
148 | local shaman_url="https://shaman.ceph.com/api/repos/${project}/master/${sha1}/ubuntu/${codename}/repo" | |
149 | $SUDO curl --silent --location $shaman_url --output /etc/apt/sources.list.d/$project.list | |
150 | $SUDO env DEBIAN_FRONTEND=noninteractive apt-get update -y -o Acquire::Languages=none -o Acquire::Translation=none || true | |
151 | $SUDO env DEBIAN_FRONTEND=noninteractive apt-get install --allow-unauthenticated -y $missing_pkgs | |
152 | fi | |
b32b8144 FG |
153 | } |
154 | ||
11fdf7f2 | 155 | function install_boost_on_ubuntu { |
7f7e6c64 TL |
156 | local ver=1.72 |
157 | local installed_ver=$(apt -qq list --installed ceph-libboost*-dev 2>/dev/null | | |
158 | grep -e 'libboost[0-9].[0-9]\+-dev' | | |
159 | cut -d' ' -f2 | | |
160 | cut -d'.' -f1,2) | |
161 | if test -n "$installed_ver"; then | |
162 | if echo "$installed_ver" | grep -q "^$ver"; then | |
163 | return | |
164 | else | |
165 | $SUDO env DEBIAN_FRONTEND=noninteractive apt-get -y remove "ceph-libboost.*${installed_ver}.*" | |
166 | $SUDO rm -f /etc/apt/sources.list.d/ceph-libboost${installed_ver}.list | |
167 | fi | |
92f5a8d4 | 168 | fi |
7f7e6c64 | 169 | local codename=$1 |
92f5a8d4 | 170 | local project=libboost |
92f5a8d4 | 171 | local sha1=1d7c7a00cc3f37e340bae0360191a757b44ec80c |
11fdf7f2 | 172 | install_pkg_on_ubuntu \ |
92f5a8d4 TL |
173 | $project \ |
174 | $sha1 \ | |
11fdf7f2 | 175 | $codename \ |
9f95a23c | 176 | check \ |
92f5a8d4 TL |
177 | ceph-libboost-atomic$ver-dev \ |
178 | ceph-libboost-chrono$ver-dev \ | |
179 | ceph-libboost-container$ver-dev \ | |
180 | ceph-libboost-context$ver-dev \ | |
181 | ceph-libboost-coroutine$ver-dev \ | |
182 | ceph-libboost-date-time$ver-dev \ | |
183 | ceph-libboost-filesystem$ver-dev \ | |
184 | ceph-libboost-iostreams$ver-dev \ | |
185 | ceph-libboost-program-options$ver-dev \ | |
186 | ceph-libboost-python$ver-dev \ | |
187 | ceph-libboost-random$ver-dev \ | |
188 | ceph-libboost-regex$ver-dev \ | |
189 | ceph-libboost-system$ver-dev \ | |
190 | ceph-libboost-test$ver-dev \ | |
191 | ceph-libboost-thread$ver-dev \ | |
192 | ceph-libboost-timer$ver-dev | |
11fdf7f2 TL |
193 | } |
194 | ||
195 | function version_lt { | |
196 | test $1 != $(echo -e "$1\n$2" | sort -rV | head -n 1) | |
197 | } | |
198 | ||
199 | function ensure_decent_gcc_on_rh { | |
200 | local old=$(gcc -dumpversion) | |
201 | local expected=5.1 | |
202 | local dts_ver=$1 | |
203 | if version_lt $old $expected; then | |
204 | if test -t 1; then | |
205 | # interactive shell | |
206 | cat <<EOF | |
207 | Your GCC is too old. Please run following command to add DTS to your environment: | |
208 | ||
eafe8130 | 209 | scl enable devtoolset-8 bash |
11fdf7f2 TL |
210 | |
211 | Or add following line to the end of ~/.bashrc to add it permanently: | |
212 | ||
eafe8130 | 213 | source scl_source enable devtoolset-8 |
11fdf7f2 TL |
214 | |
215 | see https://www.softwarecollections.org/en/scls/rhscl/devtoolset-7/ for more details. | |
216 | EOF | |
217 | else | |
218 | # non-interactive shell | |
219 | source /opt/rh/devtoolset-$dts_ver/enable | |
220 | fi | |
221 | fi | |
222 | } | |
223 | ||
9f95a23c TL |
224 | for_make_check=false |
225 | if tty -s; then | |
226 | # interactive | |
227 | for_make_check=true | |
228 | elif [ $FOR_MAKE_CHECK ]; then | |
229 | for_make_check=true | |
230 | else | |
231 | for_make_check=false | |
232 | fi | |
233 | ||
11fdf7f2 | 234 | if [ x$(uname)x = xFreeBSDx ]; then |
7c673cae | 235 | $SUDO pkg install -yq \ |
c07f9fc5 | 236 | devel/babeltrace \ |
11fdf7f2 | 237 | devel/binutils \ |
7c673cae | 238 | devel/git \ |
31f18b77 | 239 | devel/gperf \ |
7c673cae FG |
240 | devel/gmake \ |
241 | devel/cmake \ | |
242 | devel/yasm \ | |
243 | devel/boost-all \ | |
244 | devel/boost-python-libs \ | |
245 | devel/valgrind \ | |
246 | devel/pkgconf \ | |
7c673cae FG |
247 | devel/libedit \ |
248 | devel/libtool \ | |
249 | devel/google-perftools \ | |
250 | lang/cython \ | |
251 | devel/py-virtualenv \ | |
252 | databases/leveldb \ | |
11fdf7f2 | 253 | net/openldap24-client \ |
7c673cae | 254 | archivers/snappy \ |
11fdf7f2 | 255 | archivers/liblz4 \ |
7c673cae FG |
256 | ftp/curl \ |
257 | misc/e2fsprogs-libuuid \ | |
258 | misc/getopt \ | |
224ce89b | 259 | net/socat \ |
7c673cae FG |
260 | textproc/expat2 \ |
261 | textproc/gsed \ | |
f64942e4 | 262 | lang/gawk \ |
7c673cae FG |
263 | textproc/libxml2 \ |
264 | textproc/xmlstarlet \ | |
c07f9fc5 FG |
265 | textproc/jq \ |
266 | textproc/py-sphinx \ | |
7c673cae FG |
267 | emulators/fuse \ |
268 | java/junit \ | |
11fdf7f2 | 269 | lang/python36 \ |
c07f9fc5 | 270 | devel/py-pip \ |
11fdf7f2 | 271 | devel/py-flake8 \ |
9f95a23c | 272 | devel/py-tox \ |
7c673cae FG |
273 | devel/py-argparse \ |
274 | devel/py-nose \ | |
c07f9fc5 | 275 | devel/py-prettytable \ |
11fdf7f2 | 276 | www/py-routes \ |
7c673cae | 277 | www/py-flask \ |
11fdf7f2 TL |
278 | www/node \ |
279 | www/npm \ | |
7c673cae | 280 | www/fcgi \ |
11fdf7f2 | 281 | security/nss \ |
9f95a23c | 282 | security/krb5 \ |
11fdf7f2 | 283 | security/oath-toolkit \ |
7c673cae FG |
284 | sysutils/flock \ |
285 | sysutils/fusefs-libs \ | |
286 | ||
31f18b77 FG |
287 | # Now use pip to install some extra python modules |
288 | pip install pecan | |
289 | ||
7c673cae FG |
290 | exit |
291 | else | |
9f95a23c | 292 | [ $WITH_SEASTAR ] && with_seastar=true || with_seastar=false |
7c673cae | 293 | source /etc/os-release |
eafe8130 | 294 | case "$ID" in |
7c673cae FG |
295 | debian|ubuntu|devuan) |
296 | echo "Using apt-get to install dependencies" | |
11fdf7f2 TL |
297 | $SUDO apt-get install -y devscripts equivs |
298 | $SUDO apt-get install -y dpkg-dev | |
b32b8144 | 299 | case "$VERSION" in |
11fdf7f2 | 300 | *Bionic*) |
9f95a23c TL |
301 | ensure_decent_gcc_on_ubuntu 9 bionic |
302 | [ ! $NO_BOOST_PKGS ] && install_boost_on_ubuntu bionic | |
303 | ;; | |
304 | *Disco*) | |
305 | [ ! $NO_BOOST_PKGS ] && apt-get install -y libboost1.67-all-dev | |
11fdf7f2 TL |
306 | ;; |
307 | *) | |
308 | $SUDO apt-get install -y gcc | |
b32b8144 FG |
309 | ;; |
310 | esac | |
7c673cae FG |
311 | if ! test -r debian/control ; then |
312 | echo debian/control is not a readable file | |
313 | exit 1 | |
314 | fi | |
315 | touch $DIR/status | |
316 | ||
317 | backports="" | |
9f95a23c | 318 | control=$(munge_debian_control "$VERSION" "$with_seastar" "$for_make_check" "debian/control") |
11fdf7f2 TL |
319 | case "$VERSION" in |
320 | *squeeze*|*wheezy*) | |
321 | backports="-t $codename-backports" | |
7c673cae FG |
322 | ;; |
323 | esac | |
324 | ||
325 | # make a metapackage that expresses the build dependencies, | |
326 | # install it, rm the .deb; then uninstall the package as its | |
327 | # work is done | |
328 | $SUDO env DEBIAN_FRONTEND=noninteractive mk-build-deps --install --remove --tool="apt-get -y --no-install-recommends $backports" $control || exit 1 | |
329 | $SUDO env DEBIAN_FRONTEND=noninteractive apt-get -y remove ceph-build-deps | |
11fdf7f2 | 330 | if [ "$control" != "debian/control" ] ; then rm $control; fi |
7c673cae FG |
331 | ;; |
332 | centos|fedora|rhel|ol|virtuozzo) | |
9f95a23c TL |
333 | yumdnf="dnf" |
334 | builddepcmd="dnf -y builddep --allowerasing" | |
335 | if [[ $ID =~ centos|rhel ]] && version_lt $VERSION_ID 8; then | |
336 | yumdnf="yum" | |
337 | builddepcmd="yum-builddep -y --setopt=*.skip_if_unavailable=true" | |
7c673cae FG |
338 | fi |
339 | echo "Using $yumdnf to install dependencies" | |
eafe8130 | 340 | if [ "$ID" = "centos" -a "$ARCH" = "aarch64" ]; then |
11fdf7f2 TL |
341 | $SUDO yum-config-manager --disable centos-sclo-sclo || true |
342 | $SUDO yum-config-manager --disable centos-sclo-rh || true | |
343 | $SUDO yum remove centos-release-scl || true | |
344 | fi | |
eafe8130 | 345 | case "$ID" in |
11fdf7f2 | 346 | fedora) |
7f7e6c64 | 347 | $SUDO $yumdnf install -y dnf-utils |
7c673cae | 348 | ;; |
11fdf7f2 TL |
349 | centos|rhel|ol|virtuozzo) |
350 | MAJOR_VERSION="$(echo $VERSION_ID | cut -d. -f1)" | |
9f95a23c | 351 | $SUDO $yumdnf install -y $yumdnf-utils |
eafe8130 | 352 | rpm --quiet --query epel-release || \ |
9f95a23c | 353 | $SUDO $yumdnf -y install --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-$MAJOR_VERSION.noarch.rpm |
7c673cae FG |
354 | $SUDO rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-$MAJOR_VERSION |
355 | $SUDO rm -f /etc/yum.repos.d/dl.fedoraproject.org* | |
11fdf7f2 | 356 | if test $ID = centos -a $MAJOR_VERSION = 7 ; then |
eafe8130 | 357 | case "$ARCH" in |
11fdf7f2 | 358 | x86_64) |
9f95a23c | 359 | $SUDO $yumdnf -y install centos-release-scl |
eafe8130 | 360 | dts_ver=8 |
11fdf7f2 TL |
361 | ;; |
362 | aarch64) | |
9f95a23c | 363 | $SUDO $yumdnf -y install centos-release-scl-rh |
11fdf7f2 TL |
364 | $SUDO yum-config-manager --disable centos-sclo-rh |
365 | $SUDO yum-config-manager --enable centos-sclo-rh-testing | |
92f5a8d4 | 366 | dts_ver=8 |
11fdf7f2 TL |
367 | ;; |
368 | esac | |
369 | elif test $ID = rhel -a $MAJOR_VERSION = 7 ; then | |
eafe8130 TL |
370 | $SUDO yum-config-manager \ |
371 | --enable rhel-server-rhscl-7-rpms \ | |
9f95a23c | 372 | --enable rhel-7-server-optional-rpms \ |
eafe8130 TL |
373 | --enable rhel-7-server-devtools-rpms |
374 | dts_ver=8 | |
9f95a23c | 375 | elif test $ID = centos -a $MAJOR_VERSION = 8 ; then |
adb31ebb TL |
376 | # Enable 'powertools' or 'PowerTools' repo |
377 | $SUDO dnf config-manager --set-enabled $(dnf repolist --all 2>/dev/null|gawk 'tolower($0) ~ /^powertools\s/{print $1}') | |
9f95a23c TL |
378 | # before EPEL8 and PowerTools provide all dependencies, we use sepia for the dependencies |
379 | $SUDO dnf config-manager --add-repo http://apt-mirror.front.sepia.ceph.com/lab-extras/8/ | |
380 | $SUDO dnf config-manager --setopt=apt-mirror.front.sepia.ceph.com_lab-extras_8_.gpgcheck=0 --save | |
381 | $SUDO dnf copr enable -y ktdreyer/ceph-el8 | |
382 | elif test $ID = rhel -a $MAJOR_VERSION = 8 ; then | |
383 | $SUDO subscription-manager repos --enable "codeready-builder-for-rhel-8-*-rpms" | |
384 | $SUDO dnf config-manager --add-repo http://apt-mirror.front.sepia.ceph.com/lab-extras/8/ | |
385 | $SUDO dnf config-manager --setopt=apt-mirror.front.sepia.ceph.com_lab-extras_8_.gpgcheck=0 --save | |
386 | $SUDO dnf copr enable -y ktdreyer/ceph-el8 | |
7c673cae FG |
387 | fi |
388 | ;; | |
389 | esac | |
9f95a23c TL |
390 | munge_ceph_spec_in $with_seastar $for_make_check $DIR/ceph.spec |
391 | # for python3_pkgversion macro defined by python-srpm-macros, which is required by python3-devel | |
392 | $SUDO $yumdnf install -y python3-devel | |
7c673cae | 393 | $SUDO $builddepcmd $DIR/ceph.spec 2>&1 | tee $DIR/yum-builddep.out |
11fdf7f2 TL |
394 | [ ${PIPESTATUS[0]} -ne 0 ] && exit 1 |
395 | if [ -n "$dts_ver" ]; then | |
396 | ensure_decent_gcc_on_rh $dts_ver | |
397 | fi | |
9f95a23c TL |
398 | IGNORE_YUM_BUILDEP_ERRORS="ValueError: SELinux policy is not managed or store cannot be accessed." |
399 | sed "/$IGNORE_YUM_BUILDEP_ERRORS/d" $DIR/yum-builddep.out | grep -qi "error:" && exit 1 | |
7c673cae | 400 | ;; |
1adf2230 | 401 | opensuse*|suse|sles) |
7c673cae | 402 | echo "Using zypper to install dependencies" |
11fdf7f2 | 403 | zypp_install="zypper --gpg-auto-import-keys --non-interactive install --no-recommends" |
92f5a8d4 | 404 | $SUDO $zypp_install systemd-rpm-macros rpm-build || exit 1 |
9f95a23c | 405 | munge_ceph_spec_in $with_seastar $for_make_check $DIR/ceph.spec |
11fdf7f2 | 406 | $SUDO $zypp_install $(rpmspec -q --buildrequires $DIR/ceph.spec) || exit 1 |
7c673cae FG |
407 | ;; |
408 | alpine) | |
409 | # for now we need the testing repo for leveldb | |
410 | TESTREPO="http://nl.alpinelinux.org/alpine/edge/testing" | |
411 | if ! grep -qF "$TESTREPO" /etc/apk/repositories ; then | |
412 | $SUDO echo "$TESTREPO" | sudo tee -a /etc/apk/repositories > /dev/null | |
413 | fi | |
414 | source alpine/APKBUILD.in | |
415 | $SUDO apk --update add abuild build-base ccache $makedepends | |
416 | if id -u build >/dev/null 2>&1 ; then | |
417 | $SUDO addgroup build abuild | |
418 | fi | |
419 | ;; | |
420 | *) | |
421 | echo "$ID is unknown, dependencies will have to be installed manually." | |
422 | exit 1 | |
423 | ;; | |
424 | esac | |
425 | fi | |
426 | ||
427 | function populate_wheelhouse() { | |
428 | local install=$1 | |
429 | shift | |
430 | ||
431 | # although pip comes with virtualenv, having a recent version | |
432 | # of pip matters when it comes to using wheel packages | |
9f95a23c TL |
433 | PIP_OPTS="--timeout 300 --exists-action i" |
434 | pip $PIP_OPTS $install \ | |
435 | 'setuptools >= 0.8' 'pip >= 7.0' 'wheel >= 0.24' 'tox >= 2.9.1' || return 1 | |
7c673cae | 436 | if test $# != 0 ; then |
9f95a23c | 437 | pip $PIP_OPTS $install $@ || return 1 |
7c673cae FG |
438 | fi |
439 | } | |
440 | ||
441 | function activate_virtualenv() { | |
442 | local top_srcdir=$1 | |
9f95a23c | 443 | local env_dir=$top_srcdir/install-deps-python3 |
7c673cae FG |
444 | |
445 | if ! test -d $env_dir ; then | |
9f95a23c | 446 | virtualenv --python=python3 ${env_dir} |
7c673cae FG |
447 | . $env_dir/bin/activate |
448 | if ! populate_wheelhouse install ; then | |
449 | rm -rf $env_dir | |
450 | return 1 | |
451 | fi | |
452 | fi | |
453 | . $env_dir/bin/activate | |
454 | } | |
455 | ||
9f95a23c TL |
456 | function preload_wheels_for_tox() { |
457 | local ini=$1 | |
458 | shift | |
459 | pushd . > /dev/null | |
460 | cd $(dirname $ini) | |
461 | local require_files=$(ls *requirements*.txt 2>/dev/null) || true | |
462 | local constraint_files=$(ls *constraints*.txt 2>/dev/null) || true | |
463 | local require=$(echo -n "$require_files" | sed -e 's/^/-r /') | |
464 | local constraint=$(echo -n "$constraint_files" | sed -e 's/^/-c /') | |
465 | local md5=wheelhouse/md5 | |
466 | if test "$require"; then | |
467 | if ! test -f $md5 || ! md5sum -c $md5 > /dev/null; then | |
468 | rm -rf wheelhouse | |
469 | fi | |
470 | fi | |
471 | if test "$require" && ! test -d wheelhouse ; then | |
472 | type python3 > /dev/null 2>&1 || continue | |
473 | activate_virtualenv $top_srcdir || exit 1 | |
474 | populate_wheelhouse "wheel -w $wip_wheelhouse" $require $constraint || exit 1 | |
475 | mv $wip_wheelhouse wheelhouse | |
476 | md5sum $require_files $constraint_files > $md5 | |
477 | fi | |
478 | popd > /dev/null | |
479 | } | |
480 | ||
7c673cae FG |
481 | # use pip cache if possible but do not store it outside of the source |
482 | # tree | |
483 | # see https://pip.pypa.io/en/stable/reference/pip_install.html#caching | |
9f95a23c TL |
484 | if $for_make_check; then |
485 | mkdir -p install-deps-cache | |
486 | top_srcdir=$(pwd) | |
487 | export XDG_CACHE_HOME=$top_srcdir/install-deps-cache | |
488 | wip_wheelhouse=wheelhouse-wip | |
489 | # | |
490 | # preload python modules so that tox can run without network access | |
491 | # | |
492 | find . -name tox.ini | while read ini ; do | |
493 | preload_wheels_for_tox $ini | |
494 | done | |
495 | rm -rf $top_srcdir/install-deps-python3 | |
496 | rm -rf $XDG_CACHE_HOME | |
497 | type git > /dev/null || (echo "Dashboard uses git to pull dependencies." ; false) | |
498 | fi |