blob: c87b6dafe60a37f3761e1a99f0320d4f9c564637 [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#
7# System package prerequisites listed in files/*/devlibs will be installed
8#
9# Builds wheels for all virtual env requirements listed in
10# ``venv-requirements.txt`` plus any supplied on the command line.
11#
12# Assumes ``tools/install_pip.sh`` has been run and a suitable pip/setuptools is available.
13
14# If TOP_DIR is set we're being sourced rather than running stand-alone
15# or in a sub-shell
16if [[ -z "$TOP_DIR" ]]; then
17
18 set -o errexit
19 set -o nounset
20
21 # Keep track of the devstack directory
22 TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
23 FILES=$TOP_DIR/files
24
25 # Import common functions
26 source $TOP_DIR/functions
27
28 GetDistro
29
30 source $TOP_DIR/stackrc
31
32 trap err_trap ERR
33
34fi
35
36# Get additional packages to build
37MORE_PACKAGES="$@"
38
39# Set a fall-back default, assume that since this script is being called
40# package builds are to happen even if WHEELHOUSE is not configured
41export WHEELHOUSE=${WHEELHOUSE:-.wheelhouse}
42
43# Exit on any errors so that errors don't compound
44function err_trap {
45 local r=$?
46 set +o xtrace
47
48 rm -rf $TMP_VENV_PATH
49
50 exit $r
51}
52
53# Get system prereqs
54install_package $(get_packages devlibs)
55
56# Get a modern ``virtualenv``
57pip_install virtualenv
58
59# Prepare the workspace
60TMP_VENV_PATH=$(mktemp -d tmp-venv-XXXX)
61virtualenv $TMP_VENV_PATH
62
63# Install modern pip and wheel
64$TMP_VENV_PATH/bin/pip install -U pip wheel
65
66# VENV_PACKAGES is a list of packages we want to pre-install
67VENV_PACKAGE_FILE=$FILES/venv-requirements.txt
68if [[ -r $VENV_PACKAGE_FILE ]]; then
69 VENV_PACKAGES=$(grep -v '^#' $VENV_PACKAGE_FILE)
70fi
71
72for pkg in ${VENV_PACKAGES,/ } ${MORE_PACKAGES}; do
73 $TMP_VENV_PATH/bin/pip wheel $pkg
74done
75
76# Clean up wheel workspace
77rm -rf $TMP_VENV_PATH