11#! /usr/bin/env bash
2+
23# Build all the wheel artifacts for the platforms supported by manylinux2014 and
34# export them to the specified location.
45set -euxo pipefail
56
7+ function assert_defined(){
8+ if [[ -z " ${! 1} " ]]; then
9+ >&2 echo " Variable '${1} ' must be defined"
10+ exit 1
11+ fi
12+ }
13+
614function usage() {
715 local -r NAME=$( basename " $0 " )
816 echo -e " $NAME - Build using a cross toolchain.
@@ -38,56 +46,83 @@ function contains_element() {
3846}
3947
4048function build_wheel() {
49+ assert_defined BUILD_DIR
50+ assert_defined VENV_DIR
4151 # Build the wheel artifact
4252 # Arguments:
4353 # $1 the python root directory
4454 if [[ " $# " -ne 1 ]]; then
4555 echo " $0 called with an illegal number of parameters"
46- exit 1 # TODO return error and check it outside
56+ exit 1
4757 fi
4858
49- # pwd
59+ # Create and activate virtualenv
60+ # this is needed so protoc can call the correct python executable
61+ local -r PYBIN=" $1 /bin"
62+ " ${PYBIN} /pip" install virtualenv
63+ " ${PYBIN} /virtualenv" -p " ${PYBIN} /python" " ${VENV_DIR} "
64+ # shellcheck source=/dev/null
65+ source " ${VENV_DIR} /bin/activate"
66+ pip install -U pip setuptools wheel mypy
67+
68+ echo " current dir: $( pwd) "
69+
5070 if [[ ! -e " CMakeLists.txt" ]] || [[ ! -d " cmake" ]]; then
5171 >&2 echo " Can't find project's CMakeLists.txt or cmake"
5272 exit 2
5373 fi
74+ cmake -S. -B" ${BUILD_DIR} " \
75+ -DCMAKE_BUILD_TYPE=Release \
76+ -DPython3_ROOT_DIR=" $1 " \
77+ -DBUILD_TESTING=OFF # --debug-find
78+ cmake --build " ${BUILD_DIR} " -v -j4
5479
55- cmake -S. -B " ${BUILD_DIR} " -DPython3_ROOT_DIR= " $1 " -DBUILD_TESTING=OFF # --debug-find
56- cmake --build " ${BUILD_DIR} "
80+ # Restore environment
81+ deactivate
5782}
5883
5984function check_wheel() {
85+ assert_defined BUILD_DIR
86+ assert_defined VENV_DIR
6087 # Check the wheel artifact
6188 # Arguments:
6289 # $1 the python root directory
6390 if [[ " $# " -ne 1 ]]; then
6491 echo " $0 called with an illegal number of parameters"
65- exit 1 # TODO return error and check it outside
92+ exit 1
6693 fi
6794
68- # Build python bindings
95+ # shellcheck source=/dev/null
96+ source " ${VENV_DIR} /bin/activate"
97+ pip install -U auditwheel
98+
99+ # Check all generated wheel packages
100+ ROOT_DIR=$( pwd)
69101 pushd " ${BUILD_DIR} /python/dist"
70102 for FILE in * .whl; do
71103 # if no files found do nothing
72104 [[ -e " $FILE " ]] || continue
73- auditwheel show " $FILE " || true
74- # auditwheel -v repair --plat manylinux2014_aarch64 "$FILE" -w "$export_root"
105+ python -m auditwheel show " $FILE " || true
106+ # python -m auditwheel -v repair --plat manylinux2014_aarch64 "$FILE" -w "$export_root"
107+ # python -m auditwheel -v repair --plat manylinux_2_28_x86_64 "$FILE" -w .
75108 done
76109 popd
110+
111+ # Restore environment
112+ deactivate
77113}
78114
79115function test_wheel() {
116+ assert_defined BUILD_DIR
117+ assert_defined TEST_DIR
80118 # Test the wheel artifacts
81119 # Arguments:
82120 # $1 the python root directory
83121 if [[ " $# " -ne 1 ]]; then
84122 echo " $0 called with an illegal number of parameters"
85- exit 1 # TODO return error and check it outside
123+ exit 1
86124 fi
87125
88- local -r BUILD_DIR=" build_${PYTAG} "
89- local -r TEST_DIR=" test_${PYTAG} "
90-
91126 # Create and activate virtualenv
92127 local -r PYBIN=" $1 /bin"
93128 " ${PYBIN} /pip" install virtualenv
@@ -102,29 +137,31 @@ function test_wheel() {
102137 local -r WHEEL_FILE=$( find " ${BUILD_DIR} " /python/dist/* .whl | head -1)
103138 echo " WHEEL file: ${WHEEL_FILE} "
104139 pip install --no-cache-dir " $WHEEL_FILE "
105- pip show pythonnative
140+ pip show cmpb11
106141
107- # Run tests
108- run_tests
109-
110- # Restore environment
111- deactivate
112- }
142+ # Python scripts to be used as tests for the installed wheel. This list of files
143+ # has been taken from the 'test_python' make target.
144+ declare -a TESTS=(
145+ " samples/sample.py "
146+ " tests/test.py "
147+ )
113148
114- function run_tests() {
115149 # Run all the specified test scripts using the current environment.
150+ local -r ROOT_DIR=$( pwd)
116151 pushd " $( mktemp -d) " # ensure we are not importing something from $PWD
117152 python --version
118- for TEST in " ${TESTS[@]} "
119- do
120- python " $TEST "
153+ for TEST in " ${TESTS[@]} " ; do
154+ python " ${ROOT_DIR} /${TEST} "
121155 done
122156 popd
157+
158+ # Restore environment
159+ deactivate
123160}
124161
125162function build() {
126163 # For each python platform provided by manylinux, build and test artifacts.
127- for PYROOT in /opt/python/* ; do
164+ for PYROOT in /opt/python/cp * ; do
128165 # shellcheck disable=SC2155
129166 PYTAG=$( basename " $PYROOT " )
130167 echo " Python: $PYTAG "
@@ -136,15 +173,15 @@ function build() {
136173 fi
137174
138175 BUILD_DIR=" build_${PYTAG} "
139- TEST_DIR= " test_ ${PYTAG} "
176+ VENV_DIR= " env_ ${PYTAG} "
140177 build_wheel " $PYROOT "
141178 check_wheel " $PYROOT "
142179 done
143180}
144181
145182function tests() {
146183 # For each python platform provided by manylinux, build and test artifacts.
147- for PYROOT in /opt/python/* ; do
184+ for PYROOT in /opt/python/cp * ; do
148185 # shellcheck disable=SC2155
149186 PYTAG=$( basename " $PYROOT " )
150187 echo " Python: $PYTAG "
@@ -154,9 +191,9 @@ function tests() {
154191 >&2 echo " skipping deprecated platform $PYTAG "
155192 continue
156193 fi
194+
157195 BUILD_DIR=" build_${PYTAG} "
158196 TEST_DIR=" test_${PYTAG} "
159-
160197 test_wheel " $PYROOT "
161198 done
162199}
@@ -169,10 +206,7 @@ function main() {
169206 esac
170207
171208 # Setup
172- # Python scripts to be used as tests for the installed wheel. This list of files
173- # has been taken from the 'test_python' make target.
174- declare -a TESTS=( " /home/project/ci/samples/sample.py" " /home/project/tests/test.py" )
175- declare -a SKIPS=( " pp37-pypy37_pp73" )
209+ declare -a SKIPS=(" cp36-cp36m" " cp37-cp37m" )
176210
177211 case ${1} in
178212 build)
0 commit comments