Skip to content

Commit b7c61ea

Browse files
committed
kivy: fix build
1 parent 4879d33 commit b7c61ea

File tree

8 files changed

+32
-101
lines changed

8 files changed

+32
-101
lines changed

pythonforandroid/build.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def setup_dirs(self, storage_dir):
150150
self.build_dir = join(self.storage_dir, 'build')
151151
self.dist_dir = join(self.storage_dir, 'dists')
152152
self.prebuilt_dir = join(self.storage_dir, 'output')
153+
self.ensure_dirs()
153154

154155
def ensure_dirs(self):
155156
ensure_dir(self.storage_dir)
@@ -226,8 +227,6 @@ def prepare_build_environment(self,
226227
227228
'''
228229

229-
self.ensure_dirs()
230-
231230
if self._build_env_prepared:
232231
return
233232

pythonforandroid/recipe.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ def unpack(self, arch):
516516
for entry in listdir(extraction_filename):
517517
# Previously we filtered out the .git folder, but during the build process for some recipes
518518
# (e.g. when version is parsed by `setuptools_scm`) that may be needed.
519-
shprint(sh.cp, '-Rv',
519+
shprint(sh.cp, '-R',
520520
join(extraction_filename, entry),
521521
directory_name)
522522
else:
@@ -1048,8 +1048,9 @@ def install_hostpython_prerequisites(self, packages=None, force_upgrade=True, ar
10481048
]
10491049
if force_upgrade:
10501050
pip_options.append("--upgrade")
1051-
# Use system's pip
1052-
shprint(sh.Command(self.real_hostpython_location), "-m", "pip", *pip_options, _env=self.get_hostrecipe_env())
1051+
pip_env = self.get_hostrecipe_env()
1052+
pip_env["HOME"] = "?"
1053+
shprint(sh.Command(self.real_hostpython_location), "-m", "pip", *pip_options, _env=pip_env)
10531054

10541055
def restore_hostpython_prerequisites(self, packages):
10551056
_packages = []

pythonforandroid/recipebuild.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@ class RecipeBuilder:
1717
def __init__(self, parsed_args):
1818
setup_color(True)
1919
self.build_dir = parsed_args.workdir
20-
self.init_context()
21-
self.build_recipes(set(parsed_args.recipes + DEFAULT_RECIPES), set(parsed_args.arch))
20+
self.init_context(parsed_args)
21+
self.build_recipes(
22+
set(parsed_args.recipes + DEFAULT_RECIPES),
23+
set(parsed_args.arch)
24+
)
2225

23-
def init_context(self):
26+
def init_context(self, parse_args):
2427
self.ctx = Context()
2528
self.ctx.save_prebuilt = True
2629
self.ctx.setup_dirs(self.build_dir)
27-
self.ctx.ndk_api = 24
28-
self.ctx.android_api = 24
30+
self.ctx.ndk_api = parse_args.min_api
31+
self.ctx.android_api = parse_args.target_api
2932
self.ctx.ndk_dir = "/home/tdynamos/.buildozer/android/platform/android-ndk-r25b"
3033

3134
def build_recipes(self, recipes, archs):
@@ -70,11 +73,11 @@ def build_recipes(self, recipes, archs):
7073
info("{} said it is already built, skipping".format(recipe.name))
7174
recipe.install_libraries(arch)
7275

73-
# input()
74-
7576
if __name__ == "__main__":
7677
parser = ArgumentParser(description="Build and package recipes.")
7778
parser.add_argument('-r', '--recipes', nargs='+', help='Recipes to build.', required=True)
7879
parser.add_argument('-a', '--arch', nargs='+', help='Android arch(s) to build.', required=True)
7980
parser.add_argument('-w', '--workdir', type=str, help="Workdir for building recipes.", required=True)
81+
parser.add_argument('-m', '--min-api', type=int, help="Android ndk (minimum) api.", default=24)
82+
parser.add_argument('-t', '--target-api', type=int, help="Android target api.", default=24)
8083
RecipeBuilder(parser.parse_args())

pythonforandroid/recipes/genericndkbuild/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from os.path import join
2-
2+
from multiprocessing import cpu_count
33
from pythonforandroid.recipe import BootstrapNDKRecipe
44
from pythonforandroid.toolchain import current_directory, shprint
55
import sh
@@ -29,7 +29,7 @@ def build_arch(self, arch):
2929
env = self.get_recipe_env(arch)
3030

3131
with current_directory(self.get_jni_dir()):
32-
shprint(sh.Command(join(self.ctx.ndk_dir, "ndk-build")), "V=1", _env=env)
32+
shprint(sh.Command(join(self.ctx.ndk_dir, "ndk-build")), "V=1", "-j", str(cpu_count()), _env=env)
3333

3434

3535
recipe = GenericNDKBuildRecipe()

pythonforandroid/recipes/hostpython3/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ def build_arch(self, arch):
159159

160160
ensure_dir(self.site_root)
161161
self.ctx.hostpython = self.python_exe
162-
shprint(sh.Command(self.python_exe), "-m", "ensurepip", "--root", self.site_root, "-U")
163-
162+
shprint(
163+
sh.Command(self.python_exe), "-m", "ensurepip", "--root", self.site_root, "-U",
164+
_env={"HOME":"?"} # need to hack HOME a bit
165+
)
164166

165167
recipe = HostPython3Recipe()

pythonforandroid/recipes/kivy/__init__.py

+10-52
Original file line numberDiff line numberDiff line change
@@ -4,67 +4,25 @@
44
import packaging.version
55

66
import sh
7-
from pythonforandroid.recipe import CythonRecipe
7+
from pythonforandroid.recipe import PyProjectRecipe
88
from pythonforandroid.toolchain import current_directory, shprint
99

1010

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):
25-
version = '2.3.0'
11+
class KivyRecipe(PyProjectRecipe):
12+
version = 'master'
2613
url = 'https://github.com/kivy/kivy/archive/{version}.zip'
27-
name = 'kivy'
28-
29-
depends = ['sdl2', 'pyjnius', 'setuptools']
14+
depends = ['sdl2', 'pyjnius']
3015
python_depends = ['certifi', 'chardet', 'idna', 'requests', 'urllib3']
31-
32-
# sdl-gl-swapwindow-nogil.patch is needed to avoid a deadlock.
33-
# See: https://github.com/kivy/kivy/pull/8025
34-
# WARNING: Remove this patch when a new Kivy version is released.
35-
patches = [("sdl-gl-swapwindow-nogil.patch", is_kivy_affected_by_deadlock_issue)]
36-
37-
def cythonize_build(self, env, build_dir='.'):
38-
super().cythonize_build(env, build_dir=build_dir)
39-
40-
if not exists(join(build_dir, 'kivy', 'include')):
41-
return
42-
43-
# If kivy is new enough to use the include dir, copy it
44-
# manually to the right location as we bypass this stage of
45-
# the build
46-
with current_directory(build_dir):
47-
build_libs_dirs = glob.glob(join('build', 'lib.*'))
48-
49-
for dirn in build_libs_dirs:
50-
shprint(sh.cp, '-r', join('kivy', 'include'),
51-
join(dirn, 'kivy'))
52-
53-
def cythonize_file(self, env, build_dir, filename):
54-
# We can ignore a few files that aren't important to the
55-
# android build, and may not work on Android anyway
56-
do_not_cythonize = ['window_x11.pyx', ]
57-
if basename(filename) in do_not_cythonize:
58-
return
59-
super().cythonize_file(env, build_dir, filename)
60-
61-
def get_recipe_env(self, arch):
62-
env = super().get_recipe_env(arch)
16+
17+
def get_recipe_env(self, arch, **kwargs):
18+
env = super().get_recipe_env(arch, **kwargs)
6319
# NDKPLATFORM is our switch for detecting Android platform, so can't be None
6420
env['NDKPLATFORM'] = "NOTNONE"
21+
env['LIBLINK'] = "NOTNONE"
6522
if 'sdl2' in self.ctx.recipe_build_order:
6623
env['USE_SDL2'] = '1'
6724
env['KIVY_SPLIT_EXAMPLES'] = '1'
25+
sdl_recipe = self.get_recipe("sdl2", self.ctx)
6826
sdl2_mixer_recipe = self.get_recipe('sdl2_mixer', self.ctx)
6927
sdl2_image_recipe = self.get_recipe('sdl2_image', self.ctx)
7028
env['KIVY_SDL2_PATH'] = ':'.join([
@@ -73,7 +31,7 @@ def get_recipe_env(self, arch):
7331
*sdl2_mixer_recipe.get_include_dirs(arch),
7432
join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'),
7533
])
76-
34+
env["LDFLAGS"] += " -L" + join(sdl_recipe.get_build_dir(arch.arch), "../..", "libs", arch.arch)
7735
return env
7836

7937

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

-32
This file was deleted.

pythonforandroid/recipes/python3/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def add_flags(include_flags, link_dirs, link_libs):
309309
)
310310
env['ZLIB_VERSION'] = line.replace('#define ZLIB_VERSION ', '')
311311
add_flags(' -I' + zlib_includes, ' -L' + zlib_lib_path, ' -lz')
312-
312+
313313
return env
314314

315315
def build_arch(self, arch):

0 commit comments

Comments
 (0)