8000 Merge pull request #1580 from opacam/rework-lxml · pygame/python-for-android@6710378 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6710378

Browse files
authored
Merge pull request kivy#1580 from opacam/rework-lxml
[WIP] Rework libxml2, libxslt and lxml (update versions)
2 parents 21bc8b8 + cad8283 commit 6710378

File tree

3 files changed

+152
-110
lines changed

3 files changed

+152
-110
lines changed

pythonforandroid/recipes/libxml2/__init__.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,58 @@
1-
from pythonforandroid.toolchain import Recipe, shprint, shutil, current_directory
1+
from pythonforandroid.recipe import Recipe
2+
from pythonforandroid.toolchain import shprint, shutil, current_directory
23
from os.path import exists, join
34
import sh
45

56

67
class Libxml2Recipe(Recipe):
7-
version = "2.7.8"
8-
url = "http://xmlsoft.org/sources/libxml2-{version}.tar.gz"
8+
version = '2.9.8'
9+
url = 'http://xmlsoft.org/sources/libxml2-{version}.tar.gz'
910
depends = []
10-
patches = ["add-glob.c.patch"]
11+
patches = ['add-glob.c.patch']
1112

1213
def should_build(self, arch):
1314
super(Libxml2Recipe, self).should_build(arch)
14-
return not exists(join(self.ctx.get_libs_dir(arch.arch), "libxml2.a"))
15+
return not exists(
16+
join(self.get_build_dir(arch.arch), '.libs', 'libxml2.a'))
1517

1618
def build_arch(self, arch):
1719
super(Libxml2Recipe, self).build_arch(arch)
1820
env = self.get_recipe_env(arch)
1921
with current_directory(self.get_build_dir(arch.arch)):
20-
env["CC"] += " -I%s" % self.get_build_dir(arch.arch)
21-
shprint(
22-
sh.Command("./configure"),
23-
"--host=arm-linux-eabi",
24-
"--without-modules",
25-
"--without-legacy",
26-
"--without-history",
27-
"--without-debug",
28-
"--without-docbook",
29-
"--without-python",
30-
"--without-threads",
31-
"--without-iconv",
32-
_env=env,
33-
)
22+
23+
if not exists('configure'):
24+
shprint(sh.Command('./autogen.sh'), _env=env)
25+
shprint(sh.Command('autoreconf'), '-vif', _env=env)
26+
build_arch = shprint(
27+
sh.gcc, '-dumpmachine').stdout.decode('utf-8').split('\n')[0]
28+
shprint(sh.Command('./configure'),
29+
'--build=' + build_arch,
30+
'--host=' + arch.command_prefix,
31+
'--target=' + arch.command_prefix,
32+
'--without-modules',
33+
'--without-legacy',
34+
'--without-history',
35+
'--without-debug',
36+
'--without-docbook',
37+
'--without-python',
38+
'--without-threads',
39+
'--without-iconv',
40+
'--disable-shared',
41+
'--enable-static',
42+
_env=env)
3443

3544
# Ensure we only build libxml2.la as if we do everything
3645
# we'll need the glob dependency which is a big headache
3746
shprint(sh.make, "libxml2.la", _env=env)
38-
shutil.copyfile(
39-
".libs/libxml2.a", join(self.ctx.get_libs_dir(arch.arch), "libxml2.a")
40-
)
47+
48+
shutil.copyfile('.libs/libxml2.a',
49+
join(self.ctx.libs_dir, 'libxml2.a'))
4150

4251
def get_recipe_env(self, arch):
4352
env = super(Libxml2Recipe, self).get_recipe_env(arch)
44-
env["CONFIG_SHELL"] = "/bin/bash"
45-
env["SHELL"] = "/bin/bash"
46-
env[
47-
"CC"
48-
] = "arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer --sysroot={}".format(
49-
self.ctx.ndk_platform
50-
)
53+
env['CONFIG_SHELL'] = '/bin/bash'
54+
env['SHELL'] = '/bin/bash'
55+
env['CC'] += ' -I' + self.get_build_dir(arch.arch)
5156
return env
5257

5358

pythonforandroid/recipes/libxslt/__init__.py

+51Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,73 @@
1-
from pythonforandroid.toolchain import Recipe, shprint, shutil, current_directory
1+
from pythonforandroid.recipe import Recipe
2+
from pythonforandroid.toolchain import shprint, shutil, current_directory
23
from os.path import exists, join
34
import sh
45

56

67
class LibxsltRecipe(Recipe):
7-
version = "1.1.28"
8-
url = "http://xmlsoft.org/sources/libxslt-{version}.tar.gz"
9-
depends = ["libxml2"]
10-
patches = ["fix-dlopen.patch"]
8+
version = '1.1.32'
9+
url = 'http://xmlsoft.org/sources/libxslt-{version}.tar.gz'
10+
depends = ['libxml2']
11+
patches = ['fix-dlopen.patch']
1112

