blob: 14c2999c8fcdb7ee16ee00f8ec9bfd9ee1ccbcf0 [file] [log] [blame]
Dean Troyerb1d8e8e2015-02-16 13:58:35 -06001#!/usr/bin/env bash
2#
3# **tools/build_wheels.sh** - Build a cache of Python wheels
4#
5# build_wheels.sh [package [...]]
6#
Dean Troyerdc97cb72015-03-28 08:20:50 -05007# System package prerequisites listed in ``files/*/devlibs`` will be installed
Dean Troyerb1d8e8e2015-02-16 13:58:35 -06008#
9# Builds wheels for all virtual env requirements listed in
10# ``venv-requirements.txt`` plus any supplied on the command line.
11#
Dean Troyerdc97cb72015-03-28 08:20:50 -050012# Assumes:
13# - ``tools/install_pip.sh`` has been run and a suitable ``pip/setuptools`` is available.
Dean Troyerb1d8e8e2015-02-16 13:58:35 -060014
Dean Troyerdc97cb72015-03-28 08:20:50 -050015# If ``TOP_DIR`` is set we're being sourced rather than running stand-alone
Dean Troyerb1d8e8e2015-02-16 13:58:35 -060016# or in a sub-shell
17if [[ -z "$TOP_DIR" ]]; then
18
19 set -o errexit
20 set -o nounset
21
Dean Troyerdc97cb72015-03-28 08:20:50 -050022 # Keep track of the DevStack directory
Dean Troyerb1d8e8e2015-02-16 13:58:35 -060023 TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
24 FILES=$TOP_DIR/files
25
26 # Import common functions
27 source $TOP_DIR/functions
28
29 GetDistro
30
31 source $TOP_DIR/stackrc
32
33 trap err_trap ERR
34
35fi
36
37# Get additional packages to build
38MORE_PACKAGES="$@"
39
Dean Troyerb1d8e8e2015-02-16 13:58:35 -060040# Exit on any errors so that errors don't compound
41function err_trap {
42 local r=$?
43 set +o xtrace
44
45 rm -rf $TMP_VENV_PATH
46
47 exit $r
48}
49
50# Get system prereqs
51install_package $(get_packages devlibs)
52
53# Get a modern ``virtualenv``
54pip_install virtualenv
55
56# Prepare the workspace
57TMP_VENV_PATH=$(mktemp -d tmp-venv-XXXX)
58virtualenv $TMP_VENV_PATH
59
60# Install modern pip and wheel
Ramy Asselindb29a7c2015-02-26 14:30:07 -080061PIP_VIRTUAL_ENV=$TMP_VENV_PATH pip_install -U pip wheel
Dean Troyerb1d8e8e2015-02-16 13:58:35 -060062
Sean Dague5a59ac72015-05-06 09:48:54 -040063# BUG: cffi has a lot of issues. It has no stable ABI, if installed
64# code is built with a different ABI than the one that's detected at
65# load time, it tries to compile on the fly for the new ABI in the
66# install location (which will probably be /usr and not
67# writable). Also cffi is often included via setup_requires by
68# packages, which have different install rules (allowing betas) than
69# pip has.
70#
71# Because of this we must pip install cffi into the venv to build
72# wheels.
73PIP_VIRTUAL_ENV=$TMP_VENV_PATH pip_install_gr cffi
74
Dean Troyerdc97cb72015-03-28 08:20:50 -050075# ``VENV_PACKAGES`` is a list of packages we want to pre-install
Dean Troyerb1d8e8e2015-02-16 13:58:35 -060076VENV_PACKAGE_FILE=$FILES/venv-requirements.txt
77if [[ -r $VENV_PACKAGE_FILE ]]; then
78 VENV_PACKAGES=$(grep -v '^#' $VENV_PACKAGE_FILE)
79fi
80
81for pkg in ${VENV_PACKAGES,/ } ${MORE_PACKAGES}; do
82 $TMP_VENV_PATH/bin/pip wheel $pkg
83done
84
85# Clean up wheel workspace
86rm -rf $TMP_VENV_PATH