diff --git a/pythonforandroid/recipes/gevent/__init__.py b/pythonforandroid/recipes/gevent/__init__.py index 5933fb3364..98fb2c316e 100644 --- a/pythonforandroid/recipes/gevent/__init__.py +++ b/pythonforandroid/recipes/gevent/__init__.py @@ -13,9 +13,10 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True): """ - Moves all -I -D from CFLAGS to CPPFLAGS environment. - Moves all -l from LDFLAGS to LIBS environment. + - Copies all -l from LDLIBS to LIBS environment. - Fixes linker name (use cross compiler) and flags (appends LIBS) """ - env = super(GeventRecipe, self).get_recipe_env(arch, with_flags_in_cc) + env = super().get_recipe_env(arch, with_flags_in_cc) # CFLAGS may only be used to specify C compiler flags, for macro definitions use CPPFLAGS regex = re.compile(r'(?:\s|^)-[DI][\S]+') env['CPPFLAGS'] = ''.join(re.findall(regex, env['CFLAGS'])).strip() @@ -24,6 +25,7 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True): # LDFLAGS may only be used to specify linker flags, for libraries use LIBS regex = re.compile(r'(?:\s|^)-l[\w\.]+') env['LIBS'] = ''.join(re.findall(regex, env['LDFLAGS'])).strip() + env['LIBS'] += ' {}'.format(''.join(re.findall(regex, env['LDLIBS'])).strip()) env['LDFLAGS'] = re.sub(regex, '', env['LDFLAGS']) info('Moved "{}" from LDFLAGS to LIBS.'.format(env['LIBS'])) return env diff --git a/tests/recipes/test_gevent.py b/tests/recipes/test_gevent.py index fa56fe6a11..8c6601e255 100644 --- a/tests/recipes/test_gevent.py +++ b/tests/recipes/test_gevent.py @@ -29,9 +29,11 @@ def test_get_recipe_env(self): # checks the regex doesn't parse `python3-libffi-openssl` as a `-libffi` '-L/path/to/python3-libffi-openssl/library3 ' ) + mocked_ldlibs = ' -lm' mocked_env = { 'CFLAGS': mocked_cflags, 'LDFLAGS': mocked_ldflags, + 'LDLIBS': mocked_ldlibs, } with patch('pythonforandroid.recipe.CythonRecipe.get_recipe_env') as m_get_recipe_env: m_get_recipe_env.return_value = mocked_env @@ -53,11 +55,13 @@ def test_get_recipe_env(self): ' -L/path/to/library2' ' -L/path/to/python3-libffi-openssl/library3 ' ) - expected_libs = '-lm -lpython3.7m' + expected_ldlibs = mocked_ldlibs + expected_libs = '-lm -lpython3.7m -lm' expected_env = { 'CFLAGS': expected_cflags, 'CPPFLAGS': expected_cppflags, 'LDFLAGS': expected_ldflags, + 'LDLIBS': expected_ldlibs, 'LIBS': expected_libs, } self.assertEqual(expected_env, env)