19
19
class DefaultTargetInfo (object ):
20
20
def __init__ (self , full_config ):
21
21
self .full_config = full_config
22
+ self .executor = None
22
23
23
24
def platform (self ):
24
25
return sys .platform .lower ().strip ()
@@ -50,39 +51,37 @@ def add_path(self, dest_env, new_path):
50
51
dest_env ['PATH' ] = '%s%s%s' % (new_path , split_char ,
51
52
dest_env ['PATH' ])
52
53
53
-
54
- def test_locale (loc ):
55
- assert loc is not None
56
- default_locale = locale .setlocale (locale .LC_ALL )
57
- try :
58
- locale .setlocale (locale .LC_ALL , loc )
59
- return True
60
- except locale .Error :
61
- return False
62
- finally :
63
- locale .setlocale (locale .LC_ALL , default_locale )
64
-
65
-
66
- def add_common_locales (features , lit_config , is_windows = False ):
67
- # A list of locales needed by the test-suite.
68
- # The list uses the canonical name for the locale used in the test-suite
69
- # TODO: On Linux ISO8859 *may* needs to hyphenated.
70
- locales = [
71
- ('en_US.UTF-8' , 'English_United States.1252' ),
72
- ('fr_FR.UTF-8' , 'French_France.1252' ),
73
- ('ru_RU.UTF-8' , 'Russian_Russia.1251' ),
74
- ('zh_CN.UTF-8' , 'Chinese_China.936' ),
75
- ('fr_CA.ISO8859-1' , 'French_Canada.1252' ),
76
- ('cs_CZ.ISO8859-2' , 'Czech_Czech Republic.1250' )
77
- ]
78
- for loc_id , windows_loc_name in locales :
79
- loc_name = windows_loc_name if is_windows else loc_id
80
- if test_locale (loc_name ):
81
- features .add ('locale.{0}' .format (loc_id ))
82
- else :
83
- lit_config .warning ('The locale {0} is not supported by '
84
- 'your platform. Some tests will be '
85
- 'unsupported.' .format (loc_name ))
54
+ def _test_locale (self , loc ):
55
+ assert loc is not None
56
+ default_locale = locale .setlocale (locale .LC_ALL )
57
+ try :
58
+ locale .setlocale (locale .LC_ALL , loc )
59
+ return True
60
+ except locale .Error :
61
+ return False
62
+ finally :
63
+ locale .setlocale (locale .LC_ALL , default_locale )
64
+
65
+ def add_common_locales (self , features , is_windows = False ):
66
+ # A list of locales needed by the test-suite.
67
+ # The list uses the canonical name for the locale used in the test-suite
68
+ # TODO: On Linux ISO8859 *may* needs to hyphenated.
69
+ locales = [
70
+ ('en_US.UTF-8' , 'English_United States.1252' ),
71
+ ('fr_FR.UTF-8' , 'French_France.1252' ),
72
+ ('ru_RU.UTF-8' , 'Russian_Russia.1251' ),
73
+ ('zh_CN.UTF-8' , 'Chinese_China.936' ),
74
+ ('fr_CA.ISO8859-1' , 'French_Canada.1252' ),
75
+ ('cs_CZ.ISO8859-2' , 'Czech_Czech Republic.1250' )
76
+ ]
77
+ for loc_id , windows_loc_name in locales :
78
+ loc_name = windows_loc_name if is_windows else loc_id
79
+ if self ._test_locale (loc_name ):
80
+ features .add ('locale.{0}' .format (loc_id ))
81
+ else :
82
+ self .full_config .lit_config .warning ('The locale {0} is not supported by '
83
+ 'your platform. Some tests will be '
84
+ 'unsupported.' .format (loc_name ))
86
85
87
86
88
87
class DarwinLocalTI (DefaultTargetInfo ):
@@ -136,7 +135,7 @@ def get_platform(self):
136
135
return (True , name , version )
137
136
138
137
def add_locale_features (self , features ):
139
- add_common_locales (features , self . full_config . lit_config )
138
+ self . add_common_locales (features )
140
139
141
140
def add_cxx_compile_flags (self , flags ):
142
141
if self .full_config .use_deployment :
@@ -182,7 +181,7 @@ def __init__(self, full_config):
182
181
super (FreeBSDLocalTI , self ).__init__ (full_config )
183
182
184
183
def add_locale_features (self , features ):
185
- add_common_locales (features , self . full_config . lit_config )
184
+ self . add_common_locales (features )
186
185
187
186
def add_cxx_link_flags (self , flags ):
188
187
flags += ['-lc' , '-lm' , '-lpthread' , '-lgcc_s' , '-lcxxrt' ]
@@ -193,7 +192,7 @@ def __init__(self, full_config):
193
192
super (NetBSDLocalTI , self ).__init__ (full_config )
194
193
195
194
def add_locale_features (self , features ):
196
- add_common_locales (features , self . full_config . lit_config )
195
+ self . add_common_locales (features )
197
196
198
197
def add_cxx_link_flags (self , flags ):
199
198
flags += ['-lc' , '-lm' , '-lpthread' , '-lgcc_s' , '-lc++abi' ,
@@ -220,7 +219,7 @@ def platform_ver(self):
220
219
return ver # Permitted to be None.
221
220
222
221
def add_locale_features (self , features ):
223
- add_common_locales (features , self . full_config . lit_config )
222
+ self . add_common_locales (features )
224
223
# Some linux distributions have different locale data than others.
225
224
# Insert the distributions name and name-version into the available
226
225
# features to allow tests to XFAIL on them.
@@ -268,14 +267,30 @@ def add_cxx_link_flags(self, flags):
268
267
# clang/lib/Driver/Tools.cpp
269
268
flags += ['-lpthread' , '-lrt' , '-lm' , '-ldl' ]
270
269
270
+ class LinuxRemoteTI (LinuxLocalTI ):
271
+ def __init__ (self , full_config ):
272
+ super (LinuxRemoteTI , self ).__init__ (full_config )
273
+ self .__cached_locales = None
274
+
275
+ def _test_locale (self , loc ):
276
+ if self .__cached_locales is None :
277
+ self .full_config .lit_config .note ('asking the remote host for supported locales...' )
278
+ _ , out , err , exit_code = self .executor .execute_command_remote (['locale' , '-a' ])
279
+ if exit_code != 0 :
280
+ raise RuntimeError (err )
281
+ self .__cached_locales = out .splitlines ()
282
+
283
+ # It is possible that the output will use 'en_US.utf8' instead of 'en_US.UTF-8',
284
+ # so we check both variants.
285
+ return loc in self .__cached_locales or \
286
+ loc .replace ('UTF-8' , 'utf8' ) in self .__cached_locales
271
287
272
288
class WindowsLocalTI (DefaultTargetInfo ):
273
289
def __init__ (self , full_config ):
274
290
super (WindowsLocalTI , self ).__init__ (full_config )
275
291
276
292
def add_locale_features (self , features ):
277
- add_common_locales (features , self .full_config .lit_config ,
278
- is_windows = True )
293
+ self .add_common_locales (features , is_windows = True )
279
294
280
295
def use_lit_shell_default (self ):
281
296
# Default to the internal shell on Windows, as bash on Windows is
0 commit comments