Skip to content

Commit 3dadccc

Browse files
committed
kivy and pyjnius: switch to PyProjectRecipe
1 parent 58d148b commit 3dadccc

File tree

9 files changed

+108
-96
lines changed

9 files changed

+108
-96
lines changed

ci/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class TargetPython(Enum):
1919
# requires `libpq-dev` system dependency e.g. for `pg_config` binary
2020
'psycopg2',
2121
# most likely some setup in the Docker container, because it works in host
22-
'pyjnius', 'pyopenal',
22+
'pyopenal',
2323
# SyntaxError: invalid syntax (Python2)
2424
'storm',
2525
# mpmath package with a version >= 0.19 required

pythonforandroid/recipes/kivy/__init__.py

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,30 @@
1-
import glob
2-
from os.path import basename, exists, join
3-
import sys
4-
import packaging.version
1+
from os.path import join
2+
from pythonforandroid.recipe import PyProjectRecipe
53

6-
import sh
7-
from pythonforandroid.recipe import CythonRecipe
8-
from pythonforandroid.toolchain import current_directory, shprint
94

10-
11-
def is_kivy_affected_by_deadlock_issue(recipe=None, arch=None):
12-
with current_directory(join(recipe.get_build_dir(arch.arch), "kivy")):
13-
kivy_version = shprint(
14-
sh.Command(sys.executable),
15-
"-c",
16-
"import _version; print(_version.__version__)",
17-
)
18-
19-
return packaging.version.parse(
20-
str(kivy_version)
21-
) < packaging.version.Version("2.2.0.dev0")
22-
23-
24-
class KivyRecipe(CythonRecipe):
5+
class KivyRecipe(PyProjectRecipe):
256
version = '2.3.1'
267
url = 'https://github.com/kivy/kivy/archive/{version}.zip'
8+
<<<<<<< HEAD
279
name = 'kivy'
2810

2911
depends = [('sdl2', 'sdl3'), 'pyjnius', 'setuptools']
12+
||||||| parent of e3538b5 (`kivy` and `pyjnius`: switch to `PyProjectRecipe`)
13+
name = 'kivy'
14+
15+
depends = ['sdl2', 'pyjnius', 'setuptools']
16+
=======
17+
depends = ['sdl2', 'pyjnius']
18+
>>>>>>> e3538b5 (`kivy` and `pyjnius`: switch to `PyProjectRecipe`)
3019
python_depends = ['certifi', 'chardet', 'idna', 'requests', 'urllib3', 'filetype']
20+
<<<<<<< HEAD
3121
hostpython_prerequisites = []
22+
||||||| parent of e3538b5 (`kivy` and `pyjnius`: switch to `PyProjectRecipe`)
23+
=======
24+
patches = ["use_cython.patch"]
25+
>>>>>>> e3538b5 (`kivy` and `pyjnius`: switch to `PyProjectRecipe`)
3226

27+
<<<<<<< HEAD
3328
# sdl-gl-swapwindow-nogil.patch is needed to avoid a deadlock.
3429
# See: https://github.com/kivy/kivy/pull/8025
3530
# WARNING: Remove this patch when a new Kivy version is released.
@@ -61,11 +56,49 @@ def cythonize_file(self, env, build_dir, filename):
6156

