Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -44,6 +44,8 @@ pythonize_bool(LIBCXX_BUILD_32_BITS) pythonize_bool(LIBCXX_ENABLE_THREADS) pythonize_bool(LIBCXX_ENABLE_MONOTONIC_CLOCK) + set(LIBCXX_TARGET_INFO "None" CACHE STRING + "TargetInfo to use when setting up test environment.") set(AUTO_GEN_COMMENT "## Autogenerated by libcxx configuration.\n# Do not edit!") Index: libcxx/test/config.py =================================================================== --- libcxx/test/config.py +++ libcxx/test/config.py @@ -11,7 +11,7 @@ from libcxx.test.format import LibcxxTestFormat from libcxx.compiler import CXXCompiler - +from libcxx.test.target_info import * def loadSiteConfig(lit_config, config, param_name, env_name): # We haven't loaded the site specific configuration (the user is @@ -57,9 +57,6 @@ self.long_tests = None self.execute_external = False - if platform.system() not in ('Darwin', 'FreeBSD', 'Linux'): - self.lit_config.fatal("unrecognized system") - def get_lit_conf(self, name, default=None): val = self.lit_config.params.get(name, None) if val is None: @@ -80,6 +77,7 @@ "parameter '{}' should be true or false".format(name)) def configure(self): + self.configure_target_info() self.configure_cxx() self.configure_triple() self.configure_src_root() @@ -109,6 +107,14 @@ list(self.config.available_features)) self.lit_config.note('Using environment: %r' % self.env) + def configure_target_info(self): + info_str = self.get_lit_conf('target_info', "None") + self.target_info = eval(info_str) + if self.target_info: + self.lit_config.note("inferred target_info as: %r" % info_str) + else: + self.target_info = LocalTI() + def get_test_format(self): return LibcxxTestFormat( self.cxx, @@ -237,8 +243,11 @@ }, } + target_system = self.target_info.system() + target_platform = self.target_info.platform() + default_locale = locale.setlocale(locale.LC_ALL) - for feature, loc in locales[platform.system()].items(): + for feature, loc in locales[target_system].items(): try: locale.setlocale(locale.LC_ALL, loc) self.config.available_features.add( @@ -258,20 +267,14 @@ 'with_system_cxx_lib=%s' % self.config.target_triple) # Insert the platform name into the available features as a lower case. - # Strip the '2' from linux2. - if sys.platform.startswith('linux'): - platform_name = 'linux' - else: - platform_name = sys.platform - self.config.available_features.add(platform_name.lower()) + self.config.available_features.add(target_platform) # Some linux distributions have different locale data than others. # Insert the distributions name and name-version into the available # features to allow tests to XFAIL on them. - if sys.platform.startswith('linux'): - name, ver, _ = platform.linux_distribution() - name = name.lower().strip() - ver = ver.lower().strip() + if target_platform == 'linux': + name = self.target_info.platform_name() + ver = self.target_info.platform_ver() if name: self.config.available_features.add(name) if name and ver: @@ -439,9 +442,10 @@ def configure_extra_library_flags(self): enable_threads = self.get_lit_bool('enable_threads', True) llvm_unwinder = self.get_lit_bool('llvm_unwinder', False) - if sys.platform == 'darwin': + target_platform = self.target_info.platform() + if target_platform == 'darwin': self.cxx.link_flags += ['-lSystem'] - elif sys.platform.startswith('linux'): + elif target_platform == 'linux': if not llvm_unwinder: self.cxx.link_flags += ['-lgcc_eh'] self.cxx.link_flags += ['-lc', '-lm'] @@ -452,10 +456,10 @@ self.cxx.link_flags += ['-lunwind', '-ldl'] else: self.cxx.link_flags += ['-lgcc_s'] - elif sys.platform.startswith('freebsd'): + elif target_platform.startswith('freebsd'): self.cxx.link_flags += ['-lc', '-lm', '-lpthread', '-lgcc_s'] else: - self.lit_config.fatal("unrecognized system: %r" % sys.platform) + self.lit_config.fatal("unrecognized system: %r" % target_platform) def configure_warnings(self): enable_warnings = self.get_lit_bool('enable_warnings', False) @@ -480,7 +484,7 @@ symbolizer_search_paths) # Setup the sanitizer compile flags self.cxx.flags += ['-g', '-fno-omit-frame-pointer'] - if sys.platform.startswith('linux'): + if self.target_info.platform() == 'linux': self.cxx.link_flags += ['-ldl'] if san == 'Address': self.cxx.flags += ['-fsanitize=address'] Index: libcxx/test/target_info.py =================================================================== --- libcxx/test/target_info.py +++ libcxx/test/target_info.py @@ -0,0 +1,55 @@ +import locale +import platform +import sys + +class TargetInfo(object): + def platform(self): + raise NotImplementedError + + def system(self): + raise NotImplementedError + + def platform_ver(self): + raise NotImplementedError + + def platform_name(self): + raise NotImplementedError + + def supports_locale(self, loc): + raise NotImplementedError + + +class LocalTI(TargetInfo): + def platform(self): + platform_name = sys.platform.lower().strip() + # Strip the '2' from linux2. + if platform_name.startswith('linux'): + platform_name = 'linux' + return platform_name + + def system(self): + return platform.system() + + def platform_name(self): + if platform() == 'linux': + name, _, _ = platform.linux_distribution() + name = name.lower().strip() + if name: + return name + return None + + def platform_ver(self): + if platform() == 'linux': + _, ver, _ = platform.linux_distribution() + ver = ver.lower().strip() + if ver: + return ver + return None + + def supports_locale(self, loc): + try: + locale.setlocale(locale.LC_ALL, loc) + return True + except locale.Error: + return False + Index: lit.site.cfg.in =================================================================== --- lit.site.cfg.in +++ lit.site.cfg.in @@ -17,6 +17,7 @@ config.target_triple = "@LIBCXX_TARGET_TRIPLE@" config.sysroot = "@LIBCXX_SYSROOT@" config.gcc_toolchain = "@LIBCXX_GCC_TOOLCHAIN@" +config.target_info = "@LIBCXX_TARGET_INFO@" # Let the main config do the real work. lit_config.load_config(config, "@LIBCXX_SOURCE_DIR@/test/lit.cfg")