From 3f0a13ca47bfc6d41e0ddf5c234d4fb0de9a2a49 Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Mon, 29 Apr 2019 17:56:12 +0200 Subject: [PATCH] Docker: Update manylinux package generation (Fix #1218) --- tools/docker/build-manylinux1.sh | 59 +++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/tools/docker/build-manylinux1.sh b/tools/docker/build-manylinux1.sh index 1c74bf1987..50b60682b3 100755 --- a/tools/docker/build-manylinux1.sh +++ b/tools/docker/build-manylinux1.sh @@ -16,7 +16,7 @@ # BUILD_ROOT if not specified at command line, this value is used as the # root path for the build process. set -x -set -e +set -eo pipefail DEFAULT_BUILD_ROOT="$HOME" DEFAULT_EXPORT_ROOT="${HOME}/export" @@ -177,23 +177,56 @@ do # it has been built once) cd "$SRC_ROOT" make clean_python + + # Hack wheel file to rename it manylinux1 since manylinux2010 is still not + # supported by default pip on most distro. + FILE=(${EXPORT_ROOT}/ortools-*-${PYTAG}-manylinux2010_x86_64.whl) + echo "Old wheel file to hack: ${WHEEL_FILE}" + + # Unpack to hack it + unzip "$FILE" -d /tmp + rm -f $FILE + WHEEL_FILE=(/tmp/ortools-*.dist-info/WHEEL) + RECORD_FILE=(/tmp/ortools-*.dist-info/RECORD) + + # Save old hash and size, in order to look them up in RECORD + # see: https://github.com/pypa/pip/blob/c9df690f3b5bb285a855953272e6fe24f69aa08a/src/pip/_internal/wheel.py#L71-L84 + WHEEL_HASH_CMD="/opt/_internal/cpython-3.7.3/bin/python3 -c \ +\"import hashlib;\ +import base64;\ +print(\ +base64.urlsafe_b64encode(\ +hashlib.sha256(open('${WHEEL_FILE}', 'rb').read())\ +.digest())\ +.decode('latin1')\ +.rstrip('='))\"" + OLD_HASH=$(eval ${WHEEL_HASH_CMD}) + OLD_SIZE=$(wc -c < ${WHEEL_FILE}) + + # Hack the WHEEL file and recompute the new hash + sed -i 's/manylinux2010/manylinux1/' ${WHEEL_FILE} + NEW_HASH=$(eval ${WHEEL_HASH_CMD}) + NEW_SIZE=$(wc -c < ${WHEEL_FILE}) + # Update RECORD file with the new hash and size + sed -i "s/${OLD_HASH},${OLD_SIZE}/${NEW_HASH},${NEW_SIZE}/" ${RECORD_FILE} + + # Repack it as a manylinux1 package + WHEEL_FILE=${FILE//manylinux2010/manylinux1} + (cd /tmp; zip -r ${WHEEL_FILE} ortools ortools-*; rm -r ortools*) + echo "New hacked wheel file: ${WHEEL_FILE}" + + # verify manylinux1 package integrity using pex + pip install pex + python -m pex -o ort.pex ${WHEEL_FILE} + rm ort.pex + # Restore environment deactivate + + ### ### Wheel test ### - - # Hack wheel file to rename it manylinux1 since manylinux2010 is still not - # supported by pip - FILE=(${EXPORT_ROOT}/*-${PYTAG}-*.whl) - unzip "$FILE" -d /tmp - sed -i 's/manylinux2010/manylinux1/' /tmp/ortools-*.dist-info/WHEEL - rm -f $FILE - - WHEEL_FILE=${FILE//manylinux2010/manylinux1} - (cd /tmp; zip -r ${WHEEL_FILE} ortools ortools-*; rm -r ortools*) - echo "Wheel file: ${WHEEL_FILE}" - # Create and activate a new virtualenv "${PYBIN}/virtualenv" -p "${PYBIN}/python" "${BUILD_ROOT}/${PYTAG}-test" # shellcheck source=/dev/null