Skip to content

Commit a0bdc29

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 a0bdc29

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

pythonforandroid/recipes/gevent/__init__.py

Lines changed: 15 additions & 9 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+
- Makes sure the linker is the cross compiler one.
15+
- Moves all -I<inc> -D<macro> from CFLAGS to CPPFLAGS environment.
16+
- Moves all -l<lib> from LDFLAGS to LIBS environment.
17+
"""
1218
env = super(GeventRecipe, self).get_recipe_env(arch, with_flags_in_cc)
1319
# sets linker to use the correct gcc (cross compiler)
1420
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
1521
# 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'] = ''
22+
regex = re.compile('\s*-[DI][\S]+')
23+
env['CPPFLAGS'] = ''.join(re.findall(regex, env['CFLAGS'])).strip()
24+
env['CFLAGS'] = re.sub(regex, '', env['CFLAGS'])
25+
info('Moved "{}" from CFLAGS to CPPFLAGS.'.format(env['CPPFLAGS']))
1826
# 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']
27+
regex = re.compile('\s*-l[\w\.]+')
28+
env['LIBS'] = ''.join(re.findall(regex, env['LDFLAGS'])).strip()
29+
env['LDFLAGS'] = re.sub(regex, '', env['LDFLAGS'])
30+
info('Moved "{}" from LDFLAGS to LIBS.'.format(env['LIBS']))
2531
return env
2632

2733

0 commit comments

Comments
 (0)