6257
def get_recipe_env(self, arch):
6358
env = super().get_recipe_env(arch)
59+
||||||| parent of e3538b5 (`kivy` and `pyjnius`: switch to `PyProjectRecipe`)
60+
# sdl-gl-swapwindow-nogil.patch is needed to avoid a deadlock.
61+
# See: https://github.com/kivy/kivy/pull/8025
62+
# WARNING: Remove this patch when a new Kivy version is released.
63+
patches = [("sdl-gl-swapwindow-nogil.patch", is_kivy_affected_by_deadlock_issue)]
64+
65+
def cythonize_build(self, env, build_dir='.'):
66+
super().cythonize_build(env, build_dir=build_dir)
67+
68+
if not exists(join(build_dir, 'kivy', 'include')):
69+
return
70+
71+
# If kivy is new enough to use the include dir, copy it
72+
# manually to the right location as we bypass this stage of
73+
# the build
74+
with current_directory(build_dir):
75+
build_libs_dirs = glob.glob(join('build', 'lib.*'))
76+
77+
for dirn in build_libs_dirs:
78+
shprint(sh.cp, '-r', join('kivy', 'include'),
79+
join(dirn, 'kivy'))
80+
81+
def cythonize_file(self, env, build_dir, filename):
82+
# We can ignore a few files that aren't important to the
83+
# android build, and may not work on Android anyway
84+
do_not_cythonize = ['window_x11.pyx', ]
85+
if basename(filename) in do_not_cythonize:
86+
return
87+
super().cythonize_file(env, build_dir, filename)
88+
89+
def get_recipe_env(self, arch):
90+
env = super().get_recipe_env(arch)
91+
=======
92+
def get_recipe_env(self, arch, **kwargs):
93+
env = super().get_recipe_env(arch, **kwargs)
94+
>>>>>>> e3538b5 (`kivy` and `pyjnius`: switch to `PyProjectRecipe`)
6495
# NDKPLATFORM is our switch for detecting Android platform, so can't be None
6596
env['NDKPLATFORM'] = "NOTNONE"
97+
env['LIBLINK'] = "NOTNONE"
6698
if 'sdl2' in self.ctx.recipe_build_order:
6799
env['USE_SDL2'] = '1'
68100
env['KIVY_SPLIT_EXAMPLES'] = '1'
101+
sdl_recipe = self.get_recipe("sdl2", self.ctx)
69102
sdl2_mixer_recipe = self.get_recipe('sdl2_mixer', self.ctx)
70103
sdl2_image_recipe = self.get_recipe('sdl2_image', self.ctx)
71104
env['KIVY_SDL2_PATH'] = ':'.join([
@@ -74,6 +107,7 @@ def get_recipe_env(self, arch):
74107
*sdl2_mixer_recipe.get_include_dirs(arch),
75108
join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'),
76109
])
110+
<<<<<<< HEAD
77111
if "sdl3" in self.ctx.recipe_build_order:
78112
sdl3_mixer_recipe = self.get_recipe("sdl3_mixer", self.ctx)
79113
sdl3_image_recipe = self.get_recipe("sdl3_image", self.ctx)
@@ -90,6 +124,11 @@ def get_recipe_env(self, arch):
90124
]
91125
)
92126

127+
||||||| parent of e3538b5 (`kivy` and `pyjnius`: switch to `PyProjectRecipe`)
128+
129+
=======
130+
env["LDFLAGS"] += " -L" + join(sdl_recipe.get_build_dir(arch.arch), "../..", "libs", arch.arch)
131+
>>>>>>> e3538b5 (`kivy` and `pyjnius`: switch to `PyProjectRecipe`)
93132
return env
94133

95134

pythonforandroid/recipes/kivy/sdl-gl-swapwindow-nogil.patch

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- kivy-master/setup.py 2025-02-25 03:08:18.000000000 +0530
2+
+++ kivy-master.mod/setup.py 2025-03-01 13:10:24.227808612 +0530
3+
@@ -249,7 +249,7 @@
4+
# This determines whether Cython specific functionality may be used.
5+
can_use_cython = True
6+
7+
-if platform in ('ios', 'android'):
8+
+if platform in ('ios'):
9+
# NEVER use or declare cython on these platforms
10+
print('Not using cython on %s' % platform)
11+
can_use_cython = False

pythonforandroid/recipes/pyjnius/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
1-
from pythonforandroid.recipe import CythonRecipe
1+
from pythonforandroid.recipe import PyProjectRecipe
22
from pythonforandroid.toolchain import shprint, current_directory, info
33
from pythonforandroid.patching import will_build
44
import sh
55
from os.path import join
66

77

8-
class PyjniusRecipe(CythonRecipe):
8+
class PyjniusRecipe(PyProjectRecipe):
99
version = '1.6.1'
1010
url = 'https://github.com/kivy/pyjnius/archive/{version}.zip'
1111
name = 'pyjnius'
1212
depends = [('genericndkbuild', 'sdl2', 'sdl3'), 'six']
1313
site_packages_name = 'jnius'
1414

