[libc++] Provide a method for adding compiler flags in lit.local.cfg files
authorLouis Dionne <ldionne@apple.com>
Mon, 30 Mar 2020 17:22:06 +0000 (13:22 -0400)
committerLouis Dionne <ldionne@apple.com>
Tue, 31 Mar 2020 13:29:18 +0000 (09:29 -0400)
That way, local lit configuration files don't have to worry about
deep-copying the compiler instance of the test format, which is
arguably an implementation detail.

We pass the config to this method even though it is not used by the
current test format because this allows replacing the current test
format by other test formats that would require the config to add
new compile flags.

libcxx/test/std/experimental/filesystem/lit.local.cfg
libcxx/test/std/experimental/language.support/support.coroutines/lit.local.cfg
libcxx/test/std/input.output/filesystems/lit.local.cfg
libcxx/utils/libcxx/test/format.py

index 1d0cf19..460a0b8 100644 (file)
@@ -1 +1 @@
-config.test_format.cxx.compile_flags += ['-D_LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_FILESYSTEM']
+config.test_format.addCompileFlags(config, '-D_LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_FILESYSTEM')
index a0b3de8..d32e99f 100644 (file)
@@ -4,6 +4,4 @@
 if 'fcoroutines-ts' not in config.available_features:
   config.unsupported = True
 else:
-  import copy
-  config.test_format.cxx = copy.deepcopy(config.test_format.cxx)
-  config.test_format.cxx.compile_flags += ['-fcoroutines-ts']
+  config.test_format.addCompileFlags(config, '-fcoroutines-ts')
index f2f26e6..00e1492 100644 (file)
@@ -1,4 +1,3 @@
-import copy
 import os
 import sys
 
@@ -8,11 +7,9 @@ if 'dylib-has-no-filesystem' in config.available_features:
 if 'c++filesystem-disabled' in config.available_features:
   config.unsupported = True
 
-config.test_format.cxx = copy.deepcopy(config.test_format.cxx)
-
 inputs = os.path.join(os.path.dirname(__file__), 'Inputs', 'static_test_env')
-config.test_format.cxx.compile_flags += ['-DLIBCXX_FILESYSTEM_STATIC_TEST_ROOT="{}"'.format(inputs)]
+config.test_format.addCompileFlags(config, '-DLIBCXX_FILESYSTEM_STATIC_TEST_ROOT="{}"'.format(inputs))
 
 dynamic_helper = os.path.join(config.test_source_root, 'support', 'filesystem_dynamic_test_helper.py')
 assert os.path.isfile(dynamic_helper)
-config.test_format.cxx.compile_flags += ['-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_HELPER="{} {}"'.format(sys.executable, dynamic_helper)]
+config.test_format.addCompileFlags(config, '-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_HELPER="{} {}"'.format(sys.executable, dynamic_helper))
index 4199ddd..6dabc03 100644 (file)
@@ -51,6 +51,11 @@ class LibcxxTestFormat(object):
                                         initial_value=[])
         ]
 
+    # Utility function to add compile flags in lit.local.cfg files.
+    def addCompileFlags(self, config, *flags):
+        self.cxx = copy.deepcopy(self.cxx)
+        self.cxx.compile_flags += flags
+
     @staticmethod
     def _get_parser(key, parsers):
         for p in parsers: