1
- import importlib
2
1
import locale
3
2
import os
4
3
import platform
12
11
13
12
from libcxx .test .format import LibcxxTestFormat
14
13
from libcxx .compiler import CXXCompiler
14
+ from libcxx .test .target_info import make_target_info
15
15
from libcxx .test .executor import *
16
16
from libcxx .test .tracing import *
17
17
@@ -42,22 +42,6 @@ def prevent_reload_fn(*args, **kwargs):
42
42
ld_fn (config , site_cfg )
43
43
lit_config .load_config = ld_fn
44
44
45
- def getSysrootFlagsOnDarwin (config , lit_config ):
46
- # On Darwin, support relocatable SDKs by providing Clang with a
47
- # default system root path.
48
- if 'darwin' in config .target_triple :
49
- try :
50
- out = lit .util .capture (['xcrun' , '--show-sdk-path' ]).strip ()
51
- res = 0
52
- except OSError :
53
- res = - 1
54
- if res == 0 and out :
55
- sdk_path = out
56
- lit_config .note ('using SDKROOT: %r' % sdk_path )
57
- return ["-isysroot" , sdk_path ]
58
- return []
59
-
60
-
61
45
class Configuration (object ):
62
46
# pylint: disable=redefined-outer-name
63
47
def __init__ (self , lit_config , config ):
@@ -157,13 +141,7 @@ def configure_executor(self):
157
141
self .executor = te
158
142
159
143
def configure_target_info (self ):
160
- default = "libcxx.test.target_info.LocalTI"
161
- info_str = self .get_lit_conf ('target_info' , default )
162
- mod_path , _ , info = info_str .rpartition ('.' )
163
- mod = importlib .import_module (mod_path )
164
- self .target_info = getattr (mod , info )()
165
- if info_str != default :
166
- self .lit_config .note ("inferred target_info as: %r" % info_str )
144
+ self .target_info = make_target_info (self )
167
145
168
146
def configure_cxx (self ):
169
147
# Gather various compiler parameters.
@@ -234,13 +212,12 @@ def configure_use_clang_verify(self):
234
212
def configure_execute_external (self ):
235
213
# Choose between lit's internal shell pipeline runner and a real shell.
236
214
# If LIT_USE_INTERNAL_SHELL is in the environment, we use that as the
237
- # default value. Otherwise we default to internal on Windows and
238
- # external elsewhere, as bash on Windows is usually very slow.
215
+ # default value. Otherwise we ask the target_info.
239
216
use_lit_shell_default = os .environ .get ('LIT_USE_INTERNAL_SHELL' )
240
217
if use_lit_shell_default is not None :
241
218
use_lit_shell_default = use_lit_shell_default != '0'
242
219
else :
243
- use_lit_shell_default = sys . platform == 'win32'
220
+ use_lit_shell_default = self . target_info . use_lit_shell_default ()
244
221
# Check for the command line parameter using the default value if it is
245
222
# not present.
246
223
use_lit_shell = self .get_lit_bool ('use_lit_shell' ,
@@ -259,63 +236,10 @@ def configure_features(self):
259
236
if additional_features :
260
237
for f in additional_features .split (',' ):
261
238
self .config .available_features .add (f .strip ())
239
+ self .target_info .add_locale_features (self .config .available_features )
262
240
263
- # Figure out which of the required locales we support
264
- locales = {
265
- 'Darwin' : {
266
- 'en_US.UTF-8' : 'en_US.UTF-8' ,
267
- 'cs_CZ.ISO8859-2' : 'cs_CZ.ISO8859-2' ,
268
- 'fr_FR.UTF-8' : 'fr_FR.UTF-8' ,
269
- 'fr_CA.ISO8859-1' : 'fr_CA.ISO8859-1' ,
270
- 'ru_RU.UTF-8' : 'ru_RU.UTF-8' ,
271
- 'zh_CN.UTF-8' : 'zh_CN.UTF-8' ,
272
- },
273
- 'FreeBSD' : {
274
- 'en_US.UTF-8' : 'en_US.UTF-8' ,
275
- 'cs_CZ.ISO8859-2' : 'cs_CZ.ISO8859-2' ,
276
- 'fr_FR.UTF-8' : 'fr_FR.UTF-8' ,
277
- 'fr_CA.ISO8859-1' : 'fr_CA.ISO8859-1' ,
278
- 'ru_RU.UTF-8' : 'ru_RU.UTF-8' ,
279
- 'zh_CN.UTF-8' : 'zh_CN.UTF-8' ,
280
- },
281
- 'Linux' : {
282
- 'en_US.UTF-8' : 'en_US.UTF-8' ,
283
- 'cs_CZ.ISO8859-2' : 'cs_CZ.ISO-8859-2' ,
284
- 'fr_FR.UTF-8' : 'fr_FR.UTF-8' ,
285
- 'fr_CA.ISO8859-1' : 'fr_CA.ISO-8859-1' ,
286
- 'ru_RU.UTF-8' : 'ru_RU.UTF-8' ,
287
- 'zh_CN.UTF-8' : 'zh_CN.UTF-8' ,
288
- },
289
- 'Windows' : {
290
- 'en_US.UTF-8' : 'English_United States.1252' ,
291
- 'cs_CZ.ISO8859-2' : 'Czech_Czech Republic.1250' ,
292
- 'fr_FR.UTF-8' : 'French_France.1252' ,
293
- 'fr_CA.ISO8859-1' : 'French_Canada.1252' ,
294
- 'ru_RU.UTF-8' : 'Russian_Russia.1251' ,
295
- 'zh_CN.UTF-8' : 'Chinese_China.936' ,
296
- },
297
- }
298
-
299
- target_system = self .target_info .system ()
300
241
target_platform = self .target_info .platform ()
301
242
302
- if target_system in locales :
303
- default_locale = locale .setlocale (locale .LC_ALL )
304
- for feature , loc in locales [target_system ].items ():
305
- try :
306
- locale .setlocale (locale .LC_ALL , loc )
307
- self .config .available_features .add (
308
- 'locale.{0}' .format (feature ))
309
- except locale .Error :
310
- self .lit_config .warning ('The locale {0} is not supported by '
311
- 'your platform. Some tests will be '
312
- 'unsupported.' .format (loc ))
313
- locale .setlocale (locale .LC_ALL , default_locale )
314
- else :
315
- # Warn that the user doesn't get any free XFAILs for locale issues
316
- self .lit_config .warning ("No locales entry for target_system: %s" %
317
- target_system )
318
-
319
243
# Write an "available feature" that combines the triple when
320
244
# use_system_cxx_lib is enabled. This is so that we can easily write
321
245
# XFAIL markers for tests that are known to fail with versions of
@@ -327,17 +251,6 @@ def configure_features(self):
327
251
# Insert the platform name into the available features as a lower case.
328
252
self .config .available_features .add (target_platform )
329
253
330
- # Some linux distributions have different locale data than others.
331
- # Insert the distributions name and name-version into the available
332
- # features to allow tests to XFAIL on them.
333
- if target_platform == 'linux' :
334
- name = self .target_info .platform_name ()
335
- ver = self .target_info .platform_ver ()
336
- if name :
337
- self .config .available_features .add (name )
338
- if name and ver :
339
- self .config .available_features .add ('%s-%s' % (name , ver ))
340
-
341
254
# Simulator testing can take a really long time for some of these tests
342
255
# so add a feature check so we can REQUIRES: long_tests in them
343
256
self .long_tests = self .get_lit_bool ('long_tests' )
@@ -362,8 +275,6 @@ def configure_compile_flags(self):
362
275
# Configure extra flags
363
276
compile_flags_str = self .get_lit_conf ('compile_flags' , '' )
364
277
self .cxx .compile_flags += shlex .split (compile_flags_str )
365
- sysroot_flags = getSysrootFlagsOnDarwin (self .config , self .lit_config )
366
- self .cxx .compile_flags .extend (sysroot_flags )
367
278
368
279
def configure_default_compile_flags (self ):
369
280
# Try and get the std version from the command line. Fall back to
@@ -388,10 +299,7 @@ def configure_default_compile_flags(self):
388
299
# Configure include paths
389
300
self .cxx .compile_flags += ['-nostdinc++' ]
390
301
self .configure_compile_flags_header_includes ()
391
- if self .target_info .platform () == 'linux' :
392
- self .cxx .compile_flags += ['-D__STDC_FORMAT_MACROS' ,
393
- '-D__STDC_LIMIT_MACROS' ,
394
- '-D__STDC_CONSTANT_MACROS' ]
302
+ self .target_info .add_cxx_compile_flags (self .cxx .compile_flags )
395
303
# Configure feature flags.
396
304
self .configure_compile_flags_exceptions ()
397
305
self .configure_compile_flags_rtti ()
@@ -552,9 +460,7 @@ def configure_link_flags_abi_library(self):
552
460
elif cxx_abi == 'libsupc++' :
553
461
self .cxx .link_flags += ['-lsupc++' ]
554
462
elif cxx_abi == 'libcxxabi' :
555
- # Don't link libc++abi explicitly on OS X because the symbols
556
- # should be available in libc++ directly.
557
- if self .target_info .platform () != 'darwin' :
463
+ if self .target_info .allow_cxxabi_link ():
558
464
self .cxx .link_flags += ['-lc++abi' ]
559
465
elif cxx_abi == 'libcxxrt' :
560
466
self .cxx .link_flags += ['-lcxxrt' ]
@@ -565,27 +471,7 @@ def configure_link_flags_abi_library(self):
565
471
'C++ ABI setting %s unsupported for tests' % cxx_abi )
566
472
567
473
def configure_extra_library_flags (self ):
568
- enable_threads = ('libcpp-has-no-threads' not in
569
- self .config .available_features )
570
- llvm_unwinder = self .get_lit_bool ('llvm_unwinder' , False )
571
- target_platform = self .target_info .platform ()
572
- if target_platform == 'darwin' :
573
- self .cxx .link_flags += ['-lSystem' ]
574
- elif target_platform == 'linux' :
575
- self .cxx .link_flags += ['-lm' ]
576
- if not llvm_unwinder :
577
- self .cxx .link_flags += ['-lgcc_s' , '-lgcc' ]
578
- if enable_threads :
579
- self .cxx .link_flags += ['-lpthread' ]
580
- self .cxx .link_flags += ['-lc' ]
581
- if llvm_unwinder :
582
- self .cxx .link_flags += ['-lunwind' , '-ldl' ]
583
- else :
584
- self .cxx .link_flags += ['-lgcc_s' , '-lgcc' ]
585
- elif target_platform .startswith ('freebsd' ):
586
- self .cxx .link_flags += ['-lc' , '-lm' , '-lpthread' , '-lgcc_s' , '-lcxxrt' ]
587
- else :
588
- self .lit_config .fatal ("unrecognized system: %r" % target_platform )
474
+ self .target_info .add_cxx_link_flags (self .cxx .link_flags )
589
475
590
476
def configure_color_diagnostics (self ):
591
477
use_color = self .get_lit_conf ('color_diagnostics' )
@@ -639,6 +525,7 @@ def configure_warnings(self):
639
525
def configure_sanitizer (self ):
640
526
san = self .get_lit_conf ('use_sanitizer' , '' ).strip ()
641
527
if san :
528
+ self .target_info .add_sanitizer_features (san , self .config .available_features )
642
529
# Search for llvm-symbolizer along the compiler path first
643
530
# and then along the PATH env variable.
644
531
symbolizer_search_paths = os .environ .get ('PATH' , '' )
@@ -651,11 +538,6 @@ def configure_sanitizer(self):
651
538
symbolizer_search_paths )
652
539
# Setup the sanitizer compile flags
653
540
self .cxx .flags += ['-g' , '-fno-omit-frame-pointer' ]
654
- if self .target_info .platform () == 'linux' :
655
- # The libraries and their order are taken from the
656
- # linkSanitizerRuntimeDeps function in
657
- # clang/lib/Driver/Tools.cpp
658
- self .cxx .link_flags += ['-lpthread' , '-lrt' , '-lm' , '-ldl' ]
659
541
if san == 'Address' :
660
542
self .cxx .flags += ['-fsanitize=address' ]
661
543
if llvm_symbolizer is not None :
@@ -677,8 +559,6 @@ def configure_sanitizer(self):
677
559
'-fno-sanitize-recover' ]
678
560
self .cxx .compile_flags += ['-O3' ]
679
561
self .config .available_features .add ('ubsan' )
680
- if self .target_info .platform () == 'darwin' :
681
- self .config .available_features .add ('sanitizer-new-delete' )
682
562
elif san == 'Thread' :
683
563
self .cxx .flags += ['-fsanitize=thread' ]
684
564
self .config .available_features .add ('tsan' )
@@ -762,18 +642,4 @@ def configure_triple(self):
762
642
"inferred target_triple as: %r" % self .config .target_triple )
763
643
764
644
def configure_env (self ):
765
- if self .target_info .platform () == 'darwin' :
766
- library_paths = []
767
- # Configure the library path for libc++
768
- libcxx_library = self .get_lit_conf ('libcxx_library' )
769
- if self .use_system_cxx_lib :
770
- pass
771
- elif libcxx_library :
772
- library_paths += [os .path .dirname (libcxx_library )]
773
- elif self .cxx_library_root :
774
- library_paths += [self .cxx_library_root ]
775
- # Configure the abi library path
776
- if self .abi_library_root :
777
- library_paths += [self .abi_library_root ]
778
- if library_paths :
779
- self .env ['DYLD_LIBRARY_PATH' ] = ':' .join (library_paths )
645
+ self .target_info .configure_env (self .env )
0 commit comments