1
1
import sh
2
2
import os
3
- from os.path import join, isdir
4
- from pythonforandroid.recipe import NDKRecipe
3
+ from os.path import join, isdir, exists
4
+ from multiprocessing import cpu_count
5
+ from pythonforandroid.recipe import Recipe
5
6
from pythonforandroid.toolchain import shprint
6
7
from pythonforandroid.util import current_directory, ensure_dir
7
8
8
9
9
- class ICURecipe(NDKRecipe ):
10
+ class ICURecipe(Recipe ):
10
11
name = 'icu4c'
11
12
version = '57.1'
12
- url = 'http://download.icu-project.org/files/icu4c/57.1/icu4c-57_1-src.tgz'
13
+ major_version = version.split('.')[0]
14
+ url = ('http://download.icu-project.org/files/icu4c/'
15
+ '{version}/icu4c-{version_underscore}-src.tgz')
13
16
14
17
depends = [('hostpython2', 'hostpython3')] # installs in python
15
- generated_libraries = [
16
- 'libicui18n.so', 'libicuuc.so', 'libicudata.so', 'libicule.so']
17
-
18
- def get_lib_dir(self, arch):
19
- lib_dir = join(self.ctx.get_python_install_dir(), "lib")
20
- ensure_dir(lib_dir)
21
- return lib_dir
22
-
23
- def prepare_build_dir(self, arch):
24
- if self.ctx.android_api > 19:
25
- # greater versions do not have /usr/include/sys/exec_elf.h
26
- raise RuntimeError("icu needs an android api <= 19")
27
-
28
- super(ICURecipe, self).prepare_build_dir(arch)
29
-
30
- def build_arch(self, arch, *extra_args):
18
+ patches = ['disable-libs-version.patch']
19
+
20
+ built_libraries = {
21
+ 'libicui18n{}.so'.format(major_version): 'build_icu_android/lib',
22
+ 'libicuuc{}.so'.format(major_version): 'build_icu_android/lib',
23
+ 'libicudata{}.so'.format(major_version): 'build_icu_android/lib',
24
+ 'libicule{}.so'.format(major_version): 'build_icu_android/lib',
25
+ 'libicuio{}.so'.format(major_version): 'build_icu_android/lib',
26
+ 'libicutu{}.so'.format(major_version): 'build_icu_android/lib',
27
+ 'libiculx{}.so'.format(major_version): 'build_icu_android/lib',
28
+ }
29
+ need_stl_shared = True
30
+
31
+ @property
32
+ def versioned_url(self):
33
+ if self.url is None:
34
+ return None
35
+ return self.url.format(
36
+ version=self.version,
37
+ version_underscore=self.version.replace('.', '_'))
38
+
39
+ def get_recipe_dir(self):
40
+ """
41
+ .. note:: We need to overwrite `Recipe.get_recipe_dir` due to the
42
+ mismatch name between the recipe's folder (icu) and the value
43
+ of `ICURecipe.name` (icu4c).
44
+ """
45
+ if self.ctx.local_recipes is not None:
46
+ local_recipe_dir = join(self.ctx.local_recipes, 'icu')
47
+ if exists(local_recipe_dir):
48
+ return local_recipe_dir
49
+ return join(self.ctx.root_dir, 'recipes', 'icu')
50
+
51
+ def do_build_libs(self, arch):
31
52
env = self.get_recipe_env(arch).copy()
32
53
build_root = self.get_build_dir(arch.arch)
33
54
@@ -60,74 +81,35 @@ def make_build_dest(dest):
60
81
"--prefix="+icu_build,
61
82
"--enable-extras=no",
62
83
"--enable-strict=no",
63
- "--enable-static",
84
+ "--enable-static=no ",
64
85
"--enable-tests=no",
65
86
"--enable-samples=no",
66
87
_env=host_env)
67
- shprint(sh.make, "-j5" , _env=host_env)
88
+ shprint(sh.make, "-j", str(cpu_count()) , _env=host_env)
68
89
shprint(sh.make, "install", _env=host_env)
69
90
70
91
build_android, exists = make_build_dest("build_icu_android")
71
92
if not exists:
72
93
73
94
configure = sh.Command(join(build_root, "source", "configure"))
74
95
75
- include = (
76
- " -I{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/include/"
77
- " -I{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/libs/"
78
- "{arch}/include")
79
- include = include.format(ndk=self.ctx.ndk_dir,
80
- version=env["TOOLCHAIN_VERSION"],
81
- arch=arch.arch)
82
- env["CPPFLAGS"] = env["CXXFLAGS"] + " "
83
- env["CPPFLAGS"] += host_env["CPPFLAGS"]
84
- env["CPPFLAGS"] += include
85
-
86
- lib = "{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/libs/{arch}"
87
- lib = lib.format(ndk=self.ctx.ndk_dir,
88
- version=env["TOOLCHAIN_VERSION"],
89
- arch=arch.arch)
90
- env["LDFLAGS"] += " -lgnustl_shared -L"+lib
91
-
92
- env.pop("CFLAGS", None)
93
- env.pop("CXXFLAGS", None)
94
-
95
96
with current_directory(build_android):
96
97
shprint(
97
98
configure,
98
99
"--with-cross-build="+build_linux,
99
100
"--enable-extras=no",
100
101
"--enable-strict=no",
101
- "--enable-static",
102
+ "--enable-static=no ",
102
103
"--enable-tests=no",
103
104
"--enable-samples=no",
104
105
"--host="+env["TOOLCHAIN_PREFIX"],
105
106
"--prefix="+icu_build,
106
107
_env=env)
107
- shprint(sh.make, "-j5" , _env=env)
108
+ shprint(sh.make, "-j", str(cpu_count()) , _env=env)
108
109
shprint(sh.make, "install", _env=env)
109
110
110
- self.copy_files(arch)
111
-
112
- def copy_files(self, arch):
113
- env = self.get_recipe_env(arch)
114
-
115
- lib = "{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/libs/{arch}"
116
- lib = lib.format(ndk=self.ctx.ndk_dir,
117
- version=env["TOOLCHAIN_VERSION"],
118
- arch=arch.arch)
119
- stl_lib = join(lib, "libgnustl_shared.so")
120
- dst_dir = join(self.ctx.get_site_packages_dir(), "..", "lib-dynload")
121
- shprint(sh.cp, stl_lib, dst_dir)
122
-
123
- src_lib = join(self.get_build_dir(arch.arch), "icu_build", "lib")
124
- dst_lib = self.get_lib_dir(arch)
125
-
126
- src_suffix = "." + self.version
127
- dst_suffix = "." + self.version.split(".")[0] # main version
128
- for lib in self.generated_libraries:
129
- shprint(sh.cp, join(src_lib, lib+src_suffix),
130
- join(dst_lib, lib+dst_suffix))
111
+ def do_install_libs(self, arch):
112
+ super(ICURecipe, self).do_install_libs(arch)
131
113
132
114
src_include = join(
133
115
self.get_build_dir(arch.arch), "icu_build", "include")
@@ -137,16 +119,5 @@ def copy_files(self, arch):
137
119
shprint(sh.cp, "-r", join(src_include, "layout"), dst_include)
138
120
shprint(sh.cp, "-r", join(src_include, "unicode"), dst_include)
139
121
140
- # copy stl library
141
- lib = "{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/libs/{arch}"
142
- lib = lib.format(ndk=self.ctx.ndk_dir,
143
- version=env["TOOLCHAIN_VERSION"],
144
- arch=arch.arch)
145
- stl_lib = join(lib, "libgnustl_shared.so")
146
-
147
- dst_dir = join(self.ctx.get_python_install_dir(), "lib")
148
- ensure_dir(dst_dir)
149
- shprint(sh.cp, stl_lib, dst_dir)
150
-
151
122
152
123
recipe = ICURecipe()
0 commit comments