|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2015 Cloudera Inc. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +set -eu -o pipefail |
| 17 | +set -x |
| 18 | + |
| 19 | +# Called inside the manylinux1 image |
| 20 | +echo "Started $0 $@" |
| 21 | + |
| 22 | +PIP_DISTS_BUILD_DIR="$1" |
| 23 | +GIT_VERSION_TAG="$2" |
| 24 | +GITHUB_ACCOUNT="$3" |
| 25 | + |
| 26 | +PKG_NAME=sasl |
| 27 | +GIT_REPO="python-sasl" |
| 28 | +GIT_URL="https://github.com/${GITHUB_ACCOUNT}/${GIT_REPO}.git" |
| 29 | + |
| 30 | +BDIST_TMP_DIR="${PIP_DISTS_BUILD_DIR}/tmp" |
| 31 | +WHEELHOUSE_DIR="${PIP_DISTS_BUILD_DIR}/wheelhouse" |
| 32 | +SDIST_DIR="${PIP_DISTS_BUILD_DIR}/sdist" |
| 33 | + |
| 34 | +SYSTEM_REQUIREMENTS=(cyrus-sasl cyrus-sasl-devel) |
| 35 | +BUILD_REQUIREMENTS=(devtoolset-2-gcc devtoolset-2-gcc-c++) |
| 36 | + |
| 37 | +prepare_system() { |
| 38 | + # Install system packages required by our library |
| 39 | + yum install -y "${SYSTEM_REQUIREMENTS[@]}" |
| 40 | + |
| 41 | + cd /tmp |
| 42 | + git clone -b "$GIT_VERSION_TAG" --single-branch "$GIT_URL" |
| 43 | + cd "$GIT_REPO" |
| 44 | + echo "Build directory: $(pwd)" |
| 45 | + |
| 46 | + # Clean up dists directory |
| 47 | + rm -rf "$PIP_DISTS_BUILD_DIR" || true |
| 48 | + mkdir -p "$PIP_DISTS_BUILD_DIR" |
| 49 | + |
| 50 | + echo "Python versions found: $(cd /opt/python && echo cp* | sed -e 's|[^ ]*-||g')" |
| 51 | + g++ --version |
| 52 | +} |
| 53 | + |
| 54 | +is_cpython2() { |
| 55 | + local pyver_abi="$1" |
| 56 | + [[ "$pyver_abi" =~ ^cp2 ]] |
| 57 | +} |
| 58 | + |
| 59 | +build_wheels() { |
| 60 | + # Compile wheels for all python versions |
| 61 | + local pydir="" |
| 62 | + local wheel_path="" |
| 63 | + for pydir in /opt/python/*; do |
| 64 | + # Do not build wheels for cpython2 |
| 65 | + local pyver_abi="$(basename $pydir)" |
| 66 | + if is_cpython2 "$pyver_abi"; then continue; fi |
| 67 | + |
| 68 | + echo "Building wheel with $(${pydir}/bin/python -V 2>&1)" |
| 69 | + "${pydir}/bin/python" setup.py bdist_wheel -d "$BDIST_TMP_DIR" |
| 70 | + wheel_path="$(ls ${BDIST_TMP_DIR}/*.whl)" |
| 71 | + done |
| 72 | + |
| 73 | + if [ -z "wheel_path" ]; then |
| 74 | + echo "Failed building wheels. Couldn't find python>=3.0" |
| 75 | + exit 1 |
| 76 | + fi |
| 77 | +} |
| 78 | + |
| 79 | +repair_wheels() { |
| 80 | + # Bundle external shared libraries into the wheels |
| 81 | + for whl in "${BDIST_TMP_DIR}/"*.whl; do |
| 82 | + auditwheel repair $whl -w "$WHEELHOUSE_DIR" |
| 83 | + done |
| 84 | +} |
| 85 | + |
| 86 | +show_wheels() { |
| 87 | + ls -l "${WHEELHOUSE_DIR}/"*.whl |
| 88 | +} |
| 89 | + |
| 90 | +build_sdist() { |
| 91 | + local pydir="" |
| 92 | + local sdist_path="" |
| 93 | + for pydir in /opt/python/*; do |
| 94 | + # Build sdist with python3 |
| 95 | + local pyver_abi="$(basename $pydir)" |
| 96 | + if is_cpython2 "$pyver_abi"; then continue; fi |
| 97 | + |
| 98 | + echo "Building sdist with $(${pydir}/bin/python -V 2>&1)" |
| 99 | + "${pydir}/bin/python" setup.py sdist -d "$SDIST_DIR" |
| 100 | + sdist_path="$(ls ${SDIST_DIR}/*.tar.gz)" |
| 101 | + break |
| 102 | + done |
| 103 | + |
| 104 | + if [ -z "$sdist_path" ]; then |
| 105 | + echo "Failed building sdist. Couldn't find python>=3.0" |
| 106 | + exit 1 |
| 107 | + fi |
| 108 | +} |
| 109 | + |
| 110 | +show_sdist() { |
| 111 | + ls -l "$SDIST_DIR" |
| 112 | +} |
| 113 | + |
| 114 | +set_up_virt_env() { |
| 115 | + local pydir="$1" |
| 116 | + local pyver_abi="$(basename $pydir)" |
| 117 | + |
| 118 | + if is_cpython2 "$pyver_abi"; then |
| 119 | + "${pydir}/bin/python" -m virtualenv sasl_test_env |
| 120 | + else |
| 121 | + "${pydir}/bin/python" -m venv sasl_test_env |
| 122 | + fi |
| 123 | + |
| 124 | + # set -eu must be disabled temporarily for activating the env. |
| 125 | + set +e +u |
| 126 | + source sasl_test_env/bin/activate |
| 127 | + set -eu |
| 128 | +} |
| 129 | + |
| 130 | +tear_down_virt_env() { |
| 131 | + # set -eu must be disabled temporarily for deactivating the env. |
| 132 | + set +e +u |
| 133 | + deactivate |
| 134 | + set -eu |
| 135 | + |
| 136 | + rm -rf sasl_test_env |
| 137 | +} |
| 138 | + |
| 139 | +sanity_check() { |
| 140 | + cat <<EOF >/tmp/sanity_check.py |
| 141 | +import sasl |
| 142 | +from sys import exit |
| 143 | +
|
| 144 | +sasl_client = sasl.Client() |
| 145 | +if not sasl_client.setAttr('service', 'myservice'): exit(1) |
| 146 | +if not sasl_client.setAttr('host', 'myhost'): exit(1) |
| 147 | +if not sasl_client.init(): exit(1) |
| 148 | +ok, enc = sasl_client.encode('1234567890') |
| 149 | +if not ok or enc != b'1234567890': exit(1) |
| 150 | +EOF |
| 151 | + |
| 152 | + cd /tmp |
| 153 | + |
| 154 | + # Install sdist with different python versions and run sanity_check. |
| 155 | + local sdistfn="$(ls ${SDIST_DIR}/${PKG_NAME}-*.tar.gz)" |
| 156 | + local pydir="" |
| 157 | + for pydir in /opt/python/*; do |
| 158 | + set_up_virt_env "$pydir" |
| 159 | + pip install --no-cache-dir --no-binary "$PKG_NAME" "$sdistfn" |
| 160 | + python /tmp/sanity_check.py |
| 161 | + tear_down_virt_env |
| 162 | + done |
| 163 | + |
| 164 | + # Install wheels with different python versions and run sanity_check. |
| 165 | + # System requirements can be removed as the wheels should already include them. |
| 166 | + yum remove -y "${SYSTEM_REQUIREMENTS[@]}" |
| 167 | + yum remove -y "${BUILD_REQUIREMENTS[@]}" |
| 168 | + |
| 169 | + for pydir in /opt/python/*; do |
| 170 | + # Haven't built wheels for cpython2, skip cpython2 testing |
| 171 | + local pyver_abi="$(basename $pydir)" |
| 172 | + if is_cpython2 "$pyver_abi"; then continue; fi |
| 173 | + |
| 174 | + local whlfn="$(ls ${WHEELHOUSE_DIR}/${PKG_NAME}-*-${pyver_abi}-*.whl)" |
| 175 | + |
| 176 | + set_up_virt_env "$pydir" |
| 177 | + pip install --no-cache-dir --only-binary "$PKG_NAME" "$whlfn" |
| 178 | + python /tmp/sanity_check.py |
| 179 | + tear_down_virt_env |
| 180 | + done |
| 181 | +} |
| 182 | + |
| 183 | +prepare_system |
| 184 | + |
| 185 | +build_wheels |
| 186 | +repair_wheels |
| 187 | +show_wheels |
| 188 | + |
| 189 | +build_sdist |
| 190 | +show_sdist |
| 191 | + |
| 192 | +sanity_check |
0 commit comments