Skip to content

Commit cce4d5e

Browse files
committed
Improves gevent recipe robustness
Tries to match and replace patterns to be moved from one environment variable to another rather than hard coding it. That way unexpected flags added to parent recipes hierarchy also get handled. This issue popped when testing #793
1 parent 37dc89f commit cce4d5e

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

pythonforandroid/recipes/gevent/__init__.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import os
1+
import re
2+
from pythonforandroid.logger import info
23
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
34

45

@@ -7,21 +8,27 @@ class GeventRecipe(CompiledComponentsPythonRecipe):
78
url = 'https://pypi.python.org/packages/source/g/gevent/gevent-{version}.tar.gz'
89
depends = [('python2', 'python3crystax'), 'greenlet']
910
patches = ["gevent.patch"]
11+
call_hostpython_via_targetpython = False
1012

1113
def get_recipe_env(self, arch=None, with_flags_in_cc=True):
14+
"""
15+
- Moves all -I<inc> -D<macro> from CFLAGS to CPPFLAGS environment.
16+
- Moves all -l<lib> from LDFLAGS to LIBS environment.
17+
- Fixes linker name (use cross compiler) and flags (appends LIBS)
18+
"""
1219
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'
1520
# 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'] = ''
21+
regex = re.compile('\s*-[DI][\S]+')
22+
env['CPPFLAGS'] = ''.join(re.findall(regex, env['CFLAGS'])).strip()
23+
env['CFLAGS'] = re.sub(regex, '', env['CFLAGS'])
24+
info('Moved "{}" from CFLAGS to CPPFLAGS.'.format(env['CPPFLAGS']))
1825
# 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']
26+
regex = re.compile('\s*-l[\w\.]+')
27+
env['LIBS'] = ''.join(re.findall(regex, env['LDFLAGS'])).strip()
28+
env['LDFLAGS'] = re.sub(regex, '', env['LDFLAGS'])
29+
info('Moved "{}" from LDFLAGS to LIBS.'.format(env['LIBS']))
30+
# linker to use the correct gcc (cross compiler) plus additional libs
31+
env['LDSHARED'] = '{} -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions {}'.format(env['CC'], env['LIBS'])
2532
return env
2633

2734

0 commit comments

Comments
 (0)