blob: 9fed7c5028a76c03103be192e8bf373ac989a4e2 [file] [log] [blame]
Jan Tattermusch8640f922016-02-01 18:58:46 -08001#!/bin/bash
2# Copyright 2016, Google Inc.
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are
7# met:
8#
9# * Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# * Redistributions in binary form must reproduce the above
12# copyright notice, this list of conditions and the following disclaimer
13# in the documentation and/or other materials provided with the
14# distribution.
15# * Neither the name of Google Inc. nor the names of its
16# contributors may be used to endorse or promote products derived from
17# this software without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31set -ex
32
33cd $(dirname $0)/../..
34
Masood Malekghassemi6c061892016-03-21 17:56:32 -070035export GRPC_PYTHON_USE_CUSTOM_BDIST=0
36export GRPC_PYTHON_BUILD_WITH_CYTHON=1
Masood Malekghassemi010eb482016-05-03 15:59:40 -070037export PYTHON=${PYTHON:-python}
38export PIP=${PIP:-pip}
39export AUDITWHEEL=${AUDITWHEEL:-auditwheel}
40
Ken Payson5998cd72016-08-10 15:39:43 -070041# Because multiple builds run in parallel, some distutils file
42# operations may collide. To avoid this, each build is run in
43# a temp directory
44mkdir -p artifacts
45ARTIFACT_DIR="$PWD/artifacts"
46BUILD_DIR=`mktemp -d "${TMPDIR:-/tmp}/pygrpc.XXXXXX"`
47trap "rm -rf $BUILD_DIR" EXIT
48cp -r * "$BUILD_DIR"
49cd "$BUILD_DIR"
Masood Malekghassemi010eb482016-05-03 15:59:40 -070050
Masood Malekghassemi73617342016-02-18 12:39:42 -080051# Build the source distribution first because MANIFEST.in cannot override
52# exclusion of built shared objects among package resources (for some
53# inexplicable reason).
Ken Payson5998cd72016-08-10 15:39:43 -070054${SETARCH_CMD} ${PYTHON} setup.py sdist
Masood Malekghassemi73617342016-02-18 12:39:42 -080055
Masood Malekghassemi73617342016-02-18 12:39:42 -080056# Wheel has a bug where directories don't get excluded.
57# https://bitbucket.org/pypa/wheel/issues/99/cannot-exclude-directory
Ken Payson5998cd72016-08-10 15:39:43 -070058${SETARCH_CMD} ${PYTHON} setup.py bdist_wheel
Masood Malekghassemib6d3a822016-02-11 13:08:14 -080059
Masood Malekghassemif6d09f22016-06-07 22:19:46 -070060# Build gRPC tools package distribution
61${PYTHON} tools/distrib/python/make_grpcio_tools.py
62
Masood Malekghassemi2b867292016-05-05 18:17:45 -070063# Build gRPC tools package source distribution
Ken Payson5998cd72016-08-10 15:39:43 -070064${SETARCH_CMD} ${PYTHON} tools/distrib/python/grpcio_tools/setup.py sdist
Masood Malekghassemi2b867292016-05-05 18:17:45 -070065
66# Build gRPC tools package binary distribution
Ken Payson5998cd72016-08-10 15:39:43 -070067${SETARCH_CMD} ${PYTHON} tools/distrib/python/grpcio_tools/setup.py bdist_wheel
Jan Tattermusch8640f922016-02-01 18:58:46 -080068
Ken Paysoncc17af12016-07-21 11:08:46 -070069if [ "$BUILD_MANYLINUX_WHEEL" != "" ]
Masood Malekghassemi010eb482016-05-03 15:59:40 -070070then
71 for wheel in dist/*.whl; do
Ken Payson5998cd72016-08-10 15:39:43 -070072 ${AUDITWHEEL} repair $wheel -w "$ARTIFACT_DIR"
Ken Paysoncc17af12016-07-21 11:08:46 -070073 rm $wheel
Masood Malekghassemi010eb482016-05-03 15:59:40 -070074 done
75 for wheel in tools/distrib/python/grpcio_tools/dist/*.whl; do
Ken Payson5998cd72016-08-10 15:39:43 -070076 ${AUDITWHEEL} repair $wheel -w "$ARTIFACT_DIR"
Ken Paysoncc17af12016-07-21 11:08:46 -070077 rm $wheel
Masood Malekghassemi010eb482016-05-03 15:59:40 -070078 done
Masood Malekghassemi010eb482016-05-03 15:59:40 -070079fi
Masood Malekghassemi88baf862016-05-04 06:33:15 -070080
Ken Paysondd24c1e2016-07-13 14:18:33 -070081# We need to use the built grpcio-tools/grpcio to compile the health proto
82# Wheels are not supported by setup_requires/dependency_links, so we
83# manually install the dependency. Note we should only do this if we
84# are in a docker image or in a virtualenv.
85if [ "$BUILD_HEALTH_CHECKING" != "" ]
86then
87 ${PIP} install -rrequirements.txt
Ken Payson5998cd72016-08-10 15:39:43 -070088 ${PIP} install grpcio --no-index --find-links "file://$ARTIFACT_DIR/"
89 ${PIP} install grpcio-tools --no-index --find-links "file://$ARTIFACT_DIR/"
Ken Paysondd24c1e2016-07-13 14:18:33 -070090
91 # Build gRPC health check source distribution
92 ${SETARCH_CMD} ${PYTHON} src/python/grpcio_health_checking/setup.py \
93 preprocess build_package_protos sdist
Ken Payson5998cd72016-08-10 15:39:43 -070094 cp -r src/python/grpcio_health_checking/dist/* "$ARTIFACT_DIR"
Ken Paysondd24c1e2016-07-13 14:18:33 -070095fi
96
Ken Payson5998cd72016-08-10 15:39:43 -070097cp -r dist/* "$ARTIFACT_DIR"
98cp -r tools/distrib/python/grpcio_tools/dist/* "$ARTIFACT_DIR"