Skip to content

Commit 604325a

Browse files
authored
Merge pull request beeware#23 from paulproteus/add-3.8
Add Python 3.8
2 parents 8830357 + 34a6a60 commit 604325a

File tree

4 files changed

+66
-7
lines changed

4 files changed

+66
-7
lines changed

main.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ function build_one_abi() {
8181
;;
8282
esac
8383

84+
local PYTHON_SOVERSION="${PYTHON_VERSION}"
85+
if [ "$PYTHON_VERSION" = "3.7" ] || [ "$PYTHON_VERSION" = "3.6" ] ; then
86+
# 3.6 and 3.7 use 3.6m/3.7m
87+
PYTHON_SOVERSION="${PYTHON_VERSION}m"
88+
fi
89+
8490
# We use Docker to run the build. We rely on Docker's build cache to allow the
8591
# build to be speedy if nothing changed, approx 1-2 seconds for a no-op build.
8692
# The cache persists even if no Docker "tags" point to the image.
@@ -91,15 +97,15 @@ function build_one_abi() {
9197
# For debugging the Docker image, you can use the name python-android-support-local:latest.
9298
TAG_NAME="python-android-support-local:$(python3 -c 'import random; print(random.randint(0, 1e16))')"
9399
DOCKER_BUILDKIT=1 docker build --tag ${TAG_NAME} --tag python-android-support-local:latest \
94-
--build-arg PYTHON_VERSION="${PYTHON_VERSION}" \
100+
--build-arg PYTHON_VERSION="${PYTHON_VERSION}" --build-arg PYTHON_SOVERSION="${PYTHON_SOVERSION}" \
95101
--build-arg COMPRESS_LEVEL="${COMPRESS_LEVEL}" --build-arg COMPILER_TRIPLE="${COMPILER_TRIPLE}" \
96102
--build-arg OPENSSL_BUILD_TARGET="$OPENSSL_BUILD_TARGET" --build-arg TARGET_ABI_SHORTNAME="$TARGET_ABI_SHORTNAME" \
97103
--build-arg TOOLCHAIN_TRIPLE="$TOOLCHAIN_TRIPLE" --build-arg ANDROID_API_LEVEL="$ANDROID_API_LEVEL" \
98104
-f python.Dockerfile .
99105
# Extract the build artifacts we need to create our zip file.
100106
docker run -v "${PWD}"/build/"${PYTHON_VERSION}"/:/mnt/ --rm --entrypoint rsync "$TAG_NAME" -a /opt/python-build/approot/. /mnt/.
101107
# Extract pyconfig.h for debugging ./configure strangeness.
102-
docker run -v "${PWD}"/build/"${PYTHON_VERSION}"/:/mnt/ --rm --entrypoint rsync "$TAG_NAME" -a /opt/python-build/built/python/include/python"${PYTHON_VERSION}"m/pyconfig.h /mnt/
108+
docker run -v "${PWD}"/build/"${PYTHON_VERSION}"/:/mnt/ --rm --entrypoint rsync "$TAG_NAME" -a /opt/python-build/built/python/include/python"${PYTHON_SOVERSION}"/pyconfig.h /mnt/
103109
# Remove temporary local tag.
104110
docker rmi "$TAG_NAME" > /dev/null
105111
fix_permissions
@@ -233,6 +239,9 @@ Build ZIP file of Python resources for Android, including CPython compiled as a
233239
3.7)
234240
download "python-3.7" "https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz" "55a2cce72049f0794e9a11a84862e9039af9183603b78bc60d89539f82cf533f"
235241
;;
242+
3.8)
243+
download "python-3.8" "https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tar.xz" "dfab5ec723c218082fe3d5d7ae17ecbdebffa9a1aea4d64aa3a2ecdd2e795864"
244+
;;
236245
*)
237246
echo "Invalid Python version: $VERSION"
238247
exit 1
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
From 86b7aee31eb66b99e2e9ff55f83cb2e6393dd8d3 Mon Sep 17 00:00:00 2001
2+
From: Asheesh Laroia <[email protected]>
3+
Date: Fri, 19 Jun 2020 16:47:25 -0700
4+
Subject: [PATCH] Parse certificate authority certs from Android
5+
/etc/security/cacerts directory
6+
7+
---
8+
Lib/ssl.py | 11 +++++++++++
9+
Lib/test/test_ssl.py | 1 +
10+
2 files changed, 12 insertions(+)
11+
12+
diff --git a/Lib/ssl.py b/Lib/ssl.py
13+
index 0726caee49..3878bdd8fa 100644
14+
--- a/Lib/ssl.py
15+
+++ b/Lib/ssl.py
16+
@@ -572,6 +572,17 @@ class SSLContext(_SSLContext):
17+
if sys.platform == "win32":
18+
for storename in self._windows_cert_stores:
19+
self._load_windows_store_certs(storename, purpose)
20+
+ if os.path.exists('/etc/security/cacerts'):
21+
+ certs = []
22+
+ for basename in os.listdir('/etc/security/cacerts'):
23+
+ with open('/etc/security/cacerts/' + basename) as fd:
24+
+ s = fd.read()
25+
+ if 'END CERTIFICATE' not in s:
26+
+ continue
27+
+ lines = s.split('\n')
28+
+ line_end_certificate = [i for i, line in enumerate(lines) if 'END CERTIFICATE' in line][0]
29+
+ certs.append('\n'.join(lines[0:line_end_certificate+1]))
30+
+ self.load_verify_locations(None, None, '\n'.join(certs))
31+
self.set_default_verify_paths()
32+
33+
if hasattr(_SSLContext, 'minimum_version'):
34+
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py
35+
index 0bc0a8c452..3c79debf3e 100644
36+
--- a/Lib/test/test_ssl.py
37+
+++ b/Lib/test/test_ssl.py
38+
@@ -1580,6 +1580,7 @@ class ContextTests(unittest.TestCase):
39+
@unittest.skipIf(sys.platform == "win32", "not-Windows specific")
40+
@unittest.skipIf(IS_LIBRESSL, "LibreSSL doesn't support env vars")
41+
def test_load_default_certs_env(self):
42+
+ raise unittest.SkipTest("Skipping this test for Python within an Android app")
43+
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
44+
with support.EnvironmentVarGuard() as env:
45+
env["SSL_CERT_DIR"] = CAPATH
46+
--
47+
2.27.0
48+

