forked from bincrafters/conan-icu
-
Notifications
You must be signed in to change notification settings - Fork 3
/
icu_base.py
executable file
·209 lines (179 loc) · 9.31 KB
/
icu_base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# -*- coding: utf-8 -*-
import os
import glob
import platform
from conans import ConanFile, tools, AutoToolsBuildEnvironment
class ICUBase(ConanFile):
version = "64.2"
homepage = "http://site.icu-project.org"
license = "ICU"
description = "ICU is a mature, widely used set of C/C++ and Java libraries " \
"providing Unicode and Globalization support for software applications."
url = "https://github.com/bincrafters/conan-icu"
topics = ("conan", "icu", "icu4c", "i see you", "unicode")
author = "Bincrafters <[email protected]>"
exports = ["LICENSE.md", "icu_base.py"]
# exports_sources = ["patches/*.patch"]
_source_subfolder = "source_subfolder"
_build_subfolder = "build_subfolder"
_env_build = None
short_paths = True
@property
def _the_os(self):
return self.settings.get_safe("os") or self.settings.get_safe("os_build")
@property
def _the_arch(self):
return self.settings.get_safe("arch") or self.settings.get_safe("arch_build")
@property
def _is_msvc(self):
return self.settings.compiler == "Visual Studio"
@property
def _is_mingw(self):
return self._the_os == "Windows" and self.settings.compiler == "gcc"
def build_requirements(self):
if self._the_os == "Windows":
#self.build_requires("cygwin_installer/2.9.0@bincrafters/stable")
self.build_requires("msys2_installer/latest@bincrafters/stable")
if self.settings.compiler == "gcc" and tools.os_info.is_windows:
self.build_requires("mingw_installer/1.0@conan/stable")
def source(self):
version = self.version.replace('.', '-')
version_with_underscore = self.version.replace('.', '_')
source_url = "https://github.com/unicode-org/icu/releases/download/release-{0}/icu4c-{1}-src.tgz".format(version, version_with_underscore)
self.output.info("Downloading {0} ...".format(source_url))
tools.get(source_url,
sha256="627d5d8478e6d96fc8c90fed4851239079a561a6a8b9e48b0892f24e82d31d6c")
os.rename("icu", self._source_subfolder)
def _replace_pythonpath(self):
if self._is_msvc:
srcdir = os.path.join(self.build_folder, self._source_subfolder, "source")
configure = os.path.join(self._source_subfolder, "source", "configure")
tools.replace_in_file(configure,
'PYTHONPATH="$srcdir/data"',
'PYTHONPATH="%s\\data"' % srcdir)
tools.replace_in_file(configure,
'PYTHONPATH="$srcdir/test/testdata:$srcdir/data"',
'PYTHONPATH="%s\\test\\testdata;%s\\data"' % (srcdir, srcdir))
def _workaround_icu_20545(self):
if tools.os_info.is_windows:
# https://unicode-org.atlassian.net/projects/ICU/issues/ICU-20545
srcdir = os.path.join(self.build_folder, self._source_subfolder, "source")
makeconv_cpp = os.path.join(srcdir, "tools", "makeconv", "makeconv.cpp")
tools.replace_in_file(makeconv_cpp,
"pathBuf.appendPathPart(arg, localError);",
"pathBuf.append('/', localError); pathBuf.append(arg, localError);")
def build(self):
for filename in glob.glob("patches/*.patch"):
self.output.info('applying patch "%s"' % filename)
tools.patch(base_path=self._source_subfolder, patch_file=filename)
if self._is_msvc:
run_configure_icu_file = os.path.join(self._source_subfolder, 'source', 'runConfigureICU')
flags = "-%s" % self.settings.compiler.runtime
if self.settings.get_safe("build_type") == 'Debug':
flags += " -FS"
tools.replace_in_file(run_configure_icu_file, "-MDd", flags)
tools.replace_in_file(run_configure_icu_file, "-MD", flags)
self._replace_pythonpath() # ICU 64.1
self._workaround_icu_20545()
self._env_build = AutoToolsBuildEnvironment(self)
if not self.options.get_safe("shared"):
self._env_build.defines.append("U_STATIC_IMPLEMENTATION")
if tools.is_apple_os(self._the_os):
self._env_build.defines.append("_DARWIN_C_SOURCE")
if self.settings.get_safe("os.version"):
self._env_build.flags.append(tools.apple_deployment_target_flag(self._the_os,
self.settings.os.version))
build_dir = os.path.join(self.build_folder, self._source_subfolder, 'build')
os.mkdir(build_dir)
with tools.vcvars(self.settings) if self._is_msvc else tools.no_op():
with tools.environment_append(self._env_build.vars):
with tools.chdir(build_dir):
# workaround for https://unicode-org.atlassian.net/browse/ICU-20531
os.makedirs(os.path.join("data", "out", "tmp"))
self.run(self._build_config_cmd, win_bash=tools.os_info.is_windows)
if self.options.get_safe("silent"):
silent = '--silent' if self.options.silent else 'VERBOSE=1'
else:
silent = '--silent'
command = "make {silent} -j {cpu_count}".format(silent=silent,
cpu_count=tools.cpu_count())
self.run(command, win_bash=tools.os_info.is_windows)
if self.options.get_safe("with_unit_tests"):
command = "make {silent} check".format(silent=silent)
self.run(command, win_bash=tools.os_info.is_windows)
command = "make {silent} install".format(silent=silent)
self.run(command, win_bash=tools.os_info.is_windows)
self._install_name_tool()
def package(self):
self.copy("LICENSE", dst="licenses", src=os.path.join(self.source_folder, self._source_subfolder))
@staticmethod
def detected_os():
if tools.OSInfo().is_macos:
return "Macos"
if tools.OSInfo().is_windows:
return "Windows"
return platform.system()
@property
def cross_building(self):
if tools.cross_building(self.settings):
if self._the_os == self.detected_os():
if self._the_arch == "x86" and tools.detected_architecture() == "x86_64":
return False
return True
return False
@property
def build_config_args(self):
prefix = self.package_folder.replace('\\', '/')
platform = {("Windows", "Visual Studio"): "Cygwin/MSVC",
("Windows", "gcc"): "MinGW",
("AIX", "gcc"): "AIX/GCC",
("AIX", "xlc"): "AIX",
("SunOS", "gcc"): "Solaris/GCC",
("Linux", "gcc"): "Linux/gcc",
("Linux", "clang"): "Linux",
("Macos", "gcc"): "MacOSX",
("Macos", "clang"): "MacOSX",
("Macos", "apple-clang"): "MacOSX"}.get((str(self._the_os),
str(self.settings.compiler)))
arch64 = ['x86_64', 'sparcv9', 'ppc64']
bits = "64" if self._the_arch in arch64 else "32"
args = [platform,
"--prefix={0}".format(prefix),
"--with-library-bits={0}".format(bits),
"--disable-samples",
"--disable-layout",
"--disable-layoutex"]
if self.cross_building:
if self._env_build.build:
args.append("--build=%s" % self._env_build.build)
if self._env_build.host:
args.append("--host=%s" % self._env_build.host)
if self._env_build.target:
args.append("--target=%s" % self._env_build.target)
if self.options.get_safe("data_packaging"):
args.append("--with-data-packaging={0}".format(self.options.data_packaging))
else:
args.append("--with-data-packaging=static")
if self._is_mingw:
mingw_chost = 'i686-w64-mingw32' if self._the_arch == 'x86' else 'x86_64-w64-mingw32'
args.extend(["--build={0}".format(mingw_chost),
"--host={0}".format(mingw_chost)])
if self.settings.get_safe("build_type") == "Debug":
args.extend(["--disable-release", "--enable-debug"])
if self.options.get_safe("shared"):
args.extend(["--disable-static", "--enable-shared"])
else:
args.extend(["--enable-static", "--disable-shared"])
if not self.options.get_safe("with_unit_tests"):
args.append('--disable-tests')
return args
@property
def _build_config_cmd(self):
return "../source/runConfigureICU %s" % " ".join(self.build_config_args)
def _install_name_tool(self):
if tools.is_apple_os(self._the_os):
with tools.chdir(os.path.join(self.package_folder, 'lib')):
for dylib in glob.glob('*icu*.{0}.dylib'.format(self.version)):
command = 'install_name_tool -id {0} {1}'.format(os.path.basename(dylib), dylib)
self.output.info(command)
self.run(command)