1213
call_hostpython_via_targetpython = False
1314

1415
def should_build(self, arch):
15-
super(LibxsltRecipe, self).should_build(arch)
16-
return not exists(join(self.ctx.get_libs_dir(arch.arch), "libxslt.a"))
16+
return not exists(
17+
join(self.get_build_dir(arch.arch),
18+
'libxslt', '.libs', 'libxslt.a'))
1719

1820
def build_arch(self, arch):
1921
super(LibxsltRecipe, self).build_arch(arch)
2022
env = self.get_recipe_env(arch)
21-
with current_directory(self.get_build_dir(arch.arch)):
23+
build_dir = self.get_build_dir(arch.arch)
24+
with current_directory(build_dir):
2225
# If the build is done with /bin/sh things blow up,
2326
# try really hard to use bash
24-
env["CC"] += " -I%s" % self.get_build_dir(arch.arch)
25-
libxml = Recipe.get_recipe(
26-
'libxml2', self.ctx).get_build_dir(arch.arch)
27-
shprint(
28-
sh.Command("./configure"),
29-
"--build=i686-pc-linux-gnu",
30-
"--host=arm-linux-eabi",
31-
"--without-plugins",
32-
"--without-debug",
33-
"--without-python",
34-
"--without-crypto",
35-
"--with-libxml-src=%s" % libxml,
36-
_env=env,
37-
)
27+
libxml2_recipe = Recipe.get_recipe('libxml2', self.ctx)
28+
libxml2_build_dir = libxml2_recipe.get_build_dir(arch.arch)
29+
build_arch = shprint(sh.gcc, '-dumpmachine').stdout.decode(
30+
'utf-8').split('\n')[0]
31+
32+
if not exists('configure'):
33+
shprint(sh.Command('./autogen.sh'), _env=env)
34+
shprint(sh.Command('autoreconf'), '-vif', _env=env)
35+
shprint(sh.Command('./configure'),
36+
'--build=' + build_arch,
37+
'--host=' + arch.command_prefix,
38+
'--target=' + arch.command_prefix,
39+
'--without-plugins',
40+
'--without-debug',
41+
'--without-python',
42+
'--without-crypto',
43+
'--with-libxml-src=' + libxml2_build_dir,
44+
'--disable-shared',
45+
_env=env)
3846
shprint(sh.make, "V=1", _env=env)
39-
shutil.copyfile(
40-
"libxslt/.libs/libxslt.a",
41-
join(self.ctx.get_libs_dir(arch.arch), "libxslt.a"),
42-
)
43-
shutil.copyfile(
44-
"libexslt/.libs/libexslt.a",
45-
join(self.ctx.get_libs_dir(arch.arch), "libexslt.a"),
46-
)
47+
48+
shutil.copyfile('libxslt/.libs/libxslt.a',
49+
join(self.ctx.libs_dir, 'libxslt.a'))
50+
shutil.copyfile('libexslt/.libs/libexslt.a',
51+
join(self.ctx.libs_dir, 'libexslt.a'))
4752

4853
def get_recipe_env(self, arch):
4954
env = super(LibxsltRecipe, self).get_recipe_env(arch)
50-
env["CONFIG_SHELL"] = "/bin/bash"
51-
env["SHELL"] = "/bin/bash"
52-
env[
53-
"CC"
54-
] = "arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer --sysroot={}".format(
55-
self.ctx.ndk_platform
56-
)
57-
58-
env["LDSHARED"] = "%s -nostartfiles -shared -fPIC" % env["CC"]
55+
env['CONFIG_SHELL'] = '/bin/bash'
56+
env['SHELL'] = '/bin/bash'
57+
58+
libxml2_recipe = Recipe.get_recipe('libxml2', self.ctx)
59+
libxml2_build_dir = libxml2_recipe.get_build_dir(arch.arch)
60+
libxml2_libs_dir = join(libxml2_build_dir, '.libs')
61+
62+
env['CFLAGS'] = ' '.join([
63+
env['CFLAGS'],
64+
'-I' + libxml2_build_dir,
65+
'-I' + join(libxml2_build_dir, 'include', 'libxml'),
66+
'-I' + self.get_build_dir(arch.arch),
67+
])
68+
env['LDFLAGS'] += ' -L' + libxml2_libs_dir
69+
env['LIBS'] = '-lxml2 -lz -lm'
70+
5971
return env
6072

6173

pythonforandroid/recipes/lxml/__init__.py

Lines changed: 67 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,82 @@
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
33
from os.path import exists, join
4-
from os import listdir
4+
from os import uname
5+
import sh
56

67

78
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'
1213

1314
call_hostpython_via_targetpython = False # Due to setuptools
1415

1516
def should_build(self, arch):
1617
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')
4642

4743
def get_recipe_env(self, arch):
4844
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(libxsl D40E t_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+
5580
return env
5681

5782

0 commit comments

Comments
 (0)
0