Added multiple selectable warning levels.

pull/246/head
Jussi Pakkanen 10 years ago
parent f32db9afa2
commit 6cca79b052
  1. 2
      backends.py
  2. 83
      compilers.py
  3. 29
      coredata.py
  4. 3
      meson.py
  5. 7
      mesonconf.py

@ -204,7 +204,7 @@ class Backend():
commands = []
commands += compiler.get_always_args()
if self.environment.coredata.buildtype != 'plain':
commands += compiler.get_std_warn_args()
commands += compiler.get_warn_args(self.environment.coredata.warning_level)
commands += self.build.get_global_args(compiler)
commands += self.environment.coredata.external_args[compiler.get_language()]
commands += target.get_extra_args(compiler.get_language())

@ -145,6 +145,9 @@ class CCompiler():
def get_linker_always_args(self):
return []
def get_warn_args(self, level):
return self.warn_args[level]
def get_soname_args(self, shlib_name, path, soversion):
return []
@ -913,13 +916,13 @@ class VisualStudioCCompiler(CCompiler):
self.always_args = VisualStudioCCompiler.vs2013_always_args
else:
self.always_args = VisualStudioCCompiler.vs2010_always_args
self.std_warn_args = {'1': ['/W2'],
'2': ['/W3'],
'3': ['/w4']}
def get_always_args(self):
return self.always_args
def get_std_warn_args(self):
return self.std_warn_args
def get_buildtype_args(self, buildtype):
return msvc_buildtype_args[buildtype]
@ -1045,24 +1048,17 @@ def get_gcc_soname_args(gcc_type, shlib_name, path, soversion):
raise RuntimeError('Not implemented yet.')
class GnuCCompiler(CCompiler):
old_warn = ['-Wall', '-pedantic', '-Winvalid-pch']
new_warn = ['-Wall', '-Wpedantic', '-Winvalid-pch']
def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
self.id = 'gcc'
self.gcc_type = gcc_type
if mesonlib.version_compare(version, ">=4.9.0"):
self.warn_args= GnuCCompiler.new_warn
else:
self.warn_args = GnuCCompiler.old_warn
self.warn_args = {'1': ['-Wall', '-Winvalid-pch'],
'2': ['-Wall', '-Wpedantic', '-Winvalid-pch'],
'3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']}
def get_always_args(self):
return ['-pipe']
def get_std_warn_args(self):
return self.warn_args
def get_buildtype_args(self, buildtype):
return gnulike_buildtype_args[buildtype]
@ -1082,7 +1078,7 @@ class GnuCCompiler(CCompiler):
return super().can_compile(filename) or filename.split('.')[-1].lower() == 's' # Gcc can do asm, too.
class GnuObjCCompiler(ObjCCompiler):
std_warn_args = ['-Wall', '-Wpedantic', '-Winvalid-pch']
std_opt_args = ['-O2']
def __init__(self, exelist, version, is_cross, exe_wrapper=None):
ObjCCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
@ -1090,9 +1086,9 @@ class GnuObjCCompiler(ObjCCompiler):
# Not really correct, but GNU objc is only used on non-OSX non-win. File a bug
# if this breaks your use case.
self.gcc_type = GCC_STANDARD
def get_std_warn_args(self):
return GnuObjCCompiler.std_warn_args
self.warn_args = {'1': ['-Wall', '-Winvalid-pch'],
'2': ['-Wall', '-Wpedantic', '-Winvalid-pch'],
'3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']}
def get_buildtype_args(self, buildtype):
return gnulike_buildtype_args[buildtype]
@ -1107,7 +1103,6 @@ class GnuObjCCompiler(ObjCCompiler):
return get_gcc_soname_args(self.gcc_type, shlib_name, path, soversion)
class GnuObjCPPCompiler(ObjCPPCompiler):
std_warn_args = ['-Wall', '-Wpedantic', '-Winvalid-pch']
std_opt_args = ['-O2']
def __init__(self, exelist, version, is_cross, exe_wrapper=None):
@ -1116,9 +1111,9 @@ class GnuObjCPPCompiler(ObjCPPCompiler):
# Not really correct, but GNU objc is only used on non-OSX non-win. File a bug
# if this breaks your use case.
self.gcc_type = GCC_STANDARD
def get_std_warn_args(self):
return GnuObjCPPCompiler.std_warn_args
self.warn_args = {'1': ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'],
'2': ['-Wall', '-Wpedantic', '-Winvalid-pch', '-Wnon-virtual-dtor'],
'3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']}
def get_buildtype_args(self, buildtype):
return gnulike_buildtype_args[buildtype]
@ -1148,9 +1143,9 @@ class ClangCCompiler(CCompiler):
def __init__(self, exelist, version, is_cross, exe_wrapper=None):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
self.id = 'clang'
def get_std_warn_args(self):
return ClangCCompiler.std_warn_args
self.warn_args = {'1': ['-Wall', '-Winvalid-pch'],
'2': ['-Wall', '-Wpedantic', '-Winvalid-pch'],
'3' : ['-Weverything']}
def get_buildtype_args(self, buildtype):
return gnulike_buildtype_args[buildtype]
@ -1172,8 +1167,6 @@ class ClangCCompiler(CCompiler):
class GnuCPPCompiler(CPPCompiler):
new_warn = ['-Wall', '-Wpedantic', '-Winvalid-pch', '-Wnon-virtual-dtor']
old_warn = ['-Wall', '-pedantic', '-Winvalid-pch', '-Wnon-virtual-dtor']
# may need to separate the latter to extra_debug_args or something
std_debug_args = ['-g']
@ -1181,17 +1174,13 @@ class GnuCPPCompiler(CPPCompiler):
CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
self.id = 'gcc'
self.gcc_type = gcc_type
if mesonlib.version_compare(version, ">=4.9.0"):
self.warn_args= GnuCPPCompiler.new_warn
else:
self.warn_args = GnuCPPCompiler.old_warn
self.warn_args = {'1': ['-Wall', '-Winvalid-pch'],
'2': ['-Wall', '-Wpedantic', '-Winvalid-pch', '-Wnon-virtual-dtor'],
'3': ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch', '-Wnon-virtual-dtor']}
def get_always_args(self):
return ['-pipe']
def get_std_warn_args(self):
return self.warn_args
def get_buildtype_args(self, buildtype):
return gnulike_buildtype_args[buildtype]
@ -1205,14 +1194,12 @@ class GnuCPPCompiler(CPPCompiler):
return get_gcc_soname_args(self.gcc_type, shlib_name, path, soversion)
class ClangCPPCompiler(CPPCompiler):
std_warn_args = ['-Wall', '-Wpedantic', '-Winvalid-pch', '-Wnon-virtual-dtor']
def __init__(self, exelist, version, is_cross, exe_wrapper=None):
CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
self.id = 'clang'
def get_std_warn_args(self):
return ClangCPPCompiler.std_warn_args
self.warn_args = {'1': ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'],
'2': ['-Wall', '-Wpedantic', '-Winvalid-pch', '-Wnon-virtual-dtor'],
'3': ['-Weverything']}
def get_buildtype_args(self, buildtype):
return gnulike_buildtype_args[buildtype]
@ -1230,8 +1217,6 @@ class ClangCPPCompiler(CPPCompiler):
return ['-include-pch', os.path.join (pch_dir, self.get_pch_name (header))]
class FortranCompiler():
std_warn_args = ['-Wall']
def __init__(self, exelist, version,is_cross, exe_wrapper=None):
super().__init__()
self.exelist = exelist
@ -1289,7 +1274,7 @@ end program prog
def get_linker_always_args(self):
return []
def get_std_warn_args(self):
def get_std_warn_args(self, level):
return FortranCompiler.std_warn_args
def get_buildtype_args(self, buildtype):
@ -1348,6 +1333,10 @@ end program prog
def module_name_to_filename(self, module_name):
return module_name.lower() + '.mod'
def get_warn_args(self, level):
return ['-Wall']
class GnuFortranCompiler(FortranCompiler):
def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None):
super().__init__(exelist, version, is_cross, exe_wrapper=None)
@ -1373,7 +1362,7 @@ class SunFortranCompiler(FortranCompiler):
def get_always_args(self):
return []
def get_std_warn_args(self):
def get_warn_args(self):
return []
def get_module_outdir_args(self, path):
@ -1398,7 +1387,7 @@ class IntelFortranCompiler(FortranCompiler):
return True
return False
def get_std_warn_args(self):
def get_warn_args(self, level):
return IntelFortranCompiler.std_warn_args
class PathScaleFortranCompiler(FortranCompiler):
@ -1420,7 +1409,7 @@ class PathScaleFortranCompiler(FortranCompiler):
return True
return False
def get_std_warn_args(self):
def get_std_warn_args(self, level):
return PathScaleFortranCompiler.std_warn_args
class PGIFortranCompiler(FortranCompiler):
@ -1442,7 +1431,7 @@ class PGIFortranCompiler(FortranCompiler):
return True
return False
def get_std_warn_args(self):
def get_warn_args(self, level):
return PGIFortranCompiler.std_warn_args
@ -1465,7 +1454,7 @@ class Open64FortranCompiler(FortranCompiler):
return True
return False
def get_std_warn_args(self):
def get_warn_args(self, level):
return Open64FortranCompiler.std_warn_args
class NAGFortranCompiler(FortranCompiler):
@ -1487,7 +1476,7 @@ class NAGFortranCompiler(FortranCompiler):
return True
return False
def get_std_warn_args(self):
def get_warn_args(self, level):
return NAGFortranCompiler.std_warn_args

@ -17,19 +17,21 @@ import pickle, os, uuid
version = '0.26.0-research'
builtin_options = {'buildtype': True,
'strip': True,
'coverage': True,
'pch': True,
'unity': True,
'prefix': True,
'libdir' : True,
'bindir' : True,
'includedir' : True,
'datadir' : True,
'mandir' : True,
'localedir' : True,
'werror' : True,
}
'strip': True,
'coverage': True,
'pch': True,
'unity': True,
'prefix': True,
'libdir' : True,
'bindir' : True,
'includedir' : True,
'datadir' : True,
'mandir' : True,
'localedir' : True,
'werror' : True,
'warning_level': True,
}
# This class contains all data that must persist over multiple
# invocations of Meson. It is roughly the same thing as
# cmakecache.
@ -54,6 +56,7 @@ class CoreData():
self.use_pch = options.use_pch
self.unity = options.unity
self.coverage = options.coverage
self.warning_level = options.warning_level
self.werror = options.werror
self.user_options = {}
self.external_args = {} # These are set from "the outside" with e.g. mesonconf

@ -28,6 +28,7 @@ parser = argparse.ArgumentParser()
backendlist = ['ninja', 'vs2010', 'xcode']
build_types = ['plain', 'debug', 'debugoptimized', 'release']
warning_levels = ['1', '2', '3']
if mesonlib.is_windows():
def_prefix = 'c:/'
@ -62,6 +63,8 @@ parser.add_argument('--unity', action='store_true', dest='unity', default=False,
help='unity build')
parser.add_argument('--werror', action='store_true', dest='werror', default=False,\
help='Treat warnings as errors')
parser.add_argument('--warnlevel', default='1', dest='warning_level', choices=warning_levels,\
help='Level of compiler warnings to use (larger is more)')
parser.add_argument('--cross-file', default=None, dest='cross_file',
help='file describing cross compilation environment')
parser.add_argument('-D', action='append', dest='projectoptions', default=[],

@ -18,7 +18,7 @@ import sys, os
import pickle
import argparse
import coredata, optinterpreter
from meson import build_types
from meson import build_types, warning_levels
parser = argparse.ArgumentParser()
@ -80,6 +80,10 @@ class Conf:
if v not in build_types:
raise ConfException('Invalid build type %s.' % v)
self.coredata.buildtype = v
elif k == 'warnlevel':
if not v in warning_levels:
raise ConfException('Invalid warning level %s.' % v)
self.coredata.warning_level = v
elif k == 'strip':
self.coredata.strip = self.tobool(v)
elif k == 'coverage':
@ -158,6 +162,7 @@ class Conf:
print('Core options\n')
carr = []
carr.append(['buildtype', 'Build type', self.coredata.buildtype])
carr.append(['warnlevel', 'Warning level', self.coredata.warning_level])
carr.append(['strip', 'Strip on install', self.coredata.strip])
carr.append(['coverage', 'Coverage report', self.coredata.coverage])
carr.append(['pch', 'Precompiled headers', self.coredata.use_pch])

Loading…
Cancel
Save