Merge pull request #246 from mesonbuild/warnreorg

Added warning level option.
pull/259/head
Jussi Pakkanen 9 years ago
commit 70f4e388ca
  1. 2
      backends.py
  2. 83
      compilers.py
  3. 29
      coredata.py
  4. 11
      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,17 +1048,13 @@ 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_pic_args(self):
if self.gcc_type == GCC_MINGW:
@ -1065,9 +1064,6 @@ class GnuCCompiler(CCompiler):
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]
@ -1087,7 +1083,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)
@ -1095,9 +1091,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]
@ -1112,7 +1108,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):
@ -1121,9 +1116,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]
@ -1153,9 +1148,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]
@ -1177,8 +1172,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']
@ -1186,17 +1179,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]
@ -1210,14 +1199,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]
@ -1235,8 +1222,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
@ -1302,7 +1287,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):
@ -1361,6 +1346,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)
@ -1386,7 +1375,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):
@ -1411,7 +1400,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):
@ -1433,7 +1422,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):
@ -1455,7 +1444,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
@ -1478,7 +1467,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):
@ -1500,7 +1489,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,15 @@ parser = argparse.ArgumentParser()
backendlist = ['ninja', 'vs2010', 'xcode']
build_types = ['plain', 'debug', 'debugoptimized', 'release']
warning_levels = ['1', '2', '3']
default_warning = '1'
try:
warn_candidate = os.environ['MESON_WARN_LEVEL']
if warn_candidate in warning_levels:
default_warning = warn_candidate
except KeyError:
pass
if mesonlib.is_windows():
def_prefix = 'c:/'
@ -62,6 +71,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=default_warning, dest='warning_level', choices=warning_levels,\
help='Level of compiler warnings to use (larger is more, default is %(default)s)')
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