2022-12-02 21:15:34 +01:00
|
|
|
import glob
|
|
|
|
from os.path import basename, exists, join
|
|
|
|
import sys
|
|
|
|
import packaging.version
|
|
|
|
|
|
|
|
import sh
|
2019-03-30 21:58:45 +01:00
|
|
|
from pythonforandroid.recipe import CythonRecipe
|
|
|
|
from pythonforandroid.toolchain import current_directory, shprint
|
2022-12-02 21:15:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
def is_kivy_affected_by_deadlock_issue(recipe=None, arch=None):
|
|
|
|
with current_directory(join(recipe.get_build_dir(arch.arch), "kivy")):
|
|
|
|
kivy_version = shprint(
|
|
|
|
sh.Command(sys.executable),
|
|
|
|
"-c",
|
|
|
|
"import _version; print(_version.__version__)",
|
|
|
|
)
|
|
|
|
|
|
|
|
return packaging.version.parse(
|
|
|
|
str(kivy_version)
|
|
|
|
) < packaging.version.Version("2.2.0.dev0")
|
2017-08-13 03:24:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
class KivyRecipe(CythonRecipe):
|
2022-12-02 21:15:34 +01:00
|
|
|
version = '2.1.0'
|
2017-08-13 03:24:00 +02:00
|
|
|
url = 'https://github.com/kivy/kivy/archive/{version}.zip'
|
|
|
|
name = 'kivy'
|
|
|
|
|
2022-12-02 21:15:34 +01:00
|
|
|
depends = ['sdl2', 'pyjnius', 'setuptools']
|
|
|
|
python_depends = ['certifi']
|
|
|
|
|
|
|
|
# sdl-gl-swapwindow-nogil.patch is needed to avoid a deadlock.
|
|
|
|
# See: https://github.com/kivy/kivy/pull/8025
|
|
|
|
# WARNING: Remove this patch when a new Kivy version is released.
|
|
|
|
patches = [("sdl-gl-swapwindow-nogil.patch", is_kivy_affected_by_deadlock_issue)]
|
2017-08-13 03:24:00 +02:00
|
|
|
|
|
|
|
def cythonize_build(self, env, build_dir='.'):
|
2022-12-02 21:15:34 +01:00
|
|
|
super().cythonize_build(env, build_dir=build_dir)
|
2017-08-13 03:24:00 +02:00
|
|
|
|
|
|
|
if not exists(join(build_dir, 'kivy', 'include')):
|
|
|
|
return
|
|
|
|
|
|
|
|
# If kivy is new enough to use the include dir, copy it
|
|
|
|
# manually to the right location as we bypass this stage of
|
|
|
|
# the build
|
|
|
|
with current_directory(build_dir):
|
|
|
|
build_libs_dirs = glob.glob(join('build', 'lib.*'))
|
|
|
|
|
|
|
|
for dirn in build_libs_dirs:
|
|
|
|
shprint(sh.cp, '-r', join('kivy', 'include'),
|
|
|
|
join(dirn, 'kivy'))
|
|
|
|
|
2019-03-30 21:58:45 +01:00
|
|
|
def cythonize_file(self, env, build_dir, filename):
|
|
|
|
# We can ignore a few files that aren't important to the
|
|
|
|
# android build, and may not work on Android anyway
|
|
|
|
do_not_cythonize = ['window_x11.pyx', ]
|
|
|
|
if basename(filename) in do_not_cythonize:
|
|
|
|
return
|
2022-12-02 21:15:34 +01:00
|
|
|
super().cythonize_file(env, build_dir, filename)
|
2019-03-30 21:58:45 +01:00
|
|
|
|
2017-08-13 03:24:00 +02:00
|
|
|
def get_recipe_env(self, arch):
|
2022-12-02 21:15:34 +01:00
|
|
|
env = super().get_recipe_env(arch)
|
|
|
|
# NDKPLATFORM is our switch for detecting Android platform, so can't be None
|
|
|
|
env['NDKPLATFORM'] = "NOTNONE"
|
2017-08-13 03:24:00 +02:00
|
|
|
if 'sdl2' in self.ctx.recipe_build_order:
|
|
|
|
env['USE_SDL2'] = '1'
|
|
|
|
env['KIVY_SPLIT_EXAMPLES'] = '1'
|
2022-12-02 21:15:34 +01:00
|
|
|
sdl2_mixer_recipe = self.get_recipe('sdl2_mixer', self.ctx)
|
2017-08-13 03:24:00 +02:00
|
|
|
env['KIVY_SDL2_PATH'] = ':'.join([
|
|
|
|
join(self.ctx.bootstrap.build_dir, 'jni', 'SDL', 'include'),
|
|
|
|
join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_image'),
|
2022-12-02 21:15:34 +01:00
|
|
|
*sdl2_mixer_recipe.get_include_dirs(arch),
|
2017-08-13 03:24:00 +02:00
|
|
|
join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'),
|
2022-12-02 21:15:34 +01:00
|
|
|
])
|
2017-08-13 03:24:00 +02:00
|
|
|
|
|
|
|
return env
|
|
|
|
|
2019-03-30 21:58:45 +01:00
|
|
|
|
2017-08-13 03:24:00 +02:00
|
|
|
recipe = KivyRecipe()
|