Hi mclow.lists, danalbert, jroelofs,

This patch probes the cxx compiler used during testing by getting it to dump 
its predefined macros. Based on the value of these macros the compiler name and 
compiler name + version are added to the available features.

There are three compiler names:
- `clang`
- `apple-clang`
- `gcc`.

The available features added are equivalent to:
- `'%s' % compiler_name`
- `'%s-%s.%s' % compiler_name, major_version, minor_version`

This information can be used to XFAIL tests on different compilers / versions.

http://reviews.llvm.org/D6399

Files:
  test/lit.cfg
Index: test/lit.cfg
===================================================================
--- test/lit.cfg
+++ test/lit.cfg
@@ -246,6 +246,7 @@
 
     def configure(self):
         self.configure_cxx()
+        self.probe_cxx()
         self.configure_triple()
         self.configure_src_root()
         self.configure_obj_root()
@@ -289,6 +290,44 @@
             self.lit_config.fatal('must specify user parameter cxx_under_test '
                                   '(e.g., --param=cxx_under_test=clang++)')
 
+    def probe_cxx(self):
+        # Dump all of the predefined macros
+        dump_macro_cmd = [self.cxx, '-dM', '-E', '-x', 'c++', '/dev/null']
+        out, err, rc = lit.util.executeCommand(dump_macro_cmd)
+        if rc != 0:
+            self.lit_config.warning('Failed to dump macros for compiler: %s' %
+                                    self.cxx)
+            return
+        # Create a dict containing all the predefined macros.
+        macros = {}
+        lines = [l.strip() for l in out.split('\n') if l.strip()]
+        for l in lines:
+            assert l.startswith('#define ')
+            l = l[len('#define '):]
+            (macro, _, value) = l.partition(' ')
+            macros[macro] = value
+        # Add compiler information to available features.
+        compiler_name = None
+        major_ver = minor_ver = None
+        if '__clang__' in macros.keys():
+            compiler_name = 'clang'
+            # Treat apple's llvm fork differently.
+            if '__apple_build_type__' in macros.keys():
+                compiler_name = 'apple-clang'
+            major_ver = macros['__clang_major__']
+            minor_ver = macros['__clang_minor__']
+        elif '__GNUC__' in macros.keys():
+            compiler_name = 'gcc'
+            major_ver = macros['__GNUC__']
+            minor_ver = macros['__GNUC_MINOR__']
+        else:
+            self.lit_config.warning('Failed to detect compiler for cxx: %s' %
+                                    self.cxx)
+        if compiler_name is not None:
+            self.config.available_features.add(compiler_name)
+            self.config.available_features.add('%s-%s.%s' % (
+                compiler_name, major_ver, minor_ver))
+
     def configure_src_root(self):
         self.src_root = self.get_lit_conf(
             'libcxx_src_root', os.path.dirname(self.config.test_source_root))
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to