More version information for compilers.

See issue #2762
Adds full_version to class Compiler. If set full_version will be printed
additionally.
Added support for CCompiler and CPPCompiler
Added support for gcc/g++, clang/clang++, icc.
pull/2791/head
Christoph Behle 7 years ago
parent cc952b055a
commit c6acf75617
  1. 12
      mesonbuild/compilers/c.py
  2. 6
      mesonbuild/compilers/compilers.py
  3. 16
      mesonbuild/compilers/cpp.py
  4. 7
      mesonbuild/environment.py
  5. 6
      mesonbuild/interpreter.py

@ -42,11 +42,11 @@ from .compilers import (
class CCompiler(Compiler): class CCompiler(Compiler):
def __init__(self, exelist, version, is_cross, exe_wrapper=None): def __init__(self, exelist, version, is_cross, exe_wrapper=None, **kwargs):
# If a child ObjC or CPP class has already set it, don't set it ourselves # If a child ObjC or CPP class has already set it, don't set it ourselves
if not hasattr(self, 'language'): if not hasattr(self, 'language'):
self.language = 'c' self.language = 'c'
super().__init__(exelist, version) super().__init__(exelist, version, **kwargs)
self.id = 'unknown' self.id = 'unknown'
self.is_cross = is_cross self.is_cross = is_cross
self.can_compile_suffixes.add('h') self.can_compile_suffixes.add('h')
@ -798,8 +798,8 @@ class CCompiler(Compiler):
class ClangCCompiler(ClangCompiler, CCompiler): class ClangCCompiler(ClangCompiler, CCompiler):
def __init__(self, exelist, version, clang_type, is_cross, exe_wrapper=None): def __init__(self, exelist, version, clang_type, is_cross, exe_wrapper=None, **kwargs):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
ClangCompiler.__init__(self, clang_type) ClangCompiler.__init__(self, clang_type)
default_warn_args = ['-Wall', '-Winvalid-pch'] default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'1': default_warn_args, self.warn_args = {'1': default_warn_args,
@ -830,7 +830,7 @@ class ClangCCompiler(ClangCompiler, CCompiler):
class GnuCCompiler(GnuCompiler, CCompiler): class GnuCCompiler(GnuCompiler, CCompiler):
def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None, defines=None): def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None, defines=None, **kwargs):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
GnuCompiler.__init__(self, gcc_type, defines) GnuCompiler.__init__(self, gcc_type, defines)
default_warn_args = ['-Wall', '-Winvalid-pch'] default_warn_args = ['-Wall', '-Winvalid-pch']
@ -869,7 +869,7 @@ class GnuCCompiler(GnuCompiler, CCompiler):
class IntelCCompiler(IntelCompiler, CCompiler): class IntelCCompiler(IntelCompiler, CCompiler):
def __init__(self, exelist, version, icc_type, is_cross, exe_wrapper=None): def __init__(self, exelist, version, icc_type, is_cross, exe_wrapper=None, **kwargs):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
IntelCompiler.__init__(self, icc_type) IntelCompiler.__init__(self, icc_type)
self.lang_header = 'c-header' self.lang_header = 'c-header'

@ -598,7 +598,7 @@ class Compiler:
# compiler or the C library. Currently only used for MSVC. # compiler or the C library. Currently only used for MSVC.
ignore_libs = () ignore_libs = ()
def __init__(self, exelist, version): def __init__(self, exelist, version, **kwargs):
if isinstance(exelist, str): if isinstance(exelist, str):
self.exelist = [exelist] self.exelist = [exelist]
elif isinstance(exelist, list): elif isinstance(exelist, list):
@ -612,6 +612,10 @@ class Compiler:
self.can_compile_suffixes = set(self.file_suffixes) self.can_compile_suffixes = set(self.file_suffixes)
self.default_suffix = self.file_suffixes[0] self.default_suffix = self.file_suffixes[0]
self.version = version self.version = version
if 'full_version' in kwargs:
self.full_version = kwargs['full_version']
else:
self.full_version = None
self.base_options = [] self.base_options = []
def __repr__(self): def __repr__(self):

