Dean Troyer | b1d8e8e | 2015-02-16 13:58:35 -0600 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # **tools/build_wheels.sh** - Build a cache of Python wheels |
| 4 | # |
| 5 | # build_wheels.sh [package [...]] |
| 6 | # |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 7 | # System package prerequisites listed in ``files/*/devlibs`` will be installed |
Dean Troyer | b1d8e8e | 2015-02-16 13:58:35 -0600 | [diff] [blame] | 8 | # |
| 9 | # Builds wheels for all virtual env requirements listed in |
| 10 | # ``venv-requirements.txt`` plus any supplied on the command line. |
| 11 | # |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 12 | # Assumes: |
| 13 | # - ``tools/install_pip.sh`` has been run and a suitable ``pip/setuptools`` is available. |
Dean Troyer | b1d8e8e | 2015-02-16 13:58:35 -0600 | [diff] [blame] | 14 | |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 15 | # If ``TOP_DIR`` is set we're being sourced rather than running stand-alone |
Dean Troyer | b1d8e8e | 2015-02-16 13:58:35 -0600 | [diff] [blame] | 16 | # or in a sub-shell |
| 17 | if [[ -z "$TOP_DIR" ]]; then |
| 18 | |
| 19 | set -o errexit |
| 20 | set -o nounset |
| 21 | |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 22 | # Keep track of the DevStack directory |
Dean Troyer | b1d8e8e | 2015-02-16 13:58:35 -0600 | [diff] [blame] | 23 | 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 | |
| 35 | fi |
| 36 | |
| 37 | # Get additional packages to build |
| 38 | MORE_PACKAGES="$@" |
| 39 | |
Dean Troyer | b1d8e8e | 2015-02-16 13:58:35 -0600 | [diff] [blame] | 40 | # Exit on any errors so that errors don't compound |
| 41 | function 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 |
| 51 | install_package $(get_packages devlibs) |
| 52 | |
| 53 | # Get a modern ``virtualenv`` |
| 54 | pip_install virtualenv |
| 55 | |
| 56 | # Prepare the workspace |
| 57 | TMP_VENV_PATH=$(mktemp -d tmp-venv-XXXX) |
| 58 | virtualenv $TMP_VENV_PATH |
| 59 | |
| 60 | # Install modern pip and wheel |
Ramy Asselin | db29a7c | 2015-02-26 14:30:07 -0800 | [diff] [blame] | 61 | PIP_VIRTUAL_ENV=$TMP_VENV_PATH pip_install -U pip wheel |
Dean Troyer | b1d8e8e | 2015-02-16 13:58:35 -0600 | [diff] [blame] | 62 | |
Sean Dague | 5a59ac7 | 2015-05-06 09:48:54 -0400 | [diff] [blame] | 63 | # 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. |
| 73 | PIP_VIRTUAL_ENV=$TMP_VENV_PATH pip_install_gr cffi |
| 74 | |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 75 | # ``VENV_PACKAGES`` is a list of packages we want to pre-install |
Dean Troyer | b1d8e8e | 2015-02-16 13:58:35 -0600 | [diff] [blame] | 76 | VENV_PACKAGE_FILE=$FILES/venv-requirements.txt |
| 77 | if [[ -r $VENV_PACKAGE_FILE ]]; then |
| 78 | VENV_PACKAGES=$(grep -v '^#' $VENV_PACKAGE_FILE) |
| 79 | fi |
| 80 | |
| 81 | for pkg in ${VENV_PACKAGES,/ } ${MORE_PACKAGES}; do |
| 82 | $TMP_VENV_PATH/bin/pip wheel $pkg |
| 83 | done |
| 84 | |
| 85 | # Clean up wheel workspace |
| 86 | rm -rf $TMP_VENV_PATH |