Skip to content

Commit d29c7d2

Browse files
committed
Merge pull request kivy#522 from kived/easier-patching
easier patching for recipes
2 parents 2006cad + 1d18540 commit d29c7d2

File tree

13 files changed

+162
-155
lines changed

13 files changed

+162
-155
lines changed

pythonforandroid/patching.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from os import uname
2+
3+
4+
def check_all(*callables):
5+
def check(**kwargs):
6+
return all(c(**kwargs) for c in callables)
7+
return check
8+
9+
10+
def check_any(*callables):
11+
def check(**kwargs):
12+
return any(c(**kwargs) for c in callables)
13+
return check
14+
15+
16+
def is_platform(platform):
17+
def is_x(**kwargs):
18+
return uname()[0] == platform
19+
return is_x
20+
21+
is_linux = is_platform('Linux')
22+
is_darwin = is_platform('Darwin')
23+
24+
25+
def is_arch(xarch):
26+
def is_x(arch, **kwargs):
27+
return arch.arch == xarch
28+
return is_x
29+
30+
31+
def is_api_gt(apiver):
32+
def is_x(recipe, **kwargs):
33+
return recipe.ctx.android_api > apiver
34+
return is_x
35+
36+
37+
def is_api_gte(apiver):
38+
def is_x(recipe, **kwargs):
39+
return recipe.ctx.android_api >= apiver
40+
return is_x
41+
42+
43+
def is_api_lt(apiver):
44+
def is_x(recipe, **kwargs):
45+
return recipe.ctx.android_api < apiver
46+
return is_x
47+
48+
49+
def is_api_lte(apiver):
50+
def is_x(recipe, **kwargs):
51+
return recipe.ctx.android_api <= apiver
52+
return is_x
53+
54+
55+
def is_api(apiver):
56+
def is_x(recipe, **kwargs):
57+
return recipe.ctx.android_api == apiver
58+
return is_x
59+
60+
61+
def will_build(recipe_name):
62+
def will(recipe, **kwargs):
63+
return recipe_name in recipe.ctx.recipe_build_order
64+
return will
65+

pythonforandroid/recipes/kivysdl2python3/__init__.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@ class KivySDL2Recipe(CythonRecipe):
1212
site_packages_name = 'kivy'
1313

1414
depends = ['sdl2', 'python2', 'pyjniussdl2']
15-
16-
def prebuild_arch(self, arch):
17-
super(KivySDL2Recipe, self).prebuild_arch(arch)
18-
build_dir = self.get_build_dir(arch.arch)
19-
if exists(join(build_dir, '.patched')):
20-
print('kivysdl2 already patched, skipping')
21-
return
22-
self.apply_patch('android_sdl2_compat.patch')
23-
shprint(sh.touch, join(build_dir, '.patched'))
15+
patches = ['android_sdl2_compat.patch']
2416

2517
def get_recipe_env(self, arch):
2618
env = super(KivySDL2Recipe, self).get_recipe_env(arch)
Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11

2-
from pythonforandroid.toolchain import CompiledComponentsPythonRecipe, shprint, current_directory, warning
3-
from os.path import exists, join
4-
import sh
5-
import glob
2+
from pythonforandroid.toolchain import CompiledComponentsPythonRecipe, warning
63

74

85
class NumpyRecipe(CompiledComponentsPythonRecipe):
@@ -13,23 +10,17 @@ class NumpyRecipe(CompiledComponentsPythonRecipe):
1310

1411
depends = ['python2']
1512

13+
patches = ['patches/fix-numpy.patch',
14+
'patches/prevent_libs_check.patch',
15+
'patches/ar.patch',
16+
'patches/lib.patch']
17+
1618
def prebuild_arch(self, arch):
1719
super(NumpyRecipe, self).prebuild_arch(arch)
18-
build_dir = self.get_build_dir(arch.arch)
19-
if exists(join(build_dir, '.patched')):
20-
print('numpy already patched, skipping')
21-
return
22-
23-
self.apply_patch('patches/fix-numpy.patch', arch.arch)
24-
self.apply_patch('patches/prevent_libs_check.patch', arch.arch)
25-
self.apply_patch('patches/ar.patch', arch.arch)
26-
self.apply_patch('patches/lib.patch', arch.arch)
2720

2821
# AND: Fix this warning!
2922
warning('Numpy is built assuming the archiver name is '
3023
'arm-linux-androideabi-ar, which may not always be true!')
3124

32-
shprint(sh.touch, join(build_dir, '.patched'))
33-
3425

