[libcxx-commits] [libcxx] 3864ee7 - [libc++] Translate locale detection to the DSL
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jun 5 06:50:13 PDT 2020
Author: Louis Dionne
Date: 2020-06-05T09:50:00-04:00
New Revision: 3864ee7722f7c3ae93801bc0ad4d4a3303ded0f5
URL: https://github.com/llvm/llvm-project/commit/3864ee7722f7c3ae93801bc0ad4d4a3303ded0f5
DIFF: https://github.com/llvm/llvm-project/commit/3864ee7722f7c3ae93801bc0ad4d4a3303ded0f5.diff
LOG: [libc++] Translate locale detection to the DSL
Added:
Modified:
libcxx/utils/libcxx/test/config.py
libcxx/utils/libcxx/test/features.py
libcxx/utils/libcxx/test/target_info.py
Removed:
################################################################################
diff --git a/libcxx/utils/libcxx/test/config.py b/libcxx/utils/libcxx/test/config.py
index 11f2cb1edab1..22ec6c457e56 100644
--- a/libcxx/utils/libcxx/test/config.py
+++ b/libcxx/utils/libcxx/test/config.py
@@ -7,7 +7,6 @@
#===----------------------------------------------------------------------===##
import copy
-import locale
import os
import platform
import pkgutil
@@ -283,7 +282,6 @@ def configure_features(self):
if additional_features:
for f in additional_features.split(','):
self.config.available_features.add(f.strip())
- self.target_info.add_locale_features(self.config.available_features)
# Write an "available feature" that combines the triple when
# use_system_cxx_lib is enabled. This is so that we can easily write
diff --git a/libcxx/utils/libcxx/test/features.py b/libcxx/utils/libcxx/test/features.py
index 6d30a096da87..d00866df9aaa 100644
--- a/libcxx/utils/libcxx/test/features.py
+++ b/libcxx/utils/libcxx/test/features.py
@@ -90,3 +90,21 @@
)
)
]
+
+
+# Mapping from canonical locale names (used in the tests) to possible locale
+# names on various systems. Each locale is considered supported if any of the
+# alternative names is supported.
+locales = {
+ 'en_US.UTF-8': ['en_US.UTF-8', 'en_US.utf8', 'English_United States.1252'],
+ 'fr_FR.UTF-8': ['fr_FR.UTF-8', 'fr_FR.utf8', 'French_France.1252'],
+ 'ru_RU.UTF-8': ['ru_RU.UTF-8', 'ru_RU.utf8', 'Russian_Russia.1251'],
+ 'zh_CN.UTF-8': ['zh_CN.UTF-8', 'zh_CN.utf8', 'Chinese_China.936'],
+ 'fr_CA.ISO8859-1': ['fr_CA.ISO8859-1', 'French_Canada.1252'],
+ 'cs_CZ.ISO8859-2': ['cs_CZ.ISO8859-2', 'Czech_Czech Republic.1250']
+}
+for locale, alts in locales.items():
+ features += [
+ Feature(name='locale.{}'.format(locale),
+ when=lambda cfg: any(hasLocale(cfg, alt) for alt in alts))
+ ]
diff --git a/libcxx/utils/libcxx/test/target_info.py b/libcxx/utils/libcxx/test/target_info.py
index 7c034e2640cd..adc704890efd 100644
--- a/libcxx/utils/libcxx/test/target_info.py
+++ b/libcxx/utils/libcxx/test/target_info.py
@@ -8,7 +8,6 @@
import importlib
import lit.util
-import locale
import os
import platform
import re
@@ -31,10 +30,6 @@ def is_windows(self):
def is_darwin(self):
return self.platform() == 'darwin'
- def add_locale_features(self, features):
- self.full_config.lit_config.warning(
- "No locales entry for target_system: %s" % self.platform())
-
def add_cxx_compile_flags(self, flags): pass
def add_cxx_link_flags(self, flags): pass
def allow_cxxabi_link(self): return True
@@ -53,38 +48,6 @@ def add_path(self, dest_env, new_path):
dest_env['PATH'] = '%s%s%s' % (new_path, split_char,
dest_env['PATH'])
- def _test_locale(self, loc):
- assert loc is not None
- default_locale = locale.setlocale(locale.LC_ALL)
- try:
- locale.setlocale(locale.LC_ALL, loc)
- return True
- except locale.Error:
- return False
- finally:
- locale.setlocale(locale.LC_ALL, default_locale)
-
- def add_common_locales(self, features, is_windows=False):
- # A list of locales needed by the test-suite.
- # The list uses the canonical name for the locale used in the test-suite
- # TODO: On Linux ISO8859 *may* needs to hyphenated.
- locales = [
- ('en_US.UTF-8', 'English_United States.1252'),
- ('fr_FR.UTF-8', 'French_France.1252'),
- ('ru_RU.UTF-8', 'Russian_Russia.1251'),
- ('zh_CN.UTF-8', 'Chinese_China.936'),
- ('fr_CA.ISO8859-1', 'French_Canada.1252'),
- ('cs_CZ.ISO8859-2', 'Czech_Czech Republic.1250')
- ]
- for loc_id, windows_loc_name in locales:
- loc_name = windows_loc_name if is_windows else loc_id
- if self._test_locale(loc_name):
- features.add('locale.{0}'.format(loc_id))
- else:
- self.full_config.lit_config.warning('The locale {0} is not supported by '
- 'your platform. Some tests will be '
- 'unsupported.'.format(loc_name))
-
class DarwinLocalTI(DefaultTargetInfo):
def __init__(self, full_config):
@@ -135,9 +98,6 @@ def get_platform(self):
version = self.get_sdk_version(name)
return (True, name, version)
- def add_locale_features(self, features):
- self.add_common_locales(features)
-
def add_cxx_compile_flags(self, flags):
if self.full_config.use_deployment:
_, name, _ = self.full_config.config.deployment
@@ -166,9 +126,6 @@ class FreeBSDLocalTI(DefaultTargetInfo):
def __init__(self, full_config):
super(FreeBSDLocalTI, self).__init__(full_config)
- def add_locale_features(self, features):
- self.add_common_locales(features)
-
def add_cxx_link_flags(self, flags):
flags += ['-lc', '-lm', '-lpthread', '-lgcc_s', '-lcxxrt']
@@ -177,9 +134,6 @@ class NetBSDLocalTI(DefaultTargetInfo):
def __init__(self, full_config):
super(NetBSDLocalTI, self).__init__(full_config)
- def add_locale_features(self, features):
- self.add_common_locales(features)
-
def add_cxx_link_flags(self, flags):
flags += ['-lc', '-lm', '-lpthread', '-lgcc_s', '-lc++abi',
'-lunwind']
@@ -214,9 +168,6 @@ def platform_ver(self):
ver = ver.lower().strip().replace(' ', '-')
return ver # Permitted to be None.
- def add_locale_features(self, features):
- self.add_common_locales(features)
-
def add_platform_features(self, features):
super(LinuxLocalTI, self).add_platform_features(features)
@@ -270,28 +221,11 @@ def add_cxx_link_flags(self, flags):
class LinuxRemoteTI(LinuxLocalTI):
def __init__(self, full_config):
super(LinuxRemoteTI, self).__init__(full_config)
- self.__cached_locales = None
-
- def _test_locale(self, loc):
- if self.__cached_locales is None:
- self.full_config.lit_config.note('asking the remote host for supported locales...')
- _, out, err, exit_code = self.executor.execute_command_remote(['locale', '-a'])
- if exit_code != 0:
- raise RuntimeError(err)
- self.__cached_locales = out.splitlines()
-
- # It is possible that the output will use 'en_US.utf8' instead of 'en_US.UTF-8',
- # so we check both variants.
- return loc in self.__cached_locales or \
- loc.replace('UTF-8', 'utf8') in self.__cached_locales
class WindowsLocalTI(DefaultTargetInfo):
def __init__(self, full_config):
super(WindowsLocalTI, self).__init__(full_config)
- def add_locale_features(self, features):
- self.add_common_locales(features, is_windows=True)
-
def use_lit_shell_default(self):
# Default to the internal shell on Windows, as bash on Windows is
# usually very slow.
More information about the libcxx-commits
mailing list