diff --git a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h --- a/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h +++ b/libcxx/test/std/containers/container.adaptors/container.adaptors.format/format.functions.tests.h @@ -600,16 +600,19 @@ // *** locale-specific form *** check(SV("[-42.5, 0, 1.25, 42.5]"), SV("{::L}"), input); // does not require locales present #ifndef TEST_HAS_NO_LOCALIZATION -// TODO FMT Enable with locale testing active -# if 0 +# ifdef TEST_HAS_LOCALE_fr_FR_UTF_8 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8)); check(SV("[-42,5, 0, 1,25, 42,5]"), SV("{::L}"), input); +# else +# error XXX +# endif +# ifdef TEST_HAS_LOCALE_en_US_UTF_8 std::locale::global(std::locale(LOCALE_en_US_UTF_8)); check(SV("[-42.5, 0, 1.25, 42.5]"), SV("{::L}"), input); +# endif std::locale::global(std::locale::classic()); -# endif #endif // TEST_HAS_NO_LOCALIZATION // *** type *** diff --git a/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.tests.h b/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.tests.h --- a/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.tests.h +++ b/libcxx/test/std/utilities/format/format.range/format.range.fmtset/format.functions.tests.h @@ -776,16 +776,17 @@ // *** locale-specific form *** check(SV("{-42.5, 0, 1.25, 42.5}"), SV("{::L}"), input); // does not require locales present #ifndef TEST_HAS_NO_LOCALIZATION -// TODO FMT Enable with locale testing active -# if 0 +# ifdef TEST_HAS_LOCALE_fr_FR_UTF_8 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8)); check(SV("{-42,5, 0, 1,25, 42,5}"), SV("{::L}"), input); +# endif +# ifdef TEST_HAS_LOCALE_en_US_UTF_8 std::locale::global(std::locale(LOCALE_en_US_UTF_8)); check(SV("{-42.5, 0, 1.25, 42.5}"), SV("{::L}"), input); +# endif std::locale::global(std::locale::classic()); -# endif #endif // TEST_HAS_NO_LOCALIZATION // *** type *** diff --git a/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.tests.h b/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.tests.h --- a/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.tests.h +++ b/libcxx/test/std/utilities/format/format.range/format.range.formatter/format.functions.tests.h @@ -587,16 +587,17 @@ // *** locale-specific form *** check(SV("[-42.5, 0, 1.25, 42.5]"), SV("{::L}"), input); // does not require locales present #ifndef TEST_HAS_NO_LOCALIZATION -// TODO FMT Enable with locale testing active -# if 0 +# ifdef TEST_HAS_LOCALE_fr_FR_UTF_8 std::locale::global(std::locale(LOCALE_fr_FR_UTF_8)); check(SV("[-42,5, 0, 1,25, 42,5]"), SV("{::L}"), input); +# endif +# ifdef TEST_HAS_LOCALE_en_US_UTF_8 std::locale::global(std::locale(LOCALE_en_US_UTF_8)); check(SV("[-42.5, 0, 1.25, 42.5]"), SV("{::L}"), input); +# endif std::locale::global(std::locale::classic()); -# endif #endif // TEST_HAS_NO_LOCALIZATION // *** type *** diff --git a/libcxx/test/support/test_macros.h b/libcxx/test/support/test_macros.h --- a/libcxx/test/support/test_macros.h +++ b/libcxx/test/support/test_macros.h @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef SUPPORT_TEST_MACROS_HPP -#define SUPPORT_TEST_MACROS_HPP +#ifndef SUPPORT_TEST_MACROS_H +#define SUPPORT_TEST_MACROS_H // Attempt to get STL specific macros like _LIBCPP_VERSION using the most // minimal header possible. If we're testing libc++, we should use `<__config>`. @@ -23,6 +23,12 @@ #include #endif +#ifdef __has_include +# if __has_include("config_site.h") +# include "config_site.h" +# endif +#endif + #define TEST_STRINGIZE_IMPL(x) #x #define TEST_STRINGIZE(x) TEST_STRINGIZE_IMPL(x) @@ -437,4 +443,4 @@ # define TEST_SHORT_WCHAR #endif -#endif // SUPPORT_TEST_MACROS_HPP +#endif // SUPPORT_TEST_MACROS_H diff --git a/libcxx/utils/libcxx/test/dsl.py b/libcxx/utils/libcxx/test/dsl.py --- a/libcxx/utils/libcxx/test/dsl.py +++ b/libcxx/utils/libcxx/test/dsl.py @@ -505,6 +505,35 @@ return 'add substitution {} = {}'.format(self._key, self._getSub(config)) +class AddDefine(ConfigAction): + """ + This action adds the given define to the test suite's config_site. + + Currently this only defines macros without a way to specify the macro's + value, since there is no usecase for that feature. + + """ + def __init__(self, name): + self._name = name + + def initializeConfig(self, config): + config.defines = [] + config.config_site_root = os.path.join(config.test_exec_root, 'support') + if not os.path.exists(config.config_site_root): + os.makedirs(config.config_site_root) + AddCompileFlag(f"-I {config.config_site_root}").applyTo(config) + + def applyTo(self, config): + name = self._name + if not hasattr(config, 'defines'): + self.initializeConfig(config) + config.defines.append(name) + + def pretty(self, config, litParams): + return f"add define {self._name}" + + + class Feature(object): """ Represents a Lit available feature that is enabled whenever it is supported. diff --git a/libcxx/utils/libcxx/test/features.py b/libcxx/utils/libcxx/test/features.py --- a/libcxx/utils/libcxx/test/features.py +++ b/libcxx/utils/libcxx/test/features.py @@ -240,7 +240,8 @@ # Note: Using alts directly in the lambda body here will bind it to the value at the # end of the loop. Assigning it to a default argument works around this issue. DEFAULT_FEATURES.append(Feature(name='locale.{}'.format(locale), - when=lambda cfg, alts=alts: hasAnyLocale(cfg, alts))) + when=lambda cfg, alts=alts: hasAnyLocale(cfg, alts), + actions=[AddDefine('TEST_HAS_LOCALE_{}'.format(re.sub("\W", "_", locale)))])) # Add features representing the target platform name: darwin, linux, windows, etc... diff --git a/libcxx/utils/libcxx/test/newconfig.py b/libcxx/utils/libcxx/test/newconfig.py --- a/libcxx/utils/libcxx/test/newconfig.py +++ b/libcxx/utils/libcxx/test/newconfig.py @@ -15,6 +15,31 @@ return replacement raise ValueError('Substitution {} is not in the config.'.format(substitution)) +CONFIG_SITE_TEMPLATE = """ +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef SUPPORT_TEST_CONFIG_SITE_H +#define SUPPORT_TEST_CONFIG_SITE_H + +{defines} + +#endif // SUPPORT_TEST_CONFIG_SITE_H +""" + +def _writeConfigSite(config): + file = open(os.path.join(config.config_site_root, 'config_site.h'), "w") + file.write(CONFIG_SITE_TEMPLATE.format(defines = '\n'.join( + [ + "#define {}".format(d) for d in config.defines + ]))) + file.close() + def configure(parameters, features, config, lit_config): note = lambda s: lit_config.note("({}) {}".format(config.name, s)) config.environment = dict(os.environ) @@ -41,9 +66,16 @@ action.pretty(config, lit_config.params), feature.pretty(config))) + if hasattr(config, 'defines'): + _writeConfigSite(config) + # Print the basic substitutions for sub in ('%{cxx}', '%{flags}', '%{compile_flags}', '%{link_flags}', '%{exec}'): note("Using {} substitution: '{}'".format(sub, _getSubstitution(sub, config))) # Print all available features note("All available features: {}".format(', '.join(config.available_features))) + + # Print all available defines + if hasattr(config, 'defines'): + note("All available defines: {}".format(', '.join(config.defines)))