|
1 |
| -from pythonforandroid.toolchain import Recipe, shutil |
2 |
| -from pythonforandroid.recipe import CompiledComponentsPythonRecipe |
| 1 | +from pythonforandroid.recipe import Recipe, CompiledComponentsPythonRecipe |
| 2 | +from pythonforandroid.logger import shprint |
3 | 3 | from os.path import exists, join
|
4 |
| -from os import listdir |
| 4 | +from os import uname |
| 5 | +import sh |
5 | 6 |
|
6 | 7 |
|
7 | 8 | class LXMLRecipe(CompiledComponentsPythonRecipe):
|
8 |
| - version = "3.6.0" |
9 |
| - url = "https://pypi.python.org/packages/source/l/lxml/lxml-{version}.tar.gz" |
10 |
| - depends = ["libxml2", "libxslt"] |
11 |
| - name = "lxml" |
| 9 | + version = '4.2.5' |
| 10 | + url = 'https://pypi.python.org/packages/source/l/lxml/lxml-{version}.tar.gz' # noqa |
| 11 | + depends = ['libxml2', 'libxslt', 'setuptools'] |
| 12 | + name = 'lxml' |
12 | 13 |
|
13 | 14 | call_hostpython_via_targetpython = False # Due to setuptools
|
14 | 15 |
|
15 | 16 | def should_build(self, arch):
|
16 | 17 | super(LXMLRecipe, self).should_build(arch)
|
17 |
| - return True |
18 |
| - return not exists(join(self.ctx.get_libs_dir(arch.arch), "etree.so")) |
19 |
| - |
20 |
| - def build_arch(self, arch): |
21 |
| - super(LXMLRecipe, self).build_arch(arch) |
22 |
| - |
23 |
| - def get_lib_build_dir_name(): |
24 |
| - for f in listdir(join(self.get_build_dir(arch.arch), "build")): |
25 |
| - if f.startswith("lib.linux-x86_64"): |
26 |
| - return f |
27 |
| - return None |
28 |
| - |
29 |
| - def get_so_name(so_target, dirpath): |
30 |
| - for f in listdir(dirpath): |
31 |
| - if f.startswith(so_target.partition(".")[0] + ".") and \ |
32 |
| - f.endswith(".so"): |
33 |
| - return join(dirpath, f) |
34 |
| - return None |
35 |
| - |
36 |
| - so_origin_dir = "%s/build/%s/lxml/" % (self.get_build_dir(arch.arch), |
37 |
| - get_lib_build_dir_name()) |
38 |
| - shutil.copyfile( |
39 |
| - join(so_origin_dir, get_so_name("etree.so", so_origin_dir)), |
40 |
| - join(self.ctx.get_libs_dir(arch.arch), "etree.so"), |
41 |
| - ) |
42 |
| - shutil.copyfile( |
43 |
| - join(so_origin_dir, get_so_name("objectify.so", so_origin_dir)), |
44 |
| - join(self.ctx.get_libs_dir(arch.arch), "objectify.so"), |
45 |
| - ) |
| 18 | + |
| 19 | + py_ver = self.ctx.python_recipe.major_minor_version_string |
| 20 | + build_platform = '{system}-{machine}'.format( |
| 21 | + system=uname()[0], machine=uname()[-1]).lower() |
| 22 | + build_dir = join(self.get_build_dir(arch.arch), 'build', |
| 23 | + 'lib.' + build_platform + '-' + py_ver, 'lxml') |
| 24 | + py_libs = ['_elementpath.so', 'builder.so', 'etree.so', 'objectify.so'] |
| 25 | + |
| 26 | + return not all([exists(join(build_dir, lib)) for lib in py_libs]) |
| 27 | + |
| 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') |
46 | 42 |
|
47 | 43 | def get_recipe_env(self, arch):
|
48 | 44 | env = super(LXMLRecipe, self).get_recipe_env(arch)
|
49 |
| - libxslt_recipe = Recipe.get_recipe("libxslt", self.ctx).get_build_dir(arch.arch) |
50 |
| - libxml2_recipe = Recipe.get_recipe("libxml2", self.ctx).get_build_dir(arch.arch) |
51 |
| - env["CC"] += " -I%s/include -I%s " % ( |
52 |
| - libxml2_recipe, |
53 |
| - libxslt_recipe, |
54 |
| - ) |
| 45 | + |
| 46 | + # libxslt flags |
| 47 | + libxslt_recipe = Recipe.get_recipe('libxslt', self.ctx) |
| 48 | + libxslt_build_dir = libxslt_recipe.get_build_dir(arch.arch) |
| 49 | + |
| 50 | + cflags = ' -I' + libxslt_build_dir |
| 51 | + cflags += ' -I' + join(libxslt_build_dir, 'libxslt') |
| 52 | + cflags += ' -I' + join(libxslt_build_dir, 'libexslt') |
| 53 | + |
| 54 | + env['LDFLAGS'] += ' -L' + join(libxslt_build_dir, 'libxslt', '.libs') |
| 55 | + env['LDFLAGS'] += ' -L' + join(libxslt_build_dir, 'libexslt', '.libs') |
| 56 | + env['LIBS'] = '-lxslt -lexslt' |
| 57 | + |
| 58 | + # libxml2 flags |
| 59 | + libxml2_recipe = Recipe.get_recipe('libxml2', self.ctx) |
| 60 | + libxml2_build_dir = libxml2_recipe.get_build_dir(arch.arch) |
| 61 | + libxml2_libs_dir = join(libxml2_build_dir, '.libs') |
| 62 | + |
| 63 | + cflags += ' -I' + libxml2_build_dir |
| 64 | + cflags += ' -I' + join(libxml2_build_dir, 'include') |
| 65 | + cflags += ' -I' + join(libxml2_build_dir, 'include', 'libxml') |
| 66 | + cflags += ' -I' + self.get_build_dir(arch.arch) |
| 67 | + env['LDFLAGS'] += ' -L' + libxml2_libs_dir |
| 68 | + env['LIBS'] += ' -lxml2' |
| 69 | + |
| 70 | + # android's ndk flags |
| 71 | + ndk_lib_dir = join(self.ctx.ndk_platform, 'usr', 'lib') |
| 72 | + ndk_include_dir = join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include') |
| 73 | + cflags += ' -I' + ndk_include_dir |
| 74 | + env['LDFLAGS'] += ' -L' + ndk_lib_dir |
| 75 | + env['LIBS'] += ' -lz -lm -lc' |
| 76 | + |
| 77 | + if cflags not in env['CFLAGS']: |
| 78 | + env['CFLAGS'] += cflags |
| 79 | + |
55 | 80 | return env
|
56 | 81 |
|
57 | 82 |
|
|
0 commit comments