|
| 1 | +import re |
1 | 2 | import os
|
2 |
| -from pythonforandroid.recipe import CompiledComponentsPythonRecipe |
| 3 | +import sh |
| 4 | +from pythonforandroid.logger import info, shprint |
| 5 | +from pythonforandroid.recipe import CythonRecipe |
3 | 6 |
|
4 | 7 |
|
5 |
| -class GeventRecipe(CompiledComponentsPythonRecipe): |
6 |
| - version = '1.1.1' |
| 8 | +class GeventRecipe(CythonRecipe): |
| 9 | + version = '1.3.7' |
7 | 10 | url = 'https://pypi.python.org/packages/source/g/gevent/gevent-{version}.tar.gz'
|
8 |
| - depends = [('python2', 'python3crystax'), 'greenlet'] |
9 |
| - patches = ["gevent.patch"] |
| 11 | + depends = ['greenlet'] |
| 12 | + patches = ["cross_compiling.patch"] |
| 13 | + |
| 14 | + def build_cython_components(self, arch): |
| 15 | + """ |
| 16 | + Hack to make it link properly to librt, inserted automatically by the |
| 17 | + installer (Note: the librt doesn't exist in android but it is |
| 18 | + integrated into libc, so we create a symbolic link which we will |
| 19 | + remove when our build finishes) |
| 20 | + """ |
| 21 | + link_c = os.path.join(self.ctx.ndk_platform, 'usr', 'lib', 'libc') |
| 22 | + link_rt = os.path.join(self.ctx.ndk_platform, 'usr', 'lib', 'librt') |
| 23 | + shprint(sh.ln, '-sf', link_c + '.so', link_rt + '.so') |
| 24 | + shprint(sh.ln, '-sf', link_c + '.a', link_rt + '.a') |
| 25 | + super(GeventRecipe, self).build_cython_components(arch) |
| 26 | + shprint(sh.rm, link_rt + '.so') |
| 27 | + shprint(sh.rm, link_rt + '.a') |
10 | 28 |
|
11 | 29 | def get_recipe_env(self, arch=None, with_flags_in_cc=True):
|
| 30 | + """ |
| 31 | + - Moves all -I<inc> -D<macro> from CFLAGS to CPPFLAGS environment. |
| 32 | + - Moves all -l<lib> from LDFLAGS to LIBS environment. |
| 33 | + - Fixes linker name (use cross compiler) and flags (appends LIBS) |
| 34 | + """ |
12 | 35 | env = super(GeventRecipe, self).get_recipe_env(arch, with_flags_in_cc)
|
13 |
| - # sets linker to use the correct gcc (cross compiler) |
14 |
| - env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions' |
15 | 36 | # CFLAGS may only be used to specify C compiler flags, for macro definitions use CPPFLAGS
|
16 |
| - env['CPPFLAGS'] = env['CFLAGS'] + ' -I{}/sources/python/3.5/include/python/'.format(self.ctx.ndk_dir) |
17 |
| - env['CFLAGS'] = '' |
| 37 | + regex = re.compile(r'(?:\s|^)-[DI][\S]+') |
| 38 | + env['CPPFLAGS'] = ''.join(re.findall(regex, env['CFLAGS'])).strip() |
| 39 | + env['CFLAGS'] = re.sub(regex, '', env['CFLAGS']) |
| 40 | + info('Moved "{}" from CFLAGS to CPPFLAGS.'.format(env['CPPFLAGS'])) |
18 | 41 | # LDFLAGS may only be used to specify linker flags, for libraries use LIBS
|
19 |
| - env['LDFLAGS'] = env['LDFLAGS'].replace('-lm', '').replace('-lcrystax', '') |
20 |
| - env['LDFLAGS'] += ' -L{}'.format(os.path.join(self.ctx.bootstrap.build_dir, 'libs', arch.arch)) |
21 |
| - env['LIBS'] = ' -lm' |
22 |
| - if self.ctx.ndk == 'crystax': |
23 |
| - env['LIBS'] += ' -lcrystax -lpython{}m'.format(self.ctx.python_recipe.version[0:3]) |
24 |
| - env['LDSHARED'] += env['LIBS'] |
| 42 | + regex = re.compile(r'(?:\s|^)-l[\w\.]+') |
| 43 | + env['LIBS'] = ''.join(re.findall(regex, env['LDFLAGS'])).strip() |
| 44 | + env['LDFLAGS'] = re.sub(regex, '', env['LDFLAGS']) |
| 45 | + info('Moved "{}" from LDFLAGS to LIBS.'.format(env['LIBS'])) |
25 | 46 | return env
|
26 | 47 |
|
27 | 48 |
|
|
0 commit comments