From ae59f8ab74100d20ae42ded2ec4987e120c59104 Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Tue, 24 Dec 2019 00:10:50 +0000 Subject: [PATCH 1/8] Did basic changes for Python3.8 support --- .../main/java/org/kivy/android/PythonUtil.java | 6 +++--- pythonforandroid/python.py | 17 +++++++++++++---- .../recipes/hostpython3/__init__.py | 2 +- pythonforandroid/recipes/python3/__init__.py | 9 ++++++--- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonUtil.java b/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonUtil.java index d7eb704f12..460f704190 100644 --- a/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonUtil.java +++ b/pythonforandroid/bootstraps/sdl2/build/src/main/java/org/kivy/android/PythonUtil.java @@ -44,6 +44,7 @@ protected static ArrayList getLibraries(File libsDir) { libsList.add("python3.5m"); libsList.add("python3.6m"); libsList.add("python3.7m"); + libsList.add("python3.8m"); libsList.add("main"); return libsList; } @@ -64,7 +65,7 @@ public static void loadLibraries(File filesDir, File libsDir) { // load, and it has failed, give a more // general error Log.v(TAG, "Library loading error: " + e.getMessage()); - if (lib.startsWith("python3.7") && !foundPython) { + if (lib.startsWith("python3.8") && !foundPython) { throw new java.lang.RuntimeException("Could not load any libpythonXXX.so"); } else if (lib.startsWith("python")) { continue; @@ -81,7 +82,7 @@ public static void loadLibraries(File filesDir, File libsDir) { } catch(UnsatisfiedLinkError e) { Log.v(TAG, "Failed to load _io.so or unicodedata.so...but that's okay."); } - + try { // System.loadLibrary("ctypes"); System.load(filesDirPath + "/lib/python2.7/lib-dynload/_ctypes.so"); @@ -92,4 +93,3 @@ public static void loadLibraries(File filesDir, File libsDir) { Log.v(TAG, "Loaded everything!"); } } - diff --git a/pythonforandroid/python.py b/pythonforandroid/python.py index a46b602c60..aa34aaf76f 100755 --- a/pythonforandroid/python.py +++ b/pythonforandroid/python.py @@ -438,10 +438,19 @@ def build_arch(self, arch): if not exists('config.status'): shprint(sh.Command(join(recipe_build_dir, 'configure'))) - # Create the Setup file. This copying from Setup.dist - # seems to be the normal and expected procedure. - shprint(sh.cp, join('Modules', 'Setup.dist'), - join(build_dir, 'Modules', 'Setup')) + # Create the Setup file. This copying from Setup.dist is + # the normal and expected procedure before Python 3.8, but + # after this the file with default options is already named "Setup" + setup_dist_location = join('Modules', 'Setup.dist') + if exists(setup_dist_location): + shprint(sh.cp, join('Modules', 'Setup.dist'), + join(build_dir, 'Modules', 'Setup')) + else: + # Check the expected file does exist + setup_location = join('Modules', 'Setup') + if not exists(setup_location): + raise BuildInterruptingException( + "Could not find Setup.dist or Setup in Python build") shprint(sh.make, '-j', str(cpu_count()), '-C', build_dir) diff --git a/pythonforandroid/recipes/hostpython3/__init__.py b/pythonforandroid/recipes/hostpython3/__init__.py index a23f0b9fa2..3068b85da4 100644 --- a/pythonforandroid/recipes/hostpython3/__init__.py +++ b/pythonforandroid/recipes/hostpython3/__init__.py @@ -9,7 +9,7 @@ class Hostpython3Recipe(HostPythonRecipe): Refactored into the new class :class:`~pythonforandroid.python.HostPythonRecipe` ''' - version = '3.7.1' + version = '3.8.1' name = 'hostpython3' conflicts = ['hostpython2'] diff --git a/pythonforandroid/recipes/python3/__init__.py b/pythonforandroid/recipes/python3/__init__.py index 57765b642d..b5254a8e1b 100644 --- a/pythonforandroid/recipes/python3/__init__.py +++ b/pythonforandroid/recipes/python3/__init__.py @@ -18,14 +18,17 @@ class Python3Recipe(GuestPythonRecipe): :class:`~pythonforandroid.python.GuestPythonRecipe` ''' - version = '3.7.1' + version = '3.8.1' url = 'https://www.python.org/ftp/python/{version}/Python-{version}.tgz' name = 'python3' - patches = ['patches/fix-ctypes-util-find-library.patch', - 'patches/fix-zlib-version.patch'] + # patches = ['patches/fix-ctypes-util-find-library.patch', + # 'patches/fix-zlib-version.patch'] + + patches = ['patches/py381.patch'] if sh.which('lld') is not None: + raise RuntimeError("!!!") patches = patches + ["patches/remove-fix-cortex-a8.patch"] depends = ['hostpython3', 'sqlite3', 'openssl', 'libffi'] From d2714dff96b57c68dcfb1f6285333fbd6d044120 Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Tue, 11 Feb 2020 22:11:08 +0000 Subject: [PATCH 2/8] Added python 3.8.1 patch to git --- .../recipes/python3/patches/py381.patch | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 pythonforandroid/recipes/python3/patches/py381.patch diff --git a/pythonforandroid/recipes/python3/patches/py381.patch b/pythonforandroid/recipes/python3/patches/py381.patch new file mode 100644 index 0000000000..60188057a8 --- /dev/null +++ b/pythonforandroid/recipes/python3/patches/py381.patch @@ -0,0 +1,42 @@ +diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py +index 97973bc..053c231 100644 +--- a/Lib/ctypes/util.py ++++ b/Lib/ctypes/util.py +@@ -67,6 +67,13 @@ if os.name == "nt": + return fname + return None + ++# This patch overrides the find_library to look in the right places on ++# Android ++if True: ++ from android._ctypes_library_finder import find_library as _find_lib ++ def find_library(name): ++ return _find_lib(name) ++ + elif os.name == "posix" and sys.platform == "darwin": + from ctypes.macholib.dyld import dyld_find as _dyld_find + def find_library(name): +diff --git a/configure b/configure +index 0914e24..dd00812 100755 +--- a/configure ++++ b/configure +@@ -18673,4 +18673,3 @@ if test "$Py_OPT" = 'false' -a "$Py_DEBUG" != 'true'; then + echo "" >&6 + echo "" >&6 + fi +- +diff --git a/setup.py b/setup.py +index 20d7f35..af15cc2 100644 +--- a/setup.py ++++ b/setup.py +@@ -1501,7 +1501,9 @@ class PyBuildExt(build_ext): + if zlib_inc is not None: + zlib_h = zlib_inc[0] + '/zlib.h' + version = '"0.0.0"' +- version_req = '"1.1.3"' ++ # version_req = '"1.1.3"' ++ version_req = '"{}"'.format( ++ os.environ.get('ZLIB_VERSION', '1.1.3')) + if MACOS and is_macosx_sdk_path(zlib_h): + zlib_h = os.path.join(macosx_sdk_root(), zlib_h[1:]) + with open(zlib_h) as fp: From d7e9d9d6a21aa5a357ed3ba71c64028c90b0425f Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Tue, 11 Feb 2020 22:11:41 +0000 Subject: [PATCH 3/8] Added infrastructure for recipe-version-dependent patching --- pythonforandroid/patching.py | 13 +++++++++++++ pythonforandroid/recipes/python3/__init__.py | 11 ++++++++--- pythonforandroid/recommendations.py | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/pythonforandroid/patching.py b/pythonforandroid/patching.py index 2a4773327d..25430c40d8 100644 --- a/pythonforandroid/patching.py +++ b/pythonforandroid/patching.py @@ -1,4 +1,5 @@ from os import uname +from distutils.version import LooseVersion def check_all(*callables): @@ -69,3 +70,15 @@ def is_ndk(ndk): def is_x(recipe, **kwargs): return recipe.ctx.ndk == ndk return is_x + +def is_version_gt(version): + def is_x(recipe, **kwargs): + return LooseVersion(recipe.version) > version + +def is_version_gt(version): + def is_x(recipe, **kwargs): + return LooseVersion(recipe.version) < version + +def version_starts_with(version): + def is_x(recipe, **kwargs): + return recipe.version.startswith(version) diff --git a/pythonforandroid/recipes/python3/__init__.py b/pythonforandroid/recipes/python3/__init__.py index b5254a8e1b..1c2a533d3d 100644 --- a/pythonforandroid/recipes/python3/__init__.py +++ b/pythonforandroid/recipes/python3/__init__.py @@ -1,6 +1,7 @@ import sh from pythonforandroid.python import GuestPythonRecipe from pythonforandroid.recipe import Recipe +from pythonforandroid.patching import version_starts_with class Python3Recipe(GuestPythonRecipe): @@ -22,10 +23,14 @@ class Python3Recipe(GuestPythonRecipe): url = 'https://www.python.org/ftp/python/{version}/Python-{version}.tgz' name = 'python3' - # patches = ['patches/fix-ctypes-util-find-library.patch', - # 'patches/fix-zlib-version.patch'] + patches = [ + # Python 3.7.1 + ('patches/fix-ctypes-util-find-library.patch', version_starts_with("3.7")), + ('patches/fix-zlib-version.patch', version_starts_with("3.7")) - patches = ['patches/py381.patch'] + # Python 3.8.1 + ('patches/py381.patch', version_starts_with("3.8")) + ] if sh.which('lld') is not None: raise RuntimeError("!!!") diff --git a/pythonforandroid/recommendations.py b/pythonforandroid/recommendations.py index a4a0531558..a7ae359289 100644 --- a/pythonforandroid/recommendations.py +++ b/pythonforandroid/recommendations.py @@ -187,7 +187,7 @@ def check_ndk_api(ndk_api, android_api): MIN_PYTHON_MAJOR_VERSION = 3 -MIN_PYTHON_MINOR_VERSION = 4 +MIN_PYTHON_MINOR_VERSION = 6 MIN_PYTHON_VERSION = LooseVersion('{major}.{minor}'.format(major=MIN_PYTHON_MAJOR_VERSION, minor=MIN_PYTHON_MINOR_VERSION)) PY2_ERROR_TEXT = ( From 61fcf110c1e1187962dd146285d9b86f7efe3211 Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Wed, 12 Feb 2020 22:04:01 +0000 Subject: [PATCH 4/8] Added --fix-cortex-a8 removal patch for py3.8.1 --- .../python3/patches/py381_fix_cortex_a8.patch | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 pythonforandroid/recipes/python3/patches/py381_fix_cortex_a8.patch diff --git a/pythonforandroid/recipes/python3/patches/py381_fix_cortex_a8.patch b/pythonforandroid/recipes/python3/patches/py381_fix_cortex_a8.patch new file mode 100644 index 0000000000..2f8467a6f1 --- /dev/null +++ b/pythonforandroid/recipes/python3/patches/py381_fix_cortex_a8.patch @@ -0,0 +1,18 @@ +diff --git a/configure b/configure +index 0914e24..7517168 100755 +--- a/configure ++++ b/configure +@@ -5642,7 +5642,7 @@ $as_echo_n "checking for the Android arm ABI... " >&6; } + $as_echo "$_arm_arch" >&6; } + if test "$_arm_arch" = 7; then + BASECFLAGS="${BASECFLAGS} -mfloat-abi=softfp -mfpu=vfpv3-d16" +- LDFLAGS="${LDFLAGS} -march=armv7-a -Wl,--fix-cortex-a8" ++ LDFLAGS="${LDFLAGS} -march=armv7-a" + fi + else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: not Android" >&5 +@@ -18673,4 +18673,3 @@ if test "$Py_OPT" = 'false' -a "$Py_DEBUG" != 'true'; then + echo "" >&6 + echo "" >&6 + fi +- From bc292d45a26ed56e2740df35dc4666574a2adcfc Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Wed, 12 Feb 2020 22:09:28 +0000 Subject: [PATCH 5/8] Fully set up Python3 patches to work with both 3.7.1 and 3.8.1 --- pythonforandroid/recipes/python3/__init__.py | 12 +++++++----- ...ch => py3.7.1_fix-ctypes-util-find-library.patch} | 0 ...-version.patch => py3.7.1_fix-zlib-version.patch} | 0 ...x-cortex-a8.patch => py3.7.1_fix_cortex_a8.patch} | 0 .../python3/patches/{py381.patch => py3.8.1.patch} | 0 ...x_cortex_a8.patch => py3.8.1_fix_cortex_a8.patch} | 0 6 files changed, 7 insertions(+), 5 deletions(-) rename pythonforandroid/recipes/python3/patches/{fix-ctypes-util-find-library.patch => py3.7.1_fix-ctypes-util-find-library.patch} (100%) rename pythonforandroid/recipes/python3/patches/{fix-zlib-version.patch => py3.7.1_fix-zlib-version.patch} (100%) rename pythonforandroid/recipes/python3/patches/{remove-fix-cortex-a8.patch => py3.7.1_fix_cortex_a8.patch} (100%) rename pythonforandroid/recipes/python3/patches/{py381.patch => py3.8.1.patch} (100%) rename pythonforandroid/recipes/python3/patches/{py381_fix_cortex_a8.patch => py3.8.1_fix_cortex_a8.patch} (100%) diff --git a/pythonforandroid/recipes/python3/__init__.py b/pythonforandroid/recipes/python3/__init__.py index 1c2a533d3d..a43aee74af 100644 --- a/pythonforandroid/recipes/python3/__init__.py +++ b/pythonforandroid/recipes/python3/__init__.py @@ -25,16 +25,18 @@ class Python3Recipe(GuestPythonRecipe): patches = [ # Python 3.7.1 - ('patches/fix-ctypes-util-find-library.patch', version_starts_with("3.7")), - ('patches/fix-zlib-version.patch', version_starts_with("3.7")) + ('patches/py3.7.1_fix-ctypes-util-find-library.patch', version_starts_with("3.7")), + ('patches/py3.7.1_fix-zlib-version.patch', version_starts_with("3.7")) # Python 3.8.1 - ('patches/py381.patch', version_starts_with("3.8")) + ('patches/py3.8.1.patch', version_starts_with("3.8")) ] if sh.which('lld') is not None: - raise RuntimeError("!!!") - patches = patches + ["patches/remove-fix-cortex-a8.patch"] + patches = patches + [ + ("patches/py3.7.1_remove-fix-cortex-a8.patch", version_starts_with("3.7")), + ("patches/py3.8.1_remove-fix-cortex-a8.patch", version_starts_with("3.8")) + ] depends = ['hostpython3', 'sqlite3', 'openssl', 'libffi'] conflicts = ['python2'] diff --git a/pythonforandroid/recipes/python3/patches/fix-ctypes-util-find-library.patch b/pythonforandroid/recipes/python3/patches/py3.7.1_fix-ctypes-util-find-library.patch similarity index 100% rename from pythonforandroid/recipes/python3/patches/fix-ctypes-util-find-library.patch rename to pythonforandroid/recipes/python3/patches/py3.7.1_fix-ctypes-util-find-library.patch diff --git a/pythonforandroid/recipes/python3/patches/fix-zlib-version.patch b/pythonforandroid/recipes/python3/patches/py3.7.1_fix-zlib-version.patch similarity index 100% rename from pythonforandroid/recipes/python3/patches/fix-zlib-version.patch rename to pythonforandroid/recipes/python3/patches/py3.7.1_fix-zlib-version.patch diff --git a/pythonforandroid/recipes/python3/patches/remove-fix-cortex-a8.patch b/pythonforandroid/recipes/python3/patches/py3.7.1_fix_cortex_a8.patch similarity index 100% rename from pythonforandroid/recipes/python3/patches/remove-fix-cortex-a8.patch rename to pythonforandroid/recipes/python3/patches/py3.7.1_fix_cortex_a8.patch diff --git a/pythonforandroid/recipes/python3/patches/py381.patch b/pythonforandroid/recipes/python3/patches/py3.8.1.patch similarity index 100% rename from pythonforandroid/recipes/python3/patches/py381.patch rename to pythonforandroid/recipes/python3/patches/py3.8.1.patch diff --git a/pythonforandroid/recipes/python3/patches/py381_fix_cortex_a8.patch b/pythonforandroid/recipes/python3/patches/py3.8.1_fix_cortex_a8.patch similarity index 100% rename from pythonforandroid/recipes/python3/patches/py381_fix_cortex_a8.patch rename to pythonforandroid/recipes/python3/patches/py3.8.1_fix_cortex_a8.patch From 4e180eef8a97a82bb8fa0bf56690ef36bfdb2c6e Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Thu, 13 Feb 2020 21:30:04 +0000 Subject: [PATCH 6/8] Fixed bugs in is_version_{lt,gt} patching helpers --- pythonforandroid/patching.py | 4 +++- pythonforandroid/recipes/python3/__init__.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pythonforandroid/patching.py b/pythonforandroid/patching.py index 25430c40d8..8e84543200 100644 --- a/pythonforandroid/patching.py +++ b/pythonforandroid/patching.py @@ -75,10 +75,12 @@ def is_version_gt(version): def is_x(recipe, **kwargs): return LooseVersion(recipe.version) > version -def is_version_gt(version): +def is_version_lt(version): def is_x(recipe, **kwargs): return LooseVersion(recipe.version) < version + return is_x def version_starts_with(version): def is_x(recipe, **kwargs): return recipe.version.startswith(version) + return is_x diff --git a/pythonforandroid/recipes/python3/__init__.py b/pythonforandroid/recipes/python3/__init__.py index a43aee74af..0dd5c35f57 100644 --- a/pythonforandroid/recipes/python3/__init__.py +++ b/pythonforandroid/recipes/python3/__init__.py @@ -26,7 +26,7 @@ class Python3Recipe(GuestPythonRecipe): patches = [ # Python 3.7.1 ('patches/py3.7.1_fix-ctypes-util-find-library.patch', version_starts_with("3.7")), - ('patches/py3.7.1_fix-zlib-version.patch', version_starts_with("3.7")) + ('patches/py3.7.1_fix-zlib-version.patch', version_starts_with("3.7")), # Python 3.8.1 ('patches/py3.8.1.patch', version_starts_with("3.8")) From b3e7676e805896b2a6eed0b241edfb86d4514e99 Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Sun, 16 Feb 2020 15:34:46 +0000 Subject: [PATCH 7/8] Replaced func call with pre-existing variable reference --- pythonforandroid/python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonforandroid/python.py b/pythonforandroid/python.py index aa34aaf76f..d2235b5679 100755 --- a/pythonforandroid/python.py +++ b/pythonforandroid/python.py @@ -443,7 +443,7 @@ def build_arch(self, arch): # after this the file with default options is already named "Setup" setup_dist_location = join('Modules', 'Setup.dist') if exists(setup_dist_location): - shprint(sh.cp, join('Modules', 'Setup.dist'), + shprint(sh.cp, setup_dist_location, join(build_dir, 'Modules', 'Setup')) else: # Check the expected file does exist From 7fcf06b008347b03e93228fc0bd0d843169e9fce Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Sun, 16 Feb 2020 15:38:16 +0000 Subject: [PATCH 8/8] Added some blank lines to make pep8 happy --- pythonforandroid/patching.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pythonforandroid/patching.py b/pythonforandroid/patching.py index 8e84543200..96a3b273bb 100644 --- a/pythonforandroid/patching.py +++ b/pythonforandroid/patching.py @@ -71,15 +71,18 @@ def is_x(recipe, **kwargs): return recipe.ctx.ndk == ndk return is_x + def is_version_gt(version): def is_x(recipe, **kwargs): return LooseVersion(recipe.version) > version + def is_version_lt(version): def is_x(recipe, **kwargs): return LooseVersion(recipe.version) < version return is_x + def version_starts_with(version): def is_x(recipe, **kwargs): return recipe.version.startswith(version)