3526
recipe = NumpyRecipe()

pythonforandroid/recipes/pycrypto/__init__.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,18 @@
66
info,
77
shprint,
88
)
9-
from os.path import exists, join, realpath
9+
from os.path import join
1010
import sh
11-
import glob
1211

1312

1413
class PyCryptoRecipe(CompiledComponentsPythonRecipe):
1514
version = '2.6.1'
1615
url = 'https://pypi.python.org/packages/source/p/pycrypto/pycrypto-{version}.tar.gz'
1716
depends = ['openssl', 'python2']
1817

19-
def prebuild_arch(self, arch):
20-
super(PyCryptoRecipe, self).prebuild_arch(arch)
21-
build_dir = self.get_build_dir(arch.arch)
22-
if exists(join(build_dir, '.patched')):
23-
print('pycrypto already patched, skipping')
24-
return
25-
self.apply_patch('add_length.patch', arch.arch)
26-
shprint(sh.touch, join(build_dir, '.patched'))
18+
patches = ['add_length.patch']
2719

28-
def get_recipe_env(self, arch):
20+
def get_recipe_env(self, arch=None):
2921
env = super(PyCryptoRecipe, self).get_recipe_env(arch)
3022
openssl_build_dir = Recipe.get_recipe('openssl', self.ctx).get_build_dir(arch.arch)
3123
env['CC'] = '%s -I%s' % (env['CC'], join(openssl_build_dir, 'include'))

pythonforandroid/recipes/pygame/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ class PygameRecipe(Recipe):
1212
depends = ['python2', 'sdl']
1313
conflicts = ['sdl2']
1414

15-
def get_recipe_env(self, arch):
15+
patches = ['fix-surface-access.patch',
16+
'fix-array-surface.patch',
17+
'fix-sdl-spam-log.patch']
18+
19+
def get_recipe_env(self, arch=None):
1620
env = super(PygameRecipe, self).get_recipe_env(arch)
1721
env['LDFLAGS'] = env['LDFLAGS'] + ' -L{}'.format(
1822
self.ctx.get_libs_dir(arch.arch))
@@ -27,15 +31,10 @@ def get_recipe_env(self, arch):
2731
return env
2832

2933
def prebuild_arch(self, arch):
30-
if exists(join(self.get_build_container_dir(arch.arch), '.patched')):
31-
info('Pygame already patched, skipping.')
34+
if self.is_patched(arch):
3235
return
3336
shprint(sh.cp, join(self.get_recipe_dir(), 'Setup'),
3437
join(self.get_build_dir(arch.arch), 'Setup'))
35-
self.apply_patch(join('patches', 'fix-surface-access.patch'), arch.arch)
36-
self.apply_patch(join('patches', 'fix-array-surface.patch'), arch.arch)
37-
self.apply_patch(join('patches', 'fix-sdl-spam-log.patch'), arch.arch)
38-
shprint(sh.touch, join(self.get_build_container_dir(arch.arch), '.patched'))
3938

4039
def build_arch(self, arch):
4140
# AND: I'm going to ignore any extra pythonrecipe or cythonrecipe behaviour for now

pythonforandroid/recipes/pyjnius/__init__.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11

2-
from pythonforandroid.toolchain import CythonRecipe, shprint, ArchARM, current_directory, info
2+
from pythonforandroid.toolchain import CythonRecipe, shprint, current_directory, info
3+
from pythonforandroid.patching import will_build
34
import sh
4-
import glob
5-
from os.path import join, exists
5+
from os.path import join
66

77

