|
1 | | -from pythonforandroid.recipe import TargetPythonRecipe |
| 1 | +from pythonforandroid.recipe import TargetPythonRecipe, Recipe |
2 | 2 | from pythonforandroid.toolchain import shprint, current_directory |
3 | 3 | from pythonforandroid.logger import logger, info, error |
4 | 4 | from pythonforandroid.util import ensure_dir, walk_valid_filens |
|
33 | 33 |
|
34 | 34 |
|
35 | 35 | class Python3Recipe(TargetPythonRecipe): |
| 36 | + ''' |
| 37 | + .. note:: |
| 38 | + In order to build certain python modules, we need to add some extra |
| 39 | + recipes to our build requirements: |
| 40 | +
|
| 41 | + - ctypes: you must add the recipe for ``libffi``. |
| 42 | + ''' |
36 | 43 | version = '3.7.1' |
37 | 44 | url = 'https://www.python.org/ftp/python/{version}/Python-{version}.tgz' |
38 | 45 | name = 'python3' |
39 | 46 |
|
40 | 47 | depends = ['hostpython3'] |
41 | 48 | conflicts = ['python3crystax', 'python2'] |
| 49 | + opt_depends = ['libffi'] |
42 | 50 |
|
43 | 51 | # This recipe can be built only against API 21+ |
44 | 52 | MIN_NDK_API = 21 |
45 | 53 |
|
| 54 | + def set_libs_flags(self, env, arch): |
| 55 | + '''Takes care to properly link libraries with python depending on our |
| 56 | + requirements and the attribute :attr:`opt_depends`. |
| 57 | + ''' |
| 58 | + if 'libffi' in self.ctx.recipe_build_order: |
| 59 | + info('Activating flags for libffi') |
| 60 | + recipe = Recipe.get_recipe('libffi', self.ctx) |
| 61 | + include = ' -I' + ' -I'.join(recipe.get_include_dirs(arch)) |
| 62 | + ldflag = ' -L' + join(recipe.get_build_dir(arch.arch), |
| 63 | + recipe.get_host(arch), '.libs') + ' -lffi' |
| 64 | + env['CPPFLAGS'] = env.get('CPPFLAGS', '') + include |
| 65 | + env['LDFLAGS'] = env.get('LDFLAGS', '') + ldflag |
| 66 | + return env |
| 67 | + |
46 | 68 | def build_arch(self, arch): |
47 | 69 | if self.ctx.ndk_api < self.MIN_NDK_API: |
48 | 70 | error('Target ndk-api is {}, but the python3 recipe supports only {}+'.format( |
@@ -119,6 +141,8 @@ def build_arch(self, arch): |
119 | 141 |
|
120 | 142 | env['SYSROOT'] = sysroot |
121 | 143 |
|
| 144 | + env = self.set_libs_flags(env, arch) |
| 145 | + |
122 | 146 | if not exists('config.status'): |
123 | 147 | shprint(sh.Command(join(recipe_build_dir, 'configure')), |
124 | 148 | *(' '.join(('--host={android_host}', |
|
0 commit comments