patches/3.8/series

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
01_python_ssl_module_add_android_certificates

python.Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ RUN cd openssl-src && make install SHLIB_EXT='${SHLIB_VERSION_NUMBER}.so'
105105
# requires itself to be installed globally during a cross-compile, and Python 3.6 additionally
106106
# requires Python 2 to be installed at build time.
107107
FROM toolchain as build_python
108-
RUN apt-get update -qq && apt-get -qq install python python3.6 python3.7 pkg-config zip quilt
108+
RUN apt-get update -qq && apt-get -qq install python python3.6 python3.7 python3.8 pkg-config zip quilt
109109

110110
# Get libs & vars
111111
COPY --from=build_openssl /opt/python-build/built/openssl /opt/python-build/built/openssl
@@ -126,8 +126,9 @@ ADD downloads/python-${PYTHON_VERSION}/* .
126126
RUN mv Python-* python-src
127127
# Modify ./configure so that, even though this is Linux, it does not append .1.0 to the .so file.
128128
RUN sed -i -e 's,INSTSONAME="$LDLIBRARY".$SOVERSION,,' python-src/configure
129+
ARG PYTHON_SOVERSION
129130
# Apply a C extensions linker hack; already fixed in Python 3.8+; see https://github.com/python/cpython/commit/254b309c801f82509597e3d7d4be56885ef94c11
130-
RUN sed -i -e s,'libraries or \[\],\["pythonX.Ym"] + libraries if libraries else \["pythonX.Ym"\],' -e "s,pythonX.Ym,python${PYTHON_VERSION}m,g" python-src/Lib/distutils/extension.py
131+
RUN sed -i -e s,'libraries or \[\],\["pythonPYTHON_SOVERSION"] + libraries if libraries else \["pythonPYTHON_SOVERSION"\],' -e "s,pythonPYTHON_SOVERSION,python${PYTHON_SOVERSION},g" python-src/Lib/distutils/extension.py
131132
# Apply a hack to get the NDK library paths into the Python build. Python 3.6 (but not 3.7+) needs OpenSSL here as well.
132133
# TODO(someday): Discuss with e.g. Kivy and see how to remove this.
133134
RUN sed -i -e "s# dirs = \[\]# dirs = \[os.environ.get('SYSROOT_INCLUDE'), os.environ.get('SYSROOT_LIB'), os.environ.get('OPENSSL_INSTALL_DIR') + '/include', os.environ.get('OPENSSL_INSTALL_DIR') + '/lib' \]#" python-src/setup.py
@@ -138,7 +139,7 @@ RUN sed -i -e "s#Linux#DisabledLinuxCheck#" python-src/Lib/platform.py
138139

139140
# Apply our patches to Python. See patches/3.*/* for details.
140141
ADD patches/${PYTHON_VERSION} python-src/patches
141-
RUN cd python-src && quilt push -a
142+
RUN cd python-src && if [ "$(wc -l < patches/series)" != "0" ] ; then quilt push -a; else echo "No patches." ; fi
142143

143144
# Build Python, pre-configuring some values so it doesn't check if those exist.
144145
ENV SYSROOT_LIB=${TOOLCHAIN}/sysroot/usr/lib/${TOOLCHAIN_TRIPLE}/${ANDROID_API_LEVEL}/ \
@@ -174,7 +175,7 @@ RUN cd python-src && make
174175
# Modify stdlib & test suite before `make install`.
175176

176177
# Apply a hack to ctypes so that it loads libpython.so, even though this isn't Windows.
177-
RUN sed -i -e 's,pythonapi = PyDLL(None),pythonapi = PyDLL("libpythonX.Ym.so"),' -e "s,libpythonX.Ym,libpython${PYTHON_VERSION}m,g" python-src/Lib/ctypes/__init__.py
178+
RUN sed -i -e 's,pythonapi = PyDLL(None),pythonapi = PyDLL("libpythonPYTHON_SOVERSION.so"),' -e "s,libpythonPYTHON_SOVERSION,libpython${PYTHON_SOVERSION},g" python-src/Lib/ctypes/__init__.py
178179
# Hack the test suite so that when it tries to remove files, if it can't remove them, the error passes silently.
179180
# To see if ths is still an issue, run `test_bdb`.
180181
RUN sed -i -e "s#NotADirectoryError#NotADirectoryError, OSError#" python-src/Lib/test/support/__init__.py
@@ -206,7 +207,7 @@ RUN cd python-src && rm Lib/test/test_wsgiref.py
206207

207208
# Install Python.
208209
RUN cd python-src && make install
209-
RUN cp -a $PYTHON_INSTALL_DIR/lib/libpython${PYTHON_VERSION}m.so "$JNI_LIBS"
210+
RUN cp -a $PYTHON_INSTALL_DIR/lib/libpython${PYTHON_SOVERSION}.so "$JNI_LIBS"
210211

211212
# Download & install rubicon-java's Java & C parts. The *.py files in rubicon-java are
212213
# incorporated into apps via app dependency management and are ABI-independent since

0 commit comments

Comments
 (0)