88
class PyjniusRecipe(CythonRecipe):
9-
version = 'master'
9+
version = 'master'
1010
url = 'https://github.com/kivy/pyjnius/archive/{version}.zip'
1111
name = 'pyjnius'
1212
depends = ['python2', ('sdl2', 'sdl'), 'six']
1313
site_packages_name = 'jnius'
14-
def prebuild_arch(self, arch):
15-
super(PyjniusRecipe, self).prebuild_arch(arch)
16-
if 'sdl2' in self.ctx.recipe_build_order:
17-
build_dir = self.get_build_dir(arch.arch)
18-
if exists(join(build_dir, '.patched')):
19-
print('pyjniussdl2 already pathed, skipping')
20-
return
21-
self.apply_patch('sdl2_jnienv_getter.patch', arch.arch)
22-
shprint(sh.touch, join(build_dir, '.patched'))
14+
15+
patches = [('sdl2_jnienv_getter.patch', will_build('sdl2')]
2316

2417
def postbuild_arch(self, arch):
2518
super(PyjniusRecipe, self).postbuild_arch(arch)

pythonforandroid/recipes/python2/__init__.py

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11

2-
from pythonforandroid.toolchain import Recipe, shprint, get_directory, current_directory, ArchARM, info
2+
from pythonforandroid.toolchain import Recipe, shprint, current_directory, info
3+
from pythonforandroid.patching import is_linux, is_darwin, is_api_gt
34
from os.path import exists, join, realpath
4-
from os import uname
5-
import glob
65
import sh
76

87

@@ -14,39 +13,25 @@ class Python2Recipe(Recipe):
1413
depends = ['hostpython2']
1514
conflicts = ['python3']
1615
opt_depends = ['openssl']
17-
18-
def prebuild_arch(self, arch):
19-
build_dir = self.get_build_container_dir(arch.arch)
20-
if exists(join(build_dir, '.patched')):
21-
info('Python2 already patched, skipping.')
22-
return
23-
self.apply_patch(join('patches', 'Python-{}-xcompile.patch'.format(self.version)),
24-
arch.arch)
25-
self.apply_patch(join('patches', 'Python-{}-ctypes-disable-wchar.patch'.format(self.version)),
26-
arch.arch)
27-
self.apply_patch(join('patches', 'disable-modules.patch'), arch.arch)
28-
self.apply_patch(join('patches', 'fix-locale.patch'), arch.arch)
29-
self.apply_patch(join('patches', 'fix-gethostbyaddr.patch'), arch.arch)
30-
self.apply_patch(join('patches', 'fix-setup-flags.patch'), arch.arch)
31-
self.apply_patch(join('patches', 'fix-filesystemdefaultencoding.patch'), arch.arch)
32-
self.apply_patch(join('patches', 'fix-termios.patch'), arch.arch)
33-
self.apply_patch(join('patches', 'custom-loader.patch'), arch.arch)
34-
self.apply_patch(join('patches', 'verbose-compilation.patch'), arch.arch)
35-
self.apply_patch(join('patches', 'fix-remove-corefoundation.patch'), arch.arch)
36-
self.apply_patch(join('patches', 'fix-dynamic-lookup.patch'), arch.arch)
37-
self.apply_patch(join('patches', 'fix-dlfcn.patch'), arch.arch)
38-
self.apply_patch(join('patches', 'parsetuple.patch'), arch.arch)
39-
# self.apply_patch(join('patches', 'ctypes-find-library.patch'), arch.arch)
40-
self.apply_patch(join('patches', 'ctypes-find-library-updated.patch'), arch.arch)
41-
42-
if uname()[0] == 'Linux':
43-
self.apply_patch(join('patches', 'fix-configure-darwin.patch'), arch.arch)
44-
self.apply_patch(join('patches', 'fix-distutils-darwin.patch'), arch.arch)
45-
46-
if self.ctx.android_api > 19:
47-
self.apply_patch(join('patches', 'fix-ftime-removal.patch'), arch.arch)
48-
49-
shprint(sh.touch, join(build_dir, '.patched'))
16+
17+
patches = ['patches/Python-{version}-xcompile.patch',
18+
'patches/Python-{version}-ctypes-disable-wchar.patch',
19+
'patches/disable-modules.patch',
20+
'patches/fix-locale.patch',
21+
'patches/fix-gethostbyaddr.patch',
22+
'patches/fix-setup-flags.patch',
23+
'patches/fix-filesystemdefaultencoding.patch',
24+
'patches/fix-termios.patch',
25+
'patches/custom-loader.patch',
26+
'patches/verbose-compilation.patch',
27+
'patches/fix-remove-corefoundation.patch',
28+
'patches/fix-dynamic-lookup.patch',
29+
'patches/fix-dlfcn.patch',
30+
'patches/parsetuple.patch',
31+
'patches/ctypes-find-library-updated.patch',
32+
('patches/fix-configure-darwin.patch', is_linux),
33+
('patches/fix-distutils-darwin.patch', is_linux),
34+
('patches/fix-ftime-removal.patch', is_api_gt(19))]
5035

5136
def build_arch(self, arch):
5237

@@ -151,7 +136,7 @@ def do_python_build(self, arch):
151136
'INSTSONAME=libpython2.7.so',
152137
_env=env)
153138

