Docker: Update manylinux package generation (Fix #1218)

This commit is contained in:
Corentin Le Molgat
2019-04-29 17:56:12 +02:00
parent 70ae339c2d
commit 3f0a13ca47

View File

@@ -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