Skip to content

Commit 1925bef

Browse files
committed
Create a dumb librt recipe and refactor the affected recipes to make use of this
Because some recipes inserts flags without our control (`-lrt`) and this is a problem because librt does not exist in android, but has been integrated into libc, so, this recipe create a temporary symbolic link from libc to librt so the compilation can find the necessary `symbols/functions` to finish the compilation Note: Once we end the build we will remove the created symbolic link
1 parent 041199b commit 1925bef

File tree

3 files changed

+39
-37
lines changed

3 files changed

+39
-37
lines changed

pythonforandroid/recipes/gevent/__init__.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,14 @@
11
import re
2-
import os
3-
import sh
4-
from pythonforandroid.logger import info, shprint
2+
from pythonforandroid.logger import info
53
from pythonforandroid.recipe import CythonRecipe
64

75

86
class GeventRecipe(CythonRecipe):
97
version = '1.3.7'
108
url = 'https://pypi.python.org/packages/source/g/gevent/gevent-{version}.tar.gz'
11-
depends = ['greenlet']
9+
depends = ['librt', 'greenlet']
1210
patches = ["cross_compiling.patch"]
1311

14-
def build_cython_components(self, arch):
15-
"""
16-
Hack to make it link properly to librt, inserted automatically by the
17-
installer (Note: the librt doesn't exist in android but it is
18-
integrated into libc, so we create a symbolic link which we will
19-
remove when our build finishes)
20-
"""
21-
link_c = os.path.join(self.ctx.ndk_platform, 'usr', 'lib', 'libc')
22-
link_rt = os.path.join(self.ctx.ndk_platform, 'usr', 'lib', 'librt')
23-
shprint(sh.ln, '-sf', link_c + '.so', link_rt + '.so')
24-
shprint(sh.ln, '-sf', link_c + '.a', link_rt + '.a')
25-
super(GeventRecipe, self).build_cython_components(arch)
26-
shprint(sh.rm, link_rt + '.so')
27-
shprint(sh.rm, link_rt + '.a')
28-
2912
def get_recipe_env(self, arch=None, with_flags_in_cc=True):
3013
"""
3114
- Moves all -I<inc> -D<macro> from CFLAGS to CPPFLAGS environment.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import sh
2+
from os.path import join
3+
from pythonforandroid.recipe import Recipe
4+
from pythonforandroid.logger import shprint
5+
6+
7+
class LibRt(Recipe):
8+
'''
9+
This is a dumb recipe. We may need this because some recipes inserted some
10+
flags `-lrt` without our control, case of:
11+
12+
- :class:`~pythonforandroid.recipes.gevent.GeventRecipe`
13+
- :class:`~pythonforandroid.recipes.lxml.LXMLRecipe`
14+
15+
.. note:: the librt doesn't exist in android but it is integrated into
16+
libc, so we create a symbolic link which we will remove when our build
17+
finishes'''
18+
19+
@property
20+
def libc_path(self):
21+
return join(self.ctx.ndk_platform, 'usr', 'lib', 'libc')
22+
23+
@property
24+
def librt_path(self):
25+
return join(self.ctx.ndk_platform, 'usr', 'lib', 'librt')
26+
27+
def build_arch(self, arch):
28+
shprint(sh.ln, '-sf', self.libc_path + '.so', self.librt_path + '.so')
29+
shprint(sh.ln, '-sf', self.libc_path + '.a', self.librt_path + '.a')
30+
31+
def postbuild_arch(self, arch):
32+
shprint(sh.rm, self.librt_path + '.so')
33+
shprint(sh.rm, self.librt_path + '.a')
34+
35+
36+
recipe = LibRt()

pythonforandroid/recipes/lxml/__init__.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
from pythonforandroid.recipe import Recipe, CompiledComponentsPythonRecipe
2-
from pythonforandroid.logger import shprint
32
from os.path import exists, join
43
from os import uname
5-
import sh
64

75

86
class LXMLRecipe(CompiledComponentsPythonRecipe):
97
version = '4.2.5'
108
url = 'https://pypi.python.org/packages/source/l/lxml/lxml-{version}.tar.gz' # noqa
11-
depends = ['libxml2', 'libxslt', 'setuptools']
9+
depends = ['librt', 'libxml2', 'libxslt', 'setuptools']
1210
name = 'lxml'
1311

1412
call_hostpython_via_targetpython = False # Due to setuptools
@@ -25,21 +23,6 @@ def should_build(self, arch):
2523

2624
return not all([exists(join(build_dir, lib)) for lib in py_libs])
2725

28-
def build_compiled_components(self, arch):
29-
# Hack to make it link properly to librt, inserted automatically by the
30-
# installer (Note: the librt doesn't exist in android but it is
31-
# integrated into libc, so we create a symbolic link which we will
32-
# remove when our build finishes)
33-
link_c = join(self.ctx.ndk_platform, 'usr', 'lib', 'libc')
34-
link_rt = join(self.ctx.ndk_platform, 'usr', 'lib', 'librt')
35-
shprint(sh.ln, '-sf', link_c + '.so', link_rt + '.so')
36-
shprint(sh.ln, '-sf', link_c + '.a', link_rt + '.a')
37-
38-
super(LXMLRecipe, self).build_compiled_components(arch)
39-
40-
shprint(sh.rm, '-r', link_rt + '.so')
41-
shprint(sh.rm, '-r', link_rt + '.a')
42-
4326
def get_recipe_env(self, arch):
4427
env = super(LXMLRecipe, self).get_recipe_env(arch)
4528

0 commit comments

Comments
 (0)