blob: 07c2a093bba7c7d19f23fc302d125ccdf46bb3b8 [file] [log] [blame]
Paul Yang176bac62017-06-28 15:22:19 -07001#!/usr/bin/env bash
2
3# DO NOT use this script manually! Called by docker.
4
5set -ex
6
7# Print usage and fail.
8function usage() {
Jisi Liu8fc40b52017-12-22 12:05:37 -08009 echo "Usage: protobuf_optimized_pip.sh PROTOBUF_VERSION" >&2
Paul Yang176bac62017-06-28 15:22:19 -070010 exit 1 # Causes caller to exit because we use -e.
11}
12
13# Build wheel
14function 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.
23if [ $0 != ./protobuf_optimized_pip.sh ]; then
24 echo "Please run this script from the directory in which it is located." >&2
25 exit 1
26fi
27
Jisi Liu8fc40b52017-12-22 12:05:37 -080028if [ $# -lt 1 ]; then
Paul Yang176bac62017-06-28 15:22:19 -070029 usage
30 exit 1
31fi
32
33PROTOBUF_VERSION=$1
34PYPI_USERNAME=$2
35PYPI_PASSWORD=$3
36
37DIR=${PWD}/'protobuf-python-build'
38PYTHON_VERSIONS=('cp27-cp27mu' 'cp33-cp33m' 'cp34-cp34m' 'cp35-cp35m' 'cp36-cp36m')
39
40mkdir -p ${DIR}
41cd ${DIR}
Feng Xiaoafe98de2018-08-22 11:55:30 -070042curl -SsL -O https://github.com/protocolbuffers/protobuf/archive/v${PROTOBUF_VERSION}.tar.gz
Paul Yang176bac62017-06-28 15:22:19 -070043tar xzf v${PROTOBUF_VERSION}.tar.gz
44cd $DIR/protobuf-${PROTOBUF_VERSION}
45
46# Autoconf on centos 5.11 cannot recognize AC_PROG_OBJC.
47sed -i '/AC_PROG_OBJC/d' configure.ac
48sed -i 's/conformance\/Makefile//g' configure.ac
49
Jisi Liu98c6d042017-08-16 12:57:12 -070050# Use the /usr/bin/autoconf and related tools to pick the correct aclocal macros
51export PATH="/usr/bin:$PATH"
52
Paul Yang176bac62017-06-28 15:22:19 -070053# Build protoc
54./autogen.sh
55CXXFLAGS="-fPIC -g -O2" ./configure
56make -j8
57export PROTOC=$DIR/src/protoc
58
59cd python
60
61for PYTHON_VERSION in "${PYTHON_VERSIONS[@]}"
62do
63 build_wheel $PYTHON_VERSION
64done
65
Jisi Liu8fc40b52017-12-22 12:05:37 -080066/opt/python/cp27-cp27mu/bin/twine upload wheelhouse/*