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))