[libc++] Move availability-related Lit configuration to the DSL
authorLouis Dionne <ldionne@apple.com>
Wed, 4 Nov 2020 19:46:25 +0000 (14:46 -0500)
committerLouis Dionne <ldionne@apple.com>
Wed, 4 Nov 2020 19:56:08 +0000 (14:56 -0500)
The implementation is not really satisfactory, but it's better than
being in the legacy config, which causes other issues.

libcxx/utils/libcxx/test/config.py
libcxx/utils/libcxx/test/features.py
libcxx/utils/libcxx/test/params.py

index f6ff8b1..1c51acd 100644 (file)
@@ -239,18 +239,6 @@ class Configuration(object):
             for f in additional_features.split(','):
                 self.config.available_features.add(f.strip())
 
-        # Write an "available feature" that combines the triple when
-        # use_system_cxx_lib is enabled. This is so that we can easily write
-        # XFAIL markers for tests that are known to fail with versions of
-        # libc++ as were shipped with a particular triple.
-        if self.use_system_cxx_lib:
-            (arch, vendor, platform) = self.config.target_triple.split('-', 2)
-            (sysname, version) = re.match(r'([^0-9]+)([0-9\.]*)', platform).groups()
-
-            self.config.available_features.add('with_system_cxx_lib={}-{}-{}{}'.format(arch, vendor, sysname, version))
-            self.config.available_features.add('with_system_cxx_lib={}{}'.format(sysname, version))
-            self.config.available_features.add('with_system_cxx_lib={}'.format(sysname))
-
         if self.target_info.is_windows():
             if self.cxx_stdlib_under_test == 'libc++':
                 # LIBCXX-WINDOWS-FIXME is the feature name used to XFAIL the
@@ -329,11 +317,6 @@ class Configuration(object):
         support_path = os.path.join(self.libcxx_src_root, 'test/support')
         self.cxx.compile_flags += ['-I' + support_path]
 
-        # If we're testing the upstream LLVM libc++, disable availability markup,
-        # which is not relevant for non-shipped flavors of libc++.
-        if not self.use_system_cxx_lib:
-            self.cxx.compile_flags += ['-D_LIBCPP_DISABLE_AVAILABILITY']
-
         # On GCC, the libc++ headers cause errors due to throw() decorators
         # on operator new clashing with those from the test suite, so we
         # don't enable warnings in system headers on GCC.
index cacbf6d..efafd87 100644 (file)
@@ -7,6 +7,7 @@
 #===----------------------------------------------------------------------===##
 
 from libcxx.test.dsl import *
+import re
 import sys
 
 _isClang      = lambda cfg: '__clang__' in compilerMacros(cfg) and '__apple_build_version__' not in compilerMacros(cfg)
@@ -128,3 +129,27 @@ DEFAULT_FEATURES += [
   Feature(name='linux', when=lambda cfg: '__linux__' in compilerMacros(cfg)),
   Feature(name='netbsd', when=lambda cfg: '__NetBSD__' in compilerMacros(cfg))
 ]
+
+
+# When vendor-specific availability annotations are enabled, add Lit features
+# with various forms of the target triple to make it easier to write XFAIL or
+# UNSUPPORTED markup for tests that are known to fail on a particular triple.
+#
+# TODO: This is very unclean -- we assume that the 'use_system_cxx_lib' parameter
+#       is set before this feature gets detected, and we also set a dummy name
+#       for the main feature. We also take for granted that `target_triple`
+#       exists in the config object. This should be refactored so that the
+#       'use_system_cxx_lib' Parameter can set these features itself.
+def _addSystemCxxLibDeclinations(cfg):
+  (arch, vendor, platform) = cfg.target_triple.split('-', 2)
+  (sysname, version) = re.match(r'([^0-9]+)([0-9\.]*)', platform).groups()
+  return [
+    AddFeature('with_system_cxx_lib={}-{}-{}{}'.format(arch, vendor, sysname, version)),
+    AddFeature('with_system_cxx_lib={}{}'.format(sysname, version)),
+    AddFeature('with_system_cxx_lib={}'.format(sysname)),
+  ]
+DEFAULT_FEATURES += [
+  Feature(name='__dummy_use_system_cxx_lib',
+          when=lambda cfg: 'use_system_cxx_lib' in cfg.available_features,
+          actions=_addSystemCxxLibDeclinations)
+]
index e9c0f73..d8dc012 100644 (file)
@@ -73,6 +73,18 @@ DEFAULT_PARAMETERS = [
               AddOptionalWarningFlag(w) for w in _warningFlags
             ]),
 
+  Parameter(name='use_system_cxx_lib', choices=[True, False], type=bool, default=False,
+            help="Whether the test suite is being *run* against the library shipped on "
+                 "the target triple in use, as opposed to the trunk library.",
+            actions=lambda useSystem: [
+              # TODO: Remove this, see comment in features.py
+              AddFeature('use_system_cxx_lib')
+            ] if useSystem else [
+              # If we're testing upstream libc++, disable availability markup,
+              # which is not relevant for non-shipped flabors of libc++.
+              AddCompileFlag('-D_LIBCPP_DISABLE_AVAILABILITY')
+            ]),
+
   # Parameters to enable or disable parts of the test suite
   Parameter(name='enable_filesystem', choices=[True, False], type=bool, default=True,
             help="Whether to enable tests for the C++ <filesystem> library.",