@@ -105,34 +105,43 @@ function build_one_abi() {
105
105
fix_permissions
106
106
}
107
107
108
- # Download a file and verify its sha256sum.
109
- function download_verify_sha256() {
110
- local url=" $1 "
111
- local sha256=" $2 "
112
- local filename_prefix=" ${3:- } "
113
- local DOWNLOAD_CACHE=" $PWD /downloads"
114
- local DOWNLOAD_CACHE_TMP=" $PWD /downloads.tmp"
115
- local expected_filename=" ${filename_prefix} $( echo " $url " | tr ' /' ' \n' | tail -n1) "
108
+ # Download a file into downloads/$name/$filename and verify its sha256sum.
109
+ # If any files exist under downloads/$name, remove them. In the Dockerfile,
110
+ # we refer to the tarball as downloads/$name/* , allowing the Dockerfile
111
+ # to avoid redundantly stating the version number.
112
+ function download() {
113
+ local name=" $1 "
114
+ local url=" $2 "
115
+ local sha256=" $3 "
116
+ local download_dir=" ${PWD} /downloads/$name "
117
+ local base_filename=" $( echo " $url " | tr ' /' ' \n' | tail -n1) "
118
+ local full_filename=" $download_dir /$base_filename "
119
+ local full_filename_tmp=" ${full_filename} .tmp"
116
120
117
121
# Check existing file.
118
- if [ -f " ${DOWNLOAD_CACHE} / ${expected_filename }" ] ; then
119
- echo " Using ${expected_filename} from downloads/ "
122
+ if [ -f " ${full_filename } " ] ; then
123
+ echo " Using $name ( ${full_filename} ) "
120
124
return
121
125
fi
122
126
123
- echo " Downloading $expected_filename "
124
- rm -rf downloads.tmp && mkdir -p downloads.tmp
125
- curl -L " $url " -o " downloads.tmp/$expected_filename "
127
+ echo " Downloading $name ($full_filename )"
128
+ rm -rf " $download_dir "
129
+ mkdir -p " $download_dir "
130
+ curl -L " $url " -o " $full_filename_tmp "
126
131
local OK=" no"
127
- shasum -a 256 " ${DOWNLOAD_CACHE_TMP} /${expected_filename} " | grep -q " $sha256 " && OK=" yes"
132
+ local actual_sha256=$( shasum -a 256 " ${full_filename_tmp} " )
133
+ echo $actual_sha256 | grep -q " $sha256 " && OK=" yes"
128
134
if [ " $OK " = " yes" ] ; then
129
- mkdir -p " $DOWNLOAD_CACHE "
130
- mv " ${DOWNLOAD_CACHE_TMP} /${expected_filename} " " ${DOWNLOAD_CACHE} /${expected_filename} "
131
- rmdir " ${DOWNLOAD_CACHE_TMP} "
135
+ mv " ${full_filename_tmp} " " ${full_filename} "
132
136
else
133
- echo " Checksum mismatch while downloading: $url "
137
+ echo " Checksum mismatch while downloading $name <$url >"
138
+ echo " Expected: $sha256 "
139
+ echo " Got: $actual_sha256 "
134
140
echo " "
135
- echo " Maybe your Internet connection got disconnected during the download. Please re-run the script."
141
+ echo " Maybe your Internet connection got disconnected during the download. Re-run"
142
+ echo " the script to re-download. If you're updating the version of this package"
143
+ echo " update the expected SHA in this script."
144
+ echo " Partial file remains in: ${full_filename_tmp} "
136
145
echo " Aborting."
137
146
exit 1
138
147
fi
@@ -149,8 +158,8 @@ fix_permissions() {
149
158
function main() {
150
159
# Interpret argv for settings; first, set defaults. For some settings, create
151
160
# DEFAULT_* variables for inclusion into help output.
152
- local DEFAULT_VERSIONS= " 3.6, 3.7"
153
- local VERSIONS =" $DEFAULT_VERSIONS "
161
+ local DEFAULT_VERSION= " 3.7"
162
+ local VERSION =" $DEFAULT_VERSION "
154
163
local DEFAULT_TARGET_ABIS=" x86,x86_64,armeabi-v7a,arm64-v8a"
155
164
local TARGET_ABIS=" $DEFAULT_TARGET_ABIS "
156
165
local DEFAULT_COMPRESS_LEVEL=" 8"
@@ -159,7 +168,7 @@ function main() {
159
168
while getopts " :v:a:n:z:" opt; do
160
169
case " ${opt} " in
161
170
v) # process Python version
162
- VERSIONS =" $OPTARG "
171
+ VERSION =" $OPTARG "
163
172
;;
164
173
a) # process Android ABIs
165
174
TARGET_ABIS=" $OPTARG "
@@ -174,12 +183,12 @@ function main() {
174
183
echo " Invalid option: $OPTARG requires an argument" 1>&2
175
184
;;
176
185
\? )
177
- echo " Usage: main.sh [-v versions ] [-a ABIs] [-n build_number] [-z compression_level]
186
+ echo " Usage: main.sh [-v version ] [-a ABIs] [-n build_number] [-z compression_level]
178
187
179
188
Build ZIP file of Python resources for Android, including CPython compiled as a .so.
180
189
181
- -v: Specify Python versions to build, separated by commas . For example: -v 3.6,3.7
182
- Default: ${DEFAULT_VERSIONS }
190
+ -v: Specify Python version to build. For example: -v 3.6
191
+ Default: ${DEFAULT_VERSION }
183
192
184
193
-a: Specify Android ABIs to build, separated by commas. For example: -a x86,arm64-v8a
185
194
Default: ${TARGET_ABIS}
@@ -207,58 +216,50 @@ Build ZIP file of Python resources for Android, including CPython compiled as a
207
216
208
217
echo " Downloading compile-time dependencies."
209
218
210
- local build_dependencies=(
211
- " https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u242-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u242b08.tar.gz=f39b523c724d0e0047d238eb2bb17a9565a60574cf651206c867ee5fc000ab43"
212
- " https://dl.google.com/android/repository/android-ndk-r20b-linux-x86_64.zip=8381c440fe61fcbb01e209211ac01b519cd6adf51ab1c2281d5daad6ca4c8c8c"
213
- " https://www.openssl.org/source/openssl-1.1.1f.tar.gz=186c6bfe6ecfba7a5b48c47f8a1673d0f3b0e5ba2e25602dd23b629975da3f35"
214
- " https://github.com/libffi/libffi/releases/download/v3.3/libffi-3.3.tar.gz=72fba7922703ddfa7a028d513ac15a85c8d54c8d67f55fa5a4802885dc652056"
215
- " https://tukaani.org/xz/xz-5.2.4.tar.gz=b512f3b726d3b37b6dc4c8570e137b9311e7552e8ccbab4d39d47ce5f4177145"
216
- " https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz=ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269"
217
- " http://archive.ubuntu.com/ubuntu/pool/main/s/sqlite3/sqlite3_3.11.0.orig.tar.xz=79fb8800b8744337d5317270899a5a40612bb76f81517e131bf496c26b044490"
218
- )
219
- for build_dependency in " ${build_dependencies[@]} " ; do
220
- download_verify_sha256 ${build_dependency/ =/ }
221
- done
222
-
223
- # Download rubicon-java source tarball with a rubicon-java-* filename prefix. This allows the
224
- # Dockerfile to find it as rubicon-java-*.tar.gz . Other tarballs don't need this treatment
225
- # because they have the project name in the filename.
226
- download_verify_sha256 " https://github.com/beeware/rubicon-java/archive/v0.2.0.tar.gz" " b0d3d9ad4988c2d0e6995e2cbec085a5ef49b15e1be0d325b6141fb90fccccf7" " rubicon-java-"
219
+ download jdk " https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u242-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u242b08.tar.gz" " f39b523c724d0e0047d238eb2bb17a9565a60574cf651206c867ee5fc000ab43"
220
+ download ndk " https://dl.google.com/android/repository/android-ndk-r20b-linux-x86_64.zip" " 8381c440fe61fcbb01e209211ac01b519cd6adf51ab1c2281d5daad6ca4c8c8c"
221
+ download openssl " https://www.openssl.org/source/openssl-1.1.1g.tar.gz" " ddb04774f1e32f0c49751e21b67216ac87852ceb056b75209af2443400636d46"
222
+ download libffi " https://github.com/libffi/libffi/releases/download/v3.3/libffi-3.3.tar.gz" " 72fba7922703ddfa7a028d513ac15a85c8d54c8d67f55fa5a4802885dc652056"
223
+ download xz " https://tukaani.org/xz/xz-5.2.5.tar.gz" " f6f4910fd033078738bd82bfba4f49219d03b17eb0794eb91efbae419f4aba10"
224
+ download bzip2 " https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz" " ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269"
225
+ download sqlite3 " http://archive.ubuntu.com/ubuntu/pool/main/s/sqlite3/sqlite3_3.11.0.orig.tar.xz" " 79fb8800b8744337d5317270899a5a40612bb76f81517e131bf496c26b044490"
226
+ download rubicon-java " https://github.com/beeware/rubicon-java/archive/v0.2.1.tar.gz" " a1d1c6edccbd75631a0c3cc129239e10f7b6d8f221a393b96fbdc83293636f8b"
227
227
228
- echo " Downloading Python versions, as needed."
229
- for version in ${VERSIONS// ,/ } ; do
230
- if [ " $version " = " 3.7" ] ; then
231
- download_verify_sha256 " https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz" " 55a2cce72049f0794e9a11a84862e9039af9183603b78bc60d89539f82cf533f"
232
- elif [ " $version " = " 3.6" ] ; then
233
- download_verify_sha256 " https://www.python.org/ftp/python/3.6.10/Python-3.6.10.tar.xz" " 0a833c398ac8cd7c5538f7232d8531afef943c60495c504484f308dac3af40de"
234
- else
235
- echo " Unknown Python version: $version . Aborting."
228
+ echo " Downloading Python version."
229
+ case " $VERSION " in
230
+ 3.6)
231
+ download " python-3.6" " https://www.python.org/ftp/python/3.6.10/Python-3.6.10.tar.xz" " 0a833c398ac8cd7c5538f7232d8531afef943c60495c504484f308dac3af40de"
232
+ ;;
233
+ 3.7)
234
+ download " python-3.7" " https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz" " 55a2cce72049f0794e9a11a84862e9039af9183603b78bc60d89539f82cf533f"
235
+ ;;
236
+ * )
237
+ echo " Invalid Python version: $VERSION "
236
238
exit 1
237
- fi
238
- done
239
+ ;;
240
+ esac
239
241
240
242
echo ' Starting Docker builds.'
241
- for VERSION in ${VERSIONS// ,/ } ; do
242
- # Clear the build directory.
243
- mkdir -p build
244
- mkdir -p dist
245
- fix_permissions
246
- rm -rf ./build/" $VERSION "
247
- mkdir -p build/" $VERSION "
248
243
249
- # Build each ABI.
250
- for TARGET_ABI_SHORTNAME in ${TARGET_ABIS// ,/ } ; do
251
- echo " Building Python $VERSION for $TARGET_ABI_SHORTNAME "
252
- build_one_abi " $TARGET_ABI_SHORTNAME " " $VERSION " " $COMPRESS_LEVEL "
253
- done
244
+ # Clear the build directory.
245
+ mkdir -p build
246
+ mkdir -p dist
247
+ fix_permissions
248
+ rm -rf ./build/" $VERSION "
249
+ mkdir -p build/" $VERSION "
254
250
255
- # Make a ZIP file, writing it first to `.tmp` so that we atomically clobber an
256
- # existing ZIP file rather than attempt to merge the new contents with old.
257
- pushd build/" $VERSION " /app > /dev/null
258
- zip -x@../../../excludes/all/excludes -r -" ${COMPRESS_LEVEL} " " ../../../dist/Python-$VERSION -Android-support${BUILD_TAG} .zip" .tmp .
259
- mv " ../../../dist/Python-$VERSION -Android-support${BUILD_TAG} .zip" .tmp " ../../../dist/Python-$VERSION -Android-support${BUILD_TAG} .zip"
260
- popd
251
+ # Build each ABI.
252
+ for TARGET_ABI_SHORTNAME in ${TARGET_ABIS// ,/ } ; do
253
+ echo " Building Python $VERSION for $TARGET_ABI_SHORTNAME "
254
+ build_one_abi " $TARGET_ABI_SHORTNAME " " $VERSION " " $COMPRESS_LEVEL "
261
255
done
256
+
257
+ # Make a ZIP file, writing it first to `.tmp` so that we atomically clobber an
258
+ # existing ZIP file rather than attempt to merge the new contents with old.
259
+ pushd build/" $VERSION " /app > /dev/null
260
+ zip -x@../../../excludes/all/excludes -r -" ${COMPRESS_LEVEL} " " ../../../dist/Python-$VERSION -Android-support${BUILD_TAG} .zip" .tmp .
261
+ mv " ../../../dist/Python-$VERSION -Android-support${BUILD_TAG} .zip" .tmp " ../../../dist/Python-$VERSION -Android-support${BUILD_TAG} .zip"
262
+ popd
262
263
}
263
264
264
265
main " $@ "
0 commit comments