Debian Codegraph @

tools/manylinux/build-wheels.sh

raw
1 #!/bin/bash
2 #
3 # Called inside the manylinux image
4 echo "Started $0 $@"
5
6 set -e -x
7 REQUIREMENTS=/io/requirements.txt
8 [ -n "$WHEELHOUSE" ] || WHEELHOUSE=wheelhouse
9 SDIST=$1
10 PACKAGE=$(basename ${SDIST%-*})
11 SDIST_PREFIX=$(basename ${SDIST%%.tar.gz})
12 [ -z "$PYTHON_BUILD_VERSION" ] && PYTHON_BUILD_VERSION="*"
13
14 build_wheel() {
15 pybin="$1"
16 source="$2"
17 [ -n "$source" ] || source=/io
18
19 env STATIC_DEPS=true \
20 RUN_TESTS=true \
21 LDFLAGS="$LDFLAGS -fPIC" \
22 CFLAGS="$CFLAGS -fPIC" \
23 ACLOCAL_PATH=/usr/share/aclocal/ \
24 ${pybin}/pip \
25 wheel \
26 "$source" \
27 -w /io/$WHEELHOUSE
28 }
29
30 run_tests() {
31 # Install packages and test
32 for PYBIN in /opt/python/${PYTHON_BUILD_VERSION}/bin/; do
33 ${PYBIN}/python -m pip install $PACKAGE --no-index -f /io/$WHEELHOUSE | tee install.txt || exit 1
34
35 # check import as a quick test
36 (cd $HOME; ${PYBIN}/python -c 'import lxml.etree, lxml.objectify') || {
37 # Allow PyPy to fail the import due to C-API differences for 'str' (PyVarObject or not).
38 echo "${PYBIN}" | fgrep -q pypy || exit 1
39 echo "Import failed - deleting wheel"
40 sed -ne '/Processing .*\.whl/s|Processing ||p' install.txt | (cd /io/$WHEELHOUSE && xargs rm)
41 }
42 done
43 }
44
45 prepare_system() {
46 #yum install -y zlib-devel
47 yum --version 2>/dev/null && yum -y install xz || true
48 apt-get --version 2>/dev/null && apt-get install xz-utils || true
49 #rm -fr /opt/python/cp34-*
50 echo "Python versions found: $(cd /opt/python && echo cp* | sed -e 's|[^ ]*-||g')"
51 ${CC:-gcc} --version
52 }
53
54 build_wheels() {
55 # Compile wheels for all python versions
56 test -e "$SDIST" && source="$SDIST" || source=
57 FIRST=
58 SECOND=
59 THIRD=
60 for PYBIN in /opt/python/${PYTHON_BUILD_VERSION}/bin; do
61 # Install build requirements if we need them and file exists
62 test -n "$source" -o ! -e "$REQUIREMENTS" \
63 || ${PYBIN}/python -m pip install -r "$REQUIREMENTS"
64
65 echo "Starting build with $($PYBIN/python -V)"
66 build_wheel "$PYBIN" "$source" &
67 THIRD=$!
68
69 [ -z "$FIRST" ] || wait ${FIRST}
70 if [ "$(uname -m)" == "aarch64" ]; then FIRST=$THIRD; else FIRST=$SECOND; fi
71 SECOND=$THIRD
72 done
73 wait || exit 1
74 }
75
76 repair_wheels() {
77 # Bundle external shared libraries into the wheels
78 for whl in /io/$WHEELHOUSE/${SDIST_PREFIX}-*.whl; do
79 auditwheel repair $whl -w /io/$WHEELHOUSE || exit 1
80 done
81 }
82
83 show_wheels() {
84 ls -l /io/$WHEELHOUSE/${SDIST_PREFIX}-*.whl
85 }
86
87 prepare_system
88 build_wheels
89 repair_wheels
90 run_tests
91 show_wheels