Skip to content

Commit 7740e84

Browse files
committed
easier patching for recipes
1 parent 903d661 commit 7740e84

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pythonforandroid/toolchain.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,12 @@ class Recipe(object):
16151615
'''A list of optional dependencies, that must be built before this
16161616
recipe if they are built at all, but whose presence is not essential.'''
16171617

1618+
patches = []
1619+
'''A list of patches to apply to the source. Values can be either a string
1620+
referring to the patch file relative to the recipe dir, or a tuple of the
1621+
string patch file and a callable, which will receive the kwargs `arch` and
1622+
`version`, which should return True if the patch should be applied.'''
1623+
16181624
archs = ['armeabi'] # Not currently implemented properly
16191625

16201626
@property
@@ -1981,6 +1987,27 @@ def prebuild_arch(self, arch):
19811987
else:
19821988
info('{} has no {}, skipping'.format(self.name, prebuild))
19831989

1990+
def apply_patches(self, arch):
1991+
'''Apply any patches for the Recipe.'''
1992+
if self.patches:
1993+
info_main('Applying patches for {}[{}]'
1994+
.format(self.name, arch.arch))
1995+
1996+
build_dir = self.get_build_dir(arch.arch)
1997+
if exists(join(build_dir, '.patched')):
1998+
info_main('{} already patched, skipping'.format(self.name))
1999+
return
2000+
2001+
for patch in self.patches:
2002+
if isinstance(patch, (tuple, list)):
2003+
patch, patch_check = patch
2004+
if not patch_check(arch=arch, version=self.version):
2005+
continue
2006+
2007+
self.apply_patch(patch, arch.arch)
2008+
2009+
shprint(sh.touch, join(build_dir, '.patched'))
2010+
19842011
def should_build(self, arch):
19852012
'''Should perform any necessary test and return True only if it needs
19862013
building again.
@@ -2309,6 +2336,7 @@ def build_recipes(build_order, python_modules, ctx):
23092336
for recipe in recipes:
23102337
info_main('Prebuilding {} for {}'.format(recipe.name, arch.arch))
23112338
recipe.prebuild_arch(arch)
2339+
recipe.apply_patches(arch)
23122340

23132341
# 3) build packages
23142342
info_main('# Building recipes')

0 commit comments

Comments
 (0)