154-
if uname()[0] == 'Darwin':
139+
if is_darwin():
155140
shprint(sh.cp, join(self.get_recipe_dir(), 'patches', '_scproxy.py'),
156141
join('python-install', 'Lib'))
157142
shprint(sh.cp, join(self.get_recipe_dir(), 'patches', '_scproxy.py'),

pythonforandroid/recipes/sdl2/__init__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ class LibSDL2Recipe(NDKRecipe):
1212
depends = ['python2', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf']
1313
conflicts = ['sdl', 'pygame', 'pygame_bootstrap_components']
1414

15-
def prebuild_arch(self, arch):
16-
super(LibSDL2Recipe, self).prebuild_arch(arch)
17-
build_dir = self.get_build_dir(arch.arch)
18-
if exists(join(build_dir, '.patched')):
19-
info('SDL2 already patched, skipping')
20-
return
21-
self.apply_patch('add_nativeSetEnv.patch', arch.arch)
22-
shprint(sh.touch, join(build_dir, '.patched'))
15+
patches = ['add_nativeSetEnv.patch']
2316

2417
def get_recipe_env(self, arch=None):
2518
env = super(LibSDL2Recipe, self).get_recipe_env(arch)
Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
from pythonforandroid.toolchain import NDKRecipe, shprint, info
2-
from os.path import exists, join
3-
import sh
1+
from pythonforandroid.toolchain import NDKRecipe
2+
from pythonforandroid.patching import is_arch
3+
44

55
class LibSDL2Image(NDKRecipe):
66
version = '2.0.0'
77
url = 'https://www.libsdl.org/projects/SDL_image/release/SDL2_image-{version}.tar.gz'
88
dir_name = 'SDL2_image'
9-
10-
def prebuild_arch(self, arch):
11-
super(LibSDL2Image, self).prebuild_arch(arch)
12-
build_dir = self.get_build_dir(arch.arch)
13-
if exists(join(build_dir, '.patched')):
14-
info('SDL2_image already patched, skipping')
15-
return
16-
self.apply_patch('disable_webp.patch', arch.arch)
17-
if arch.arch == 'x86':
18-
self.apply_patch('disable_jpg.patch', arch.arch)
19-
shprint(sh.touch, join(build_dir, '.patched'))
9+
10+
patches = ['disable_webp.patch',
11+
('disable_jpg.patch', is_arch('x86'))]
12+
2013

2114
recipe = LibSDL2Image()
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
from pythonforandroid.toolchain import NDKRecipe, shprint, info
2-
from os.path import exists, join
3-
import sh
1+
from pythonforandroid.toolchain import NDKRecipe
2+
43

54
class LibSDL2Mixer(NDKRecipe):
65
version = '2.0.0'
76
url = 'https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-{version}.tar.gz'
87
dir_name = 'SDL2_mixer'
98

10-
def prebuild_arch(self, arch):
11-
super(LibSDL2Mixer, self).prebuild_arch(arch)
12-
build_dir = self.get_build_dir(arch.arch)
9+
patches = ['disable_modplug_mikmod_smpeg.patch']
1310

14-
if exists(join(build_dir, '.patched')):
15-
info('SDL2_mixer already patched, skipping')
16-
return
17-
self.apply_patch('disable_modplug_mikmod_smpeg.patch',
18-
arch.arch)
19-
shprint(sh.touch, join(build_dir, '.patched'))
2011

2112
recipe = LibSDL2Mixer()

pythonforandroid/recipes/sdl2python3/__init__.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
1-
from pythonforandroid.toolchain import NDKRecipe, shprint, current_directory, info_main
2-
from os.path import exists, join
1+
from pythonforandroid.toolchain import NDKRecipe, shprint, current_directory
32
import sh
43

54

6-
75
class LibSDL2Recipe(NDKRecipe):
86
version = "2.0.3"
97
url = "https://www.libsdl.org/release/SDL2-{version}.tar.gz"
108
depends = ['python3', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf']
119
# depends = ['python2']
1210
dir_name = 'SDL'
1311

14-
def prebuild_arch(self, arch):
15-
super(LibSDL2Recipe, self).prebuild_arch(arch)
16-
build_dir = self.get_build_dir(arch.arch)
17-
if exists(join(build_dir, '.patched')):
18-
print('SDL2 already patched, skipping')
19-
return
20-
self.apply_patch('add_nativeSetEnv.patch', arch.arch)
21-
shprint(sh.touch, join(build_dir, '.patched'))
12+
patches = ['add_nativeSetEnv.patch']
2213

2314
def build_arch(self, arch):
2415
env = self.get_recipe_env(arch)

0 commit comments

Comments
 (0)