Skip to content

Commit 4d2d5f0

Browse files
authored
Merge pull request #3129 from kivy/feature/fix_gevent
🐛 Upgrade and fix gevent recipe, closes #2805
2 parents 37b5b21 + 798e2c2 commit 4d2d5f0

File tree

3 files changed

+39
-24
lines changed

3 files changed

+39
-24
lines changed

pythonforandroid/recipes/gevent/__init__.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
1+
"""
2+
Note that this recipe doesn't yet build on macOS, the error is:
3+
```
4+
deps/libuv/src/unix/bsd-ifaddrs.c:31:10: fatal error: 'net/if_dl.h' file not found
5+
#include <net/if_dl.h>
6+
^~~~~~~~~~~~~
7+
1 error generated.
8+
error: command '/Users/runner/.android/android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang' failed with exit code 1
9+
```
10+
"""
111
import re
212
from pythonforandroid.logger import info
3-
from pythonforandroid.recipe import CythonRecipe
13+
from pythonforandroid.recipe import PyProjectRecipe
414

515

6-
class GeventRecipe(CythonRecipe):
7-
version = '1.4.0'
8-
url = 'https://pypi.python.org/packages/source/g/gevent/gevent-{version}.tar.gz'
16+
class GeventRecipe(PyProjectRecipe):
17+
version = '24.11.1'
18+
url = 'https://github.com/gevent/gevent/archive/refs/tags/{version}.tar.gz'
919
depends = ['librt', 'setuptools']
1020
patches = ["cross_compiling.patch"]
1121

12-
def get_recipe_env(self, arch=None, with_flags_in_cc=True):
22+
def get_recipe_env(self, arch, **kwargs):
1323
"""
1424
- Moves all -I<inc> -D<macro> from CFLAGS to CPPFLAGS environment.
1525
- Moves all -l<lib> from LDFLAGS to LIBS environment.
1626
- Copies all -l<lib> from LDLIBS to LIBS environment.
17-
- Fixes linker name (use cross compiler) and flags (appends LIBS)
27+
- Fixes linker name (use cross compiler) and flags (appends LIBS).
28+
- Feds the command prefix for the configure --host flag.
1829
"""
19-
env = super().get_recipe_env(arch, with_flags_in_cc)
30+
env = super().get_recipe_env(arch, **kwargs)
2031
# CFLAGS may only be used to specify C compiler flags, for macro definitions use CPPFLAGS
2132
regex = re.compile(r'(?:\s|^)-[DI][\S]+')
2233
env['CPPFLAGS'] = ''.join(re.findall(regex, env['CFLAGS'])).strip()
@@ -28,6 +39,8 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
2839
env['LIBS'] += ' {}'.format(''.join(re.findall(regex, env['LDLIBS'])).strip())
2940
env['LDFLAGS'] = re.sub(regex, '', env['LDFLAGS'])
3041
info('Moved "{}" from LDFLAGS to LIBS.'.format(env['LIBS']))
42+
# used with the `./configure --host` flag for cross compiling, refs #2805
43+
env['COMMAND_PREFIX'] = arch.command_prefix
3144
return env
3245

3346

Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
diff --git a/_setupares.py b/_setupares.py
2-
index dd184de6..bb16bebe 100644
2+
index c42fe369..cd8854df 100644
33
--- a/_setupares.py
44
+++ b/_setupares.py
5-
@@ -43,7 +43,7 @@ else:
5+
@@ -42,7 +42,7 @@ cflags = ('CFLAGS="%s"' % (cflags,)) if cflags else ''
66
ares_configure_command = ' '.join([
77
"(cd ", quoted_dep_abspath('c-ares'),
8-
" && if [ -r ares_build.h ]; then cp ares_build.h ares_build.h.orig; fi ",
9-
- " && sh ./configure --disable-dependency-tracking " + _m32 + "CONFIG_COMMANDS= ",
10-
+ " && sh ./configure --host={} --disable-dependency-tracking ".format(os.environ['TOOLCHAIN_PREFIX']) + _m32 + "CONFIG_COMMANDS= ",
11-
" && cp ares_config.h ares_build.h \"$OLDPWD\" ",
12-
" && cat ares_build.h ",
13-
" && if [ -r ares_build.h.orig ]; then mv ares_build.h.orig ares_build.h; fi)",
8+
" && if [ -r include/ares_build.h ]; then cp include/ares_build.h include/ares_build.h.orig; fi ",
9+
- " && sh ./configure --disable-dependency-tracking --disable-tests -C " + cflags,
10+
+ " && sh ./configure --host={} --disable-dependency-tracking --disable-tests -C ".format(os.environ['COMMAND_PREFIX']) + cflags,
11+
" && cp src/lib/ares_config.h include/ares_build.h \"$OLDPWD\" ",
12+
" && cat include/ares_build.h ",
13+
" && if [ -r include/ares_build.h.orig ]; then mv include/ares_build.h.orig include/ares_build.h; fi)",
1414
diff --git a/_setuplibev.py b/_setuplibev.py
15-
index 2a5841bf..b6433c94 100644
15+
index f05c2fe9..32f9bd81 100644
1616
--- a/_setuplibev.py
1717
+++ b/_setuplibev.py
18-
@@ -31,7 +31,7 @@ LIBEV_EMBED = should_embed('libev')
19-
# and the PyPy branch will clean it up.
18+
@@ -28,7 +28,7 @@ LIBEV_EMBED = should_embed('libev')
19+
# Configure libev in place
2020
libev_configure_command = ' '.join([
2121
"(cd ", quoted_dep_abspath('libev'),
22-
- " && sh ./configure ",
23-
+ " && sh ./configure --host={} ".format(os.environ['TOOLCHAIN_PREFIX']),
24-
" && cp config.h \"$OLDPWD\"",
22+
- " && sh ./configure -C > configure-output.txt",
23+
+ " && sh ./configure --host={} -C > configure-output.txt".format(os.environ['COMMAND_PREFIX']),
2524
")",
26-
'> configure-output.txt'
25+
])
26+

tests/recipes/test_gevent.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def test_get_recipe_env(self):
3535
'LDFLAGS': mocked_ldflags,
3636
'LDLIBS': mocked_ldlibs,
3737
}
38-
with patch('pythonforandroid.recipe.CythonRecipe.get_recipe_env') as m_get_recipe_env:
38+
with patch('pythonforandroid.recipe.PyProjectRecipe.get_recipe_env') as m_get_recipe_env:
3939
m_get_recipe_env.return_value = mocked_env
40-
env = self.recipe.get_recipe_env()
40+
env = self.recipe.get_recipe_env(self.arch)
4141
expected_cflags = (
4242
' -fomit-frame-pointer -mandroid -isystem /path/to/isystem'
4343
' -isysroot /path/to/sysroot'
@@ -57,11 +57,13 @@ def test_get_recipe_env(self):
5757
)
5858
expected_ldlibs = mocked_ldlibs
5959
expected_libs = '-lm -lpython3.7m -lm'
60+
expected_command_prefix = 'aarch64-linux-android'
6061
expected_env = {
6162
'CFLAGS': expected_cflags,
6263
'CPPFLAGS': expected_cppflags,
6364
'LDFLAGS': expected_ldflags,
6465
'LDLIBS': expected_ldlibs,
6566
'LIBS': expected_libs,
67+
'COMMAND_PREFIX': expected_command_prefix,
6668
}
6769
self.assertEqual(expected_env, env)

0 commit comments

Comments
 (0)