1515
patches = [
16-
('genericndkbuild_jnienv_getter.patch', will_build('genericndkbuild')),
1716
('sdl3_jnienv_getter.patch', will_build('sdl3')),
17+
"use_cython.patch",
18+
"common.patch",
1819
]
1920

20-
def get_recipe_env(self, arch):
21-
env = super().get_recipe_env(arch)
21+
def get_recipe_env(self, arch, **kwargs):
22+
env = super().get_recipe_env(arch, **kwargs)
2223
# NDKPLATFORM is our switch for detecting Android platform, so can't be None
2324
env['NDKPLATFORM'] = "NOTNONE"
25+
env['LIBLINK'] = "NOTNONE"
26+
env["ANDROID_PYJNIUS_CYTHON_3"] = "1"
27+
sdl_recipe = self.get_recipe("sdl2", self.ctx)
28+
env["LDFLAGS"] += " -L" + join(sdl_recipe.get_build_dir(arch.arch), "../..", "libs", arch.arch)
2429
return env
2530

2631
def postbuild_arch(self, arch):
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff -Naur pyjnius.orig/jnius/jnius_jvm_android.pxi pyjnius/jnius/jnius_jvm_android.pxi
2+
--- pyjnius.orig/jnius/jnius_jvm_android.pxi 2022-05-28 11:16:02.000000000 +0200
3+
+++ pyjnius/jnius/jnius_jvm_android.pxi 2022-05-28 11:17:17.000000000 +0200
4+
@@ -1,6 +1,6 @@
5+
# on android, rely on SDL to get the JNI env
6+
-cdef extern JNIEnv *SDL_AndroidGetJNIEnv()
7+
+cdef extern JNIEnv *SDL_GetAndroidJNIEnv()
8+
9+
10+
cdef JNIEnv *get_platform_jnienv() except NULL:
11+
- return <JNIEnv*>SDL_AndroidGetJNIEnv()
12+
+ return <JNIEnv*>SDL_GetAndroidJNIEnv()

pythonforandroid/recipes/pyjnius/genericndkbuild_jnienv_getter.patch

Lines changed: 0 additions & 24 deletions
This file was deleted.

pythonforandroid/recipes/pyjnius/sdl3_jnienv_getter.patch

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,3 @@ diff -Naur pyjnius.orig/jnius/env.py pyjnius/jnius/env.py
1010

1111
def get_include_dirs(self):
1212
# When cross-compiling for Android, we should not use the include dirs
13-
diff -Naur pyjnius.orig/jnius/jnius_jvm_android.pxi pyjnius/jnius/jnius_jvm_android.pxi
14-
--- pyjnius.orig/jnius/jnius_jvm_android.pxi 2022-05-28 11:16:02.000000000 +0200
15-
+++ pyjnius/jnius/jnius_jvm_android.pxi 2022-05-28 11:17:17.000000000 +0200
16-
@@ -1,6 +1,6 @@
17-
# on android, rely on SDL to get the JNI env
18-
-cdef extern JNIEnv *SDL_AndroidGetJNIEnv()
19-
+cdef extern JNIEnv *SDL_GetAndroidJNIEnv()
20-
21-
22-
cdef JNIEnv *get_platform_jnienv() except NULL:
23-
- return <JNIEnv*>SDL_AndroidGetJNIEnv()
24-
+ return <JNIEnv*>SDL_GetAndroidJNIEnv()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--- pyjnius-1.6.1/setup.py 2023-11-05 21:07:43.000000000 +0530
2+
+++ pyjnius-1.6.1.mod/setup.py 2025-03-01 14:47:11.964847337 +0530
3+
@@ -59,10 +59,6 @@
4+
if NDKPLATFORM is not None and getenv('LIBLINK'):
5+
PLATFORM = 'android'
6+
7+
-# detect platform
8+
-if PLATFORM == 'android':
9+
- PYX_FILES = [fn[:-3] + 'c' for fn in PYX_FILES]
10+
-
11+
JAVA=get_java_setup(PLATFORM)
12+
13+
assert JAVA.is_jdk(), "You need a JDK, we only found a JRE. Try setting JAVA_HOME"

0 commit comments

Comments
 (0)