• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/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() {
9  echo "Usage: protobuf_optimized_pip.sh PROTOBUF_VERSION" >&2
10  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
28if [ $# -lt 1 ]; then
29  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}
42curl -SsL -O https://github.com/protocolbuffers/protobuf/archive/v${PROTOBUF_VERSION}.tar.gz
43tar 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
50# Use the /usr/bin/autoconf and related tools to pick the correct aclocal macros
51export PATH="/usr/bin:$PATH"
52
53# 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
66/opt/python/cp27-cp27mu/bin/twine upload wheelhouse/*
67