@ -28,11 +28,11 @@ from .compilers import (
) )
class CPPCompiler(CCompiler): class CPPCompiler(CCompiler):
def __init__(self, exelist, version, is_cross, exe_wrap): def __init__(self, exelist, version, is_cross, exe_wrap, **kwargs):
# If a child ObjCPP class has already set it, don't set it ourselves # If a child ObjCPP class has already set it, don't set it ourselves
if not hasattr(self, 'language'): if not hasattr(self, 'language'):
self.language = 'cpp' self.language = 'cpp'
CCompiler.__init__(self, exelist, version, is_cross, exe_wrap) CCompiler.__init__(self, exelist, version, is_cross, exe_wrap, **kwargs)
def get_display_language(self): def get_display_language(self):
return 'C++' return 'C++'
@ -66,8 +66,8 @@ class CPPCompiler(CCompiler):
class ClangCPPCompiler(ClangCompiler, CPPCompiler): class ClangCPPCompiler(ClangCompiler, CPPCompiler):
def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None): def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None, **kwargs):
CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
ClangCompiler.__init__(self, cltype) ClangCompiler.__init__(self, cltype)
default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'] default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor']
self.warn_args = {'1': default_warn_args, self.warn_args = {'1': default_warn_args,
@ -92,8 +92,8 @@ class ClangCPPCompiler(ClangCompiler, CPPCompiler):
class GnuCPPCompiler(GnuCompiler, CPPCompiler): class GnuCPPCompiler(GnuCompiler, CPPCompiler):
def __init__(self, exelist, version, gcc_type, is_cross, exe_wrap, defines): def __init__(self, exelist, version, gcc_type, is_cross, exe_wrap, defines, **kwargs):
CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap) CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap, **kwargs)
GnuCompiler.__init__(self, gcc_type, defines) GnuCompiler.__init__(self, gcc_type, defines)
default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'] default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor']
self.warn_args = {'1': default_warn_args, self.warn_args = {'1': default_warn_args,
@ -133,8 +133,8 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler):
class IntelCPPCompiler(IntelCompiler, CPPCompiler): class IntelCPPCompiler(IntelCompiler, CPPCompiler):
def __init__(self, exelist, version, icc_type, is_cross, exe_wrap): def __init__(self, exelist, version, icc_type, is_cross, exe_wrap, **kwargs):
CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap) CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap, **kwargs)
IntelCompiler.__init__(self, icc_type) IntelCompiler.__init__(self, icc_type)
self.lang_header = 'c++-header' self.lang_header = 'c++-header'
default_warn_args = ['-Wall', '-w3', '-diag-disable:remark', default_warn_args = ['-Wall', '-w3', '-diag-disable:remark',

@ -496,6 +496,7 @@ class Environment:
popen_exceptions[' '.join(compiler + [arg])] = e popen_exceptions[' '.join(compiler + [arg])] = e
continue continue
version = search_version(out) version = search_version(out)
full_version = out.split('\n', 1)[0]
if 'Free Software Foundation' in out: if 'Free Software Foundation' in out:
defines = self.get_gnu_compiler_defines(compiler) defines = self.get_gnu_compiler_defines(compiler)
if not defines: if not defines:
@ -504,7 +505,7 @@ class Environment:
gtype = self.get_gnu_compiler_type(defines) gtype = self.get_gnu_compiler_type(defines)
version = self.get_gnu_version_from_defines(defines) version = self.get_gnu_version_from_defines(defines)
cls = GnuCCompiler if lang == 'c' else GnuCPPCompiler cls = GnuCCompiler if lang == 'c' else GnuCPPCompiler
return cls(ccache + compiler, version, gtype, is_cross, exe_wrap, defines) return cls(ccache + compiler, version, gtype, is_cross, exe_wrap, defines, full_version=full_version )
if 'clang' in out: if 'clang' in out:
if 'Apple' in out or mesonlib.for_darwin(want_cross, self): if 'Apple' in out or mesonlib.for_darwin(want_cross, self):
cltype = CLANG_OSX cltype = CLANG_OSX
@ -513,7 +514,7 @@ class Environment:
else: else:
cltype = CLANG_STANDARD cltype = CLANG_STANDARD
cls = ClangCCompiler if lang == 'c' else ClangCPPCompiler cls = ClangCCompiler if lang == 'c' else ClangCPPCompiler
return cls(ccache + compiler, version, cltype, is_cross, exe_wrap) return cls(ccache + compiler, version, cltype, is_cross, exe_wrap, full_version=full_version)
if 'Microsoft' in out or 'Microsoft' in err: if 'Microsoft' in out or 'Microsoft' in err:
# Latest versions of Visual Studio print version # Latest versions of Visual Studio print version
# number to stderr but earlier ones print version # number to stderr but earlier ones print version
@ -532,7 +533,7 @@ class Environment:
# TODO: add microsoft add check OSX # TODO: add microsoft add check OSX
inteltype = ICC_STANDARD inteltype = ICC_STANDARD
cls = IntelCCompiler if lang == 'c' else IntelCPPCompiler cls = IntelCCompiler if lang == 'c' else IntelCPPCompiler
return cls(ccache + compiler, version, inteltype, is_cross, exe_wrap) return cls(ccache + compiler, version, inteltype, is_cross, exe_wrap, full_version=full_version)
self._handle_exceptions(popen_exceptions, compilers) self._handle_exceptions(popen_exceptions, compilers)
def detect_c_compiler(self, want_cross): def detect_c_compiler(self, want_cross):

@ -2021,7 +2021,11 @@ to directly access options of other subprojects.''')
continue continue
else: else:
raise raise
mlog.log('Native %s compiler: ' % comp.get_display_language(), mlog.bold(' '.join(comp.get_exelist())), ' (%s %s)' % (comp.id, comp.version), sep='') if comp.full_version != None:
version_string= ' (%s %s "%s")' % (comp.id, comp.version, comp.full_version)
else:
version_string= ' (%s %s)' % (comp.id, comp.version)
mlog.log('Native %s compiler: ' % comp.get_display_language(), mlog.bold(' '.join(comp.get_exelist())), version_string , sep='')
if not comp.get_language() in self.coredata.external_args: if not comp.get_language() in self.coredata.external_args:
(preproc_args, compile_args, link_args) = environment.get_args_from_envvars(comp) (preproc_args, compile_args, link_args) = environment.get_args_from_envvars(comp)
self.coredata.external_preprocess_args[comp.get_language()] = preproc_args self.coredata.external_preprocess_args[comp.get_language()] = preproc_args

Loading…
Cancel
Save