8000 Updated patching doc · latin1593/python-for-android@bf350e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit bf350e9

Browse files
committed
Updated patching doc
1 parent d5bdf22 commit bf350e9

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

doc/source/recipes.rst

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ The basic declaration of a recipe is as follows::
3838
url = 'http://example.com/example-{version}.tar.gz'
3939
version = '2.0.3'
4040
md5sum = '4f3dc9a9d857734a488bcbefd9cd64ed'
41+
42+
patches = ['some_fix.patch'] # Paths relative to the recipe dir
4143

4244
depends = ['kivy', 'sdl2'] # These are just examples
4345
conflicts = ['pygame']
@@ -118,26 +120,35 @@ Methods and tools to help with compilation
118120
Patching modules before installation
119121
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120122

121-
You can easily apply patches to your recipes with the ``apply_patch``
122-
method. For instance, you could do this in your prebuild method::
123-
124-
import sh
125-
def prebuild_arch(self, arch):
126-
super(YourRecipe, self).prebuild_arch(arch)
127-
build_dir = self.get_build_dir(arch.arch)
128-
if exists(join(build_dir, '.patched')):
129-
print('Your recipe is already patched, skipping')
130-
return
131-
self.apply_patch('some_patch.patch')
132-
shprint(sh.touch, join(build_dir, '.patched'))
133-
134-
The path to the patch should be in relation to your recipe code.
135-
In this case, ``some_path.patch`` must be in the same directory as the
136-
recipe.
137-
138-
This code also manually takes care to patch only once. You can use the
139-
same strategy yourself, though a more generic solution may be provided
140-
in the future.
123+
You can easily apply patches to your recipes by adding them to the
124+
``patches`` declaration, e.g.::
125+
126+
patches = ['some_fix.patch',
127+
'another_fix.patch']
128+
129+
The paths should be relative to the recipe file. Patches are
130+
automatically applied just once (i.e. not reapplied the second time
131+
python-for-android is run).
132+
133+
You can also use the helper functions in ``pythonforandroid.patching``
134 A800 +
to apply patches depending on certain conditions, e.g.::
135+
136+
from pythonforandroid.patching import will_build, is_arch
137+
138+
...
139+
140+
class YourRecipe(Recipe):
141+
142+
patches = [('x86_patch.patch', is_arch('x86')),
143+
('sdl2_compatibility.patch', will_build('sdl2'))]
144+
145+
...
146+
147+
You can include your own conditions by passing any function as the
148+
second entry of the tuple. It will receive the ``arch`` (e.g. x86,
149+
armeabi) and ``recipe`` (i.e. the Recipe object) as kwargs. The patch
150+
will be applied only if the function returns True.
151+
141152

142153
Installing libs
143154
~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)
0