Skip to content

Commit 489eb5c

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 489eb5c

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

pythonforandroid/recipes/gevent/__init__.py

Lines changed: 17 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

@@ -9,19 +10,24 @@ class GeventRecipe(CompiledComponentsPythonRecipe):
910
patches = ["gevent.patch"]
1011

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

2733

0 commit comments

Comments
 (0)