Merge pull request #623 from mesonbuild/colorout

Enable colored output with GCC.
pull/629/head
Jussi Pakkanen 9 years ago committed by GitHub
commit d6ab5027fe
  1. 7
      mesonbuild/backend/backends.py
  2. 6
      mesonbuild/backend/ninjabackend.py
  3. 30
      mesonbuild/compilers.py

@ -83,8 +83,9 @@ class Backend():
return i
raise RuntimeError('No compiler for language ' + lang)
def get_compiler_for_source(self, src):
for i in self.build.compilers:
def get_compiler_for_source(self, src, is_cross):
comp = self.build.cross_compilers if is_cross else self.build.compilers
for i in comp:
if i.can_compile(src):
return i
if isinstance(src, mesonlib.File):
@ -133,7 +134,7 @@ class Backend():
abs_files = []
result = []
for src in unity_src:
comp = self.get_compiler_for_source(src)
comp = self.get_compiler_for_source(src, target.is_cross)
language = comp.get_language()
suffix = '.' + comp.get_default_suffix()
if language not in langlist:

@ -665,7 +665,7 @@ int dummy;
outname_rel = os.path.join(self.get_target_dir(target), fname)
src_list = target.get_sources()
class_list = []
compiler = self.get_compiler_for_source(src_list[0])
compiler = self.get_compiler_for_source(src_list[0], False)
assert(compiler.get_language() == 'java')
c = 'c'
m = ''
@ -716,7 +716,7 @@ int dummy;
fname = target.get_filename()
outname_rel = os.path.join(self.get_target_dir(target), fname)
src_list = target.get_sources()
compiler = self.get_compiler_for_source(src_list[0])
compiler = self.get_compiler_for_source(src_list[0], False)
assert(compiler.get_language() == 'cs')
rel_srcs = [s.rel_to_builddir(self.build_to_src) for s in src_list]
deps = []
@ -1424,7 +1424,7 @@ rule FORTRAN_DEP_HACK
if isinstance(src, RawFilename) and src.fname.endswith('.h'):
raise RuntimeError('Fug')
extra_orderdeps = []
compiler = self.get_compiler_for_source(src)
compiler = self.get_compiler_for_source(src, target.is_cross)
commands = []
# The first thing is implicit include directories: source, build and private.
commands += compiler.get_include_args(self.get_target_private_dir(target), False)

@ -129,6 +129,10 @@ msvc_winlibs = ['kernel32.lib', 'user32.lib', 'gdi32.lib',
'winspool.lib', 'shell32.lib', 'ole32.lib', 'oleaut32.lib',
'uuid.lib', 'comdlg32.lib', 'advapi32.lib']
gnu_color_args = {'auto' : ['-fdiagnostics-color=auto'],
'always': ['-fdiagnostics-color=always'],
'never' : ['-fdiagnostics-color=never'],
}
base_options = {
'b_pch': coredata.UserBooleanOption('b_pch', 'Use precompiled headers', True),
@ -144,6 +148,9 @@ base_options = {
'b_coverage': coredata.UserBooleanOption('b_coverage',
'Enable coverage tracking.',
False),
'b_colorout' : coredata.UserComboOption('b_colorout', 'Use colored output',
['auto', 'always', 'never'],
'always'),
}
def sanitizer_compile_args(value):
@ -168,6 +175,10 @@ def get_base_compile_args(options, compiler):
args.append('-flto')
except KeyError:
pass
try:
args += compiler.get_colorout_args(options['b_colorout'].value)
except KeyError:
pass
try:
args += sanitizer_compile_args(options['b_sanitize'].value)
except KeyError:
@ -325,6 +336,9 @@ class Compiler():
extra_flags += environment.cross_info.config['properties'].get(lang_link_args_key, [])
return extra_flags
def get_colorout_args(self, colortype):
return []
class CCompiler(Compiler):
def __init__(self, exelist, version, is_cross, exe_wrapper=None):
super().__init__(exelist, version)
@ -1624,10 +1638,16 @@ class GnuCCompiler(CCompiler):
self.warn_args = {'1': ['-Wall', '-Winvalid-pch'],
'2': ['-Wall', '-Wextra', '-Winvalid-pch'],
'3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']}
self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage']
self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage',
'b_colorout']
if self.gcc_type != GCC_OSX:
self.base_options.append('b_lundef')
def get_colorout_args(self, colortype):
if mesonlib.version_compare(self.version, '>=4.9.0'):
return gnu_color_args[colortype][:]
return []
def get_pic_args(self):
if self.gcc_type == GCC_MINGW:
return [] # On Window gcc defaults to fpic being always on.
@ -1807,10 +1827,16 @@ class GnuCPPCompiler(CPPCompiler):
self.warn_args = {'1': ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'],
'2': ['-Wall', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor'],
'3': ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']}
self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage']
self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage',
'b_colorout']
if self.gcc_type != GCC_OSX:
self.base_options.append('b_lundef')
def get_colorout_args(self, colortype):
if mesonlib.version_compare(self.version, '>=4.9.0'):
return gnu_color_args[colortype][:]
return []
def get_always_args(self):
return ['-pipe']

Loading…
Cancel
Save