blob: c57568fa64734f622fd65c2679133e9f1188dd34 [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
Dean Troyerdc97cb72015-03-28 08:20:50 -050063# ``VENV_PACKAGES`` is a list of packages we want to pre-install
Dean Troyerb1d8e8e2015-02-16 13:58:35 -060064VENV_PACKAGE_FILE=$FILES/venv-requirements.txt
65if [[ -r $VENV_PACKAGE_FILE ]]; then
66 VENV_PACKAGES=$(grep -v '^#' $VENV_PACKAGE_FILE)
67fi
68
69for pkg in ${VENV_PACKAGES,/ } ${MORE_PACKAGES}; do
70 $TMP_VENV_PATH/bin/pip wheel $pkg
71done
72
73# Clean up wheel workspace
74rm -rf $TMP_VENV_PATH