Skip to content

Migrates gevent to new python3 recipe #1600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 36 additions & 15 deletions pythonforandroid/recipes/gevent/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
import re
import os
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
import sh
from pythonforandroid.logger import info, shprint
from pythonforandroid.recipe import CythonRecipe


class GeventRecipe(CompiledComponentsPythonRecipe):
version = '1.1.1'
class GeventRecipe(CythonRecipe):
version = '1.3.7'
url = 'https://pypi.python.org/packages/source/g/gevent/gevent-{version}.tar.gz'
depends = [('python2', 'python3crystax'), 'greenlet']
patches = ["gevent.patch"]
depends = ['greenlet']
patches = ["cross_compiling.patch"]

def build_cython_components(self, arch):
"""
Hack to make it link properly to librt, inserted automatically by the
installer (Note: the librt doesn't exist in android but it is
integrated into libc, so we create a symbolic link which we will
remove when our build finishes)
"""
link_c = os.path.join(self.ctx.ndk_platform, 'usr', 'lib', 'libc')
link_rt = os.path.join(self.ctx.ndk_platform, 'usr', 'lib', 'librt')
shprint(sh.ln, '-sf', link_c + '.so', link_rt + '.so')
shprint(sh.ln, '-sf', link_c + '.a', link_rt + '.a')
super(GeventRecipe, self).build_cython_components(arch)
shprint(sh.rm, link_rt + '.so')
shprint(sh.rm, link_rt + '.a')

def get_recipe_env(self, arch=None, with_flags_in_cc=True):
"""
- Moves all -I<inc> -D<macro> from CFLAGS to CPPFLAGS environment.
- Moves all -l<lib> from LDFLAGS 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)
# sets linker to use the correct gcc (cross compiler)
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
# CFLAGS may only be used to specify C compiler flags, for macro definitions use CPPFLAGS
env['CPPFLAGS'] = env['CFLAGS'] + ' -I{}/sources/python/3.5/include/python/'.format(self.ctx.ndk_dir)
env['CFLAGS'] = ''
regex = re.compile(r'(?:\s|^)-[DI][\S]+')
env['CPPFLAGS'] = ''.join(re.findall(regex, env['CFLAGS'])).strip()
env['CFLAGS'] = re.sub(regex, '', env['CFLAGS'])
info('Moved "{}" from CFLAGS to CPPFLAGS.'.format(env['CPPFLAGS']))
# LDFLAGS may only be used to specify linker flags, for libraries use LIBS
env['LDFLAGS'] = env['LDFLAGS'].replace('-lm', '').replace('-lcrystax', '')
env['LDFLAGS'] += ' -L{}'.format(os.path.join(self.ctx.bootstrap.build_dir, 'libs', arch.arch))
env['LIBS'] = ' -lm'
if self.ctx.ndk == 'crystax':
env['LIBS'] += ' -lcrystax -lpython{}m'.format(self.ctx.python_recipe.version[0:3])
env['LDSHARED'] += env['LIBS']
regex = re.compile(r'(?:\s|^)-l[\w\.]+')
env['LIBS'] = ''.join(re.findall(regex, env['LDFLAGS'])).strip()
env['LDFLAGS'] = re.sub(regex, '', env['LDFLAGS'])
info('Moved "{}" from LDFLAGS to LIBS.'.format(env['LIBS']))
return env


Expand Down
26 changes: 26 additions & 0 deletions pythonforandroid/recipes/gevent/cross_compiling.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/_setupares.py b/_setupares.py
index dd184de6..bb16bebe 100644
--- a/_setupares.py
+++ b/_setupares.py
@@ -43,7 +43,7 @@ else:
ares_configure_command = ' '.join([
"(cd ", quoted_dep_abspath('c-ares'),
" && if [ -r ares_build.h ]; then cp ares_build.h ares_build.h.orig; fi ",
- " && sh ./configure --disable-dependency-tracking " + _m32 + "CONFIG_COMMANDS= ",
+ " && sh ./configure --host={} --disable-dependency-tracking ".format(os.environ['TOOLCHAIN_PREFIX']) + _m32 + "CONFIG_COMMANDS= ",
" && cp ares_config.h ares_build.h \"$OLDPWD\" ",
" && cat ares_build.h ",
" && if [ -r ares_build.h.orig ]; then mv ares_build.h.orig ares_build.h; fi)",
diff --git a/_setuplibev.py b/_setuplibev.py
index 2a5841bf..b6433c94 100644
--- a/_setuplibev.py
+++ b/_setuplibev.py
@@ -31,7 +31,7 @@ LIBEV_EMBED = should_embed('libev')
# and the PyPy branch will clean it up.
libev_configure_command = ' '.join([
"(cd ", quoted_dep_abspath('libev'),
- " && sh ./configure ",
+ " && sh ./configure --host={} ".format(os.environ['TOOLCHAIN_PREFIX']),
" && cp config.h \"$OLDPWD\"",
")",
'> configure-output.txt'
21 changes: 0 additions & 21 deletions pythonforandroid/recipes/gevent/gevent.patch

This file was deleted.

73 changes: 73 additions & 0 deletions tests/recipes/test_gevent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import unittest
from mock import patch
from pythonforandroid.archs import ArchARMv7_a
from pythonforandroid.build import Context
from pythonforandroid.recipe import Recipe


class TestGeventRecipe(unittest.TestCase):

def setUp(self):
"""
Setups recipe and context.
"""
self.context = Context()
self.context.ndk_api = 21
self.context.android_api = 27
self.arch = ArchARMv7_a(self.context)
self.recipe = Recipe.get_recipe('gevent', self.context)

def test_get_recipe_env(self):
"""
Makes sure `get_recipe_env()` sets compilation flags properly.
"""
mocked_cflags = (
'-DANDROID -fomit-frame-pointer -D__ANDROID_API__=27 -mandroid '
'-isystem /path/to/isystem '
'-I/path/to/include1 '
'-isysroot /path/to/sysroot '
'-I/path/to/include2 '
'-march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mthumb '
'-I/path/to/python3-libffi-openssl/include'
)
mocked_ldflags = (
' --sysroot /path/to/sysroot '
'-lm '
'-L/path/to/library1 '
'-L/path/to/library2 '
'-lpython3.7m '
# checks the regex doesn't parse `python3-libffi-openssl` as a `-libffi`
'-L/path/to/python3-libffi-openssl/library3 '
)
mocked_env = {
'CFLAGS': mocked_cflags,
'LDFLAGS': mocked_ldflags,
}
with patch('pythonforandroid.recipe.CythonRecipe.get_recipe_env') as m_get_recipe_env:
m_get_recipe_env.return_value = mocked_env
env = self.recipe.get_recipe_env()
expected_cflags = (
' -fomit-frame-pointer -mandroid -isystem /path/to/isystem'
' -isysroot /path/to/sysroot'
' -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mthumb'
)
expected_cppflags = (
'-DANDROID -D__ANDROID_API__=27 '
'-I/path/to/include1 '
'-I/path/to/include2 '
'-I/path/to/python3-libffi-openssl/include'
)
expected_ldflags = (
' --sysroot /path/to/sysroot'
' -L/path/to/library1'
' -L/path/to/library2'
' -L/path/to/python3-libffi-openssl/library3 '
)
expected_libs = '-lm -lpython3.7m'
expected_env = {
'CFLAGS': expected_cflags,
'CPPFLAGS': expected_cppflags,
'LDFLAGS': expected_ldflags,
'LIBS': expected_libs,
}
self.assertEqual(expected_env, env)