forked from OSchip/llvm-project
[libcxx] Add logic to probe compiler in tests.
Summary: 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. Reviewers: mclow.lists, danalbert, jroelofs Reviewed By: jroelofs Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D6399 llvm-svn: 223593
This commit is contained in:
parent
b9f99739bc
commit
b92da3f217
|
@ -228,6 +228,7 @@ class Configuration(object):
|
|||
|
||||
def configure(self):
|
||||
self.configure_cxx()
|
||||
self.probe_cxx()
|
||||
self.configure_triple()
|
||||
self.configure_src_root()
|
||||
self.configure_obj_root()
|
||||
|
@ -271,6 +272,44 @@ class Configuration(object):
|
|||
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))
|
||||
|
|
Loading…
Reference in New Issue