Paul Yang | 176bac6 | 2017-06-28 15:22:19 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # DO NOT use this script manually! Called by docker. |
| 4 | |
| 5 | set -ex |
| 6 | |
| 7 | # Print usage and fail. |
| 8 | function usage() { |
Jisi Liu | 8fc40b5 | 2017-12-22 12:05:37 -0800 | [diff] [blame] | 9 | echo "Usage: protobuf_optimized_pip.sh PROTOBUF_VERSION" >&2 |
Paul Yang | 176bac6 | 2017-06-28 15:22:19 -0700 | [diff] [blame] | 10 | exit 1 # Causes caller to exit because we use -e. |
| 11 | } |
| 12 | |
| 13 | # Build wheel |
| 14 | function build_wheel() { |
| 15 | PYTHON_VERSION=$1 |
| 16 | PYTHON_BIN=/opt/python/${PYTHON_VERSION}/bin/python |
| 17 | |
| 18 | $PYTHON_BIN setup.py bdist_wheel --cpp_implementation --compile_static_extension |
| 19 | auditwheel repair dist/protobuf-${PROTOBUF_VERSION}-${PYTHON_VERSION}-linux_x86_64.whl |
| 20 | } |
| 21 | |
| 22 | # Validate arguments. |
| 23 | if [ $0 != ./protobuf_optimized_pip.sh ]; then |
| 24 | echo "Please run this script from the directory in which it is located." >&2 |
| 25 | exit 1 |
| 26 | fi |
| 27 | |
Jisi Liu | 8fc40b5 | 2017-12-22 12:05:37 -0800 | [diff] [blame] | 28 | if [ $# -lt 1 ]; then |
Paul Yang | 176bac6 | 2017-06-28 15:22:19 -0700 | [diff] [blame] | 29 | usage |
| 30 | exit 1 |
| 31 | fi |
| 32 | |
| 33 | PROTOBUF_VERSION=$1 |
| 34 | PYPI_USERNAME=$2 |
| 35 | PYPI_PASSWORD=$3 |
| 36 | |
| 37 | DIR=${PWD}/'protobuf-python-build' |
| 38 | PYTHON_VERSIONS=('cp27-cp27mu' 'cp33-cp33m' 'cp34-cp34m' 'cp35-cp35m' 'cp36-cp36m') |
| 39 | |
| 40 | mkdir -p ${DIR} |
| 41 | cd ${DIR} |
Feng Xiao | afe98de | 2018-08-22 11:55:30 -0700 | [diff] [blame] | 42 | curl -SsL -O https://github.com/protocolbuffers/protobuf/archive/v${PROTOBUF_VERSION}.tar.gz |
Paul Yang | 176bac6 | 2017-06-28 15:22:19 -0700 | [diff] [blame] | 43 | tar xzf v${PROTOBUF_VERSION}.tar.gz |
| 44 | cd $DIR/protobuf-${PROTOBUF_VERSION} |
| 45 | |
| 46 | # Autoconf on centos 5.11 cannot recognize AC_PROG_OBJC. |
| 47 | sed -i '/AC_PROG_OBJC/d' configure.ac |
| 48 | sed -i 's/conformance\/Makefile//g' configure.ac |
| 49 | |
Jisi Liu | 98c6d04 | 2017-08-16 12:57:12 -0700 | [diff] [blame] | 50 | # Use the /usr/bin/autoconf and related tools to pick the correct aclocal macros |
| 51 | export PATH="/usr/bin:$PATH" |
| 52 | |
Paul Yang | 176bac6 | 2017-06-28 15:22:19 -0700 | [diff] [blame] | 53 | # Build protoc |
| 54 | ./autogen.sh |
| 55 | CXXFLAGS="-fPIC -g -O2" ./configure |
| 56 | make -j8 |
| 57 | export PROTOC=$DIR/src/protoc |
| 58 | |
| 59 | cd python |
| 60 | |
| 61 | for PYTHON_VERSION in "${PYTHON_VERSIONS[@]}" |
| 62 | do |
| 63 | build_wheel $PYTHON_VERSION |
| 64 | done |
| 65 | |
Jisi Liu | 8fc40b5 | 2017-12-22 12:05:37 -0800 | [diff] [blame] | 66 | /opt/python/cp27-cp27mu/bin/twine upload wheelhouse/* |