Add warning level zero

pull/4950/head
jml1795 6 years ago committed by Jussi Pakkanen
parent 2cede4d6c9
commit a9e63568fe
  1. 2
      docs/markdown/Builtin-options.md
  2. 2
      docs/markdown/Configuring-a-build-directory.md
  3. 3
      docs/markdown/snippets/warning_level_0.md
  4. 15
      mesonbuild/compilers/c.py
  5. 11
      mesonbuild/compilers/compilers.py
  6. 12
      mesonbuild/compilers/cpp.py
  7. 3
      mesonbuild/compilers/cuda.py
  8. 7
      mesonbuild/compilers/d.py
  9. 18
      mesonbuild/compilers/fortran.py
  10. 6
      mesonbuild/compilers/objc.py
  11. 6
      mesonbuild/compilers/objcpp.py
  12. 2
      mesonbuild/coredata.py
  13. 27
      run_unittests.py
  14. 12
      test cases/common/213 warning level 0/main.cpp
  15. 3
      test cases/common/213 warning level 0/meson.build

@ -40,7 +40,7 @@ Installation options are all relative to the prefix, except:
| localstatedir | var | Localstate data directory |
| sharedstatedir | com | Architecture-independent data directory |
| werror | false | Treat warnings as errors |
| warning_level {1, 2, 3} | 1 | Set the warning level. From 1 = lowest to 3 = highest |
| warning_level {0, 1, 2, 3} | 1 | Set the warning level. From 0 = none to 3 = highest |
| layout {mirror,flat} | mirror | Build directory layout. |
| default_library {shared, static, both} | shared | Default library type. |
| backend {ninja, vs,<br>vs2010, vs2015, vs2017, xcode} | | Backend to use (default: ninja). |

@ -33,7 +33,7 @@ sample output for a simple project.
optimization 3 [0, g, 1, 2, 3, s] Optimization level
strip false [true, false] Strip targets on install
unity off [on, off, subprojects] Unity build
warning_level 1 [1, 2, 3] Compiler warning level to use
warning_level 1 [0, 1, 2, 3] Compiler warning level to use
werror false [true, false] Treat warnings as errors
Backend options:

@ -0,0 +1,3 @@
## Add warning_level 0 option
Adds support for a warning level 0 which does not enable any static analysis checks from the compiler

@ -1209,7 +1209,8 @@ class ClangCCompiler(ClangCompiler, CCompiler):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
ClangCompiler.__init__(self, compiler_type)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
@ -1243,7 +1244,8 @@ class ArmclangCCompiler(ArmclangCompiler, CCompiler):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
ArmclangCompiler.__init__(self, compiler_type)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
@ -1271,7 +1273,8 @@ class GnuCCompiler(GnuCompiler, CCompiler):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
GnuCompiler.__init__(self, compiler_type, defines)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
@ -1341,7 +1344,8 @@ class IntelCCompiler(IntelCompiler, CCompiler):
IntelCompiler.__init__(self, compiler_type)
self.lang_header = 'c-header'
default_warn_args = ['-Wall', '-w3', '-diag-disable:remark']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra']}
@ -1383,7 +1387,8 @@ class VisualStudioCCompiler(CCompiler):
# /showIncludes is needed for build dependency tracking in Ninja
# See: https://ninja-build.org/manual.html#_deps
self.always_args = ['/nologo', '/showIncludes']
self.warn_args = {'1': ['/W2'],
self.warn_args = {'0': ['/W1'],
'1': ['/W2'],
'2': ['/W3'],
'3': ['/W4']}
self.base_options = ['b_pch', 'b_ndebug', 'b_vscrt'] # FIXME add lto, pgo and the like

@ -21,7 +21,7 @@ from .. import coredata
from .. import mlog
from .. import mesonlib
from ..mesonlib import (
EnvironmentException, MachineChoice, MesonException, OrderedSet,
EnvironmentException, MesonException, OrderedSet,
version_compare, Popen_safe
)
@ -1636,7 +1636,8 @@ class PGICompiler:
self.compiler_type = compiler_type
default_warn_args = ['-Minform=inform']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args,
'3': default_warn_args}
@ -1937,7 +1938,8 @@ class ArmCompiler:
self.id = 'arm'
self.compiler_type = compiler_type
default_warn_args = []
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + [],
'3': default_warn_args + []}
# Assembly
@ -2029,7 +2031,8 @@ class CcrxCompiler:
# Assembly
self.can_compile_suffixes.update('s')
default_warn_args = []
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + [],
'3': default_warn_args + []}

@ -135,7 +135,8 @@ class ClangCPPCompiler(ClangCompiler, CPPCompiler):
CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
ClangCompiler.__init__(self, compiler_type)
default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
@ -166,7 +167,8 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler):
CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
ArmclangCompiler.__init__(self, compiler_type)
default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
@ -194,7 +196,8 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler):
CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap, **kwargs)
GnuCompiler.__init__(self, compiler_type, defines)
default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
@ -272,7 +275,8 @@ class IntelCPPCompiler(IntelCompiler, CPPCompiler):
self.lang_header = 'c++-header'
default_warn_args = ['-Wall', '-w3', '-diag-disable:remark',
'-Wpch-messages', '-Wnon-virtual-dtor']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra']}

@ -28,7 +28,8 @@ class CudaCompiler(Compiler):
self.exe_wrapper = exe_wrapper
self.id = 'nvcc'
default_warn_args = []
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Xcompiler=-Wextra'],
'3': default_warn_args + ['-Xcompiler=-Wextra',
'-Xcompiler=-Wpedantic']}

@ -498,7 +498,8 @@ class GnuDCompiler(DCompiler):
DCompiler.__init__(self, exelist, version, is_cross, arch, **kwargs)
self.id = 'gcc'
default_warn_args = ['-Wall', '-Wdeprecated']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
self.base_options = ['b_colorout', 'b_sanitize', 'b_staticpic', 'b_vscrt']
@ -569,8 +570,10 @@ class LLVMDCompiler(DCompiler):
def get_warn_args(self, level):
if level == '2' or level == '3':
return ['-wi', '-dw']
else:
elif level == '1':
return ['-wi']
else:
return []
def get_buildtype_args(self, buildtype):
if buildtype != 'plain':

@ -280,7 +280,8 @@ class GnuFortranCompiler(GnuCompiler, FortranCompiler):
FortranCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
GnuCompiler.__init__(self, compiler_type, defines)
default_warn_args = ['-Wall']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
@ -307,7 +308,8 @@ class G95FortranCompiler(FortranCompiler):
FortranCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwags)
self.id = 'g95'
default_warn_args = ['-Wall']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-pedantic']}
@ -352,7 +354,8 @@ class IntelFortranCompiler(IntelCompiler, FortranCompiler):
IntelCompiler.__init__(self, CompilerType.ICC_STANDARD)
self.id = 'intel'
default_warn_args = ['-warn', 'general', '-warn', 'truncated_source']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-warn', 'unused'],
'3': ['-warn', 'all']}
@ -374,7 +377,8 @@ class PathScaleFortranCompiler(FortranCompiler):
FortranCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwags)
self.id = 'pathscale'
default_warn_args = ['-fullwarn']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args,
'3': default_warn_args}
@ -394,7 +398,8 @@ class FlangFortranCompiler(ClangCompiler, FortranCompiler):
ClangCompiler.__init__(self, CompilerType.CLANG_STANDARD)
self.id = 'flang'
default_warn_args = ['-Minform=inform']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args,
'3': default_warn_args}
@ -403,7 +408,8 @@ class Open64FortranCompiler(FortranCompiler):
FortranCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwags)
self.id = 'open64'
default_warn_args = ['-fullwarn']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args,
'3': default_warn_args}

@ -55,7 +55,8 @@ class GnuObjCCompiler(GnuCompiler, ObjCCompiler):
ObjCCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
GnuCompiler.__init__(self, compiler_type, defines)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
@ -65,7 +66,8 @@ class ClangObjCCompiler(ClangCompiler, ObjCCompiler):
ObjCCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
ClangCompiler.__init__(self, compiler_type)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage']

@ -53,7 +53,8 @@ class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler):
ObjCPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
GnuCompiler.__init__(self, compiler_type, defines)
default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
@ -63,7 +64,8 @@ class ClangObjCPPCompiler(ClangCompiler, ObjCPPCompiler):
ObjCPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
ClangCompiler.__init__(self, compiler_type)
default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor']
self.warn_args = {'1': default_warn_args,
self.warn_args = {'0': [],
'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage']

@ -834,7 +834,7 @@ builtin_options = {
'localstatedir': [UserStringOption, 'Localstate data directory', 'var'],
'sharedstatedir': [UserStringOption, 'Architecture-independent data directory', 'com'],
'werror': [UserBooleanOption, 'Treat warnings as errors', False],
'warning_level': [UserComboOption, 'Compiler warning level to use', ['1', '2', '3'], '1'],
'warning_level': [UserComboOption, 'Compiler warning level to use', ['0', '1', '2', '3'], '1'],
'layout': [UserComboOption, 'Build directory layout', ['mirror', 'flat'], 'mirror'],
'default_library': [UserComboOption, 'Default library type', ['shared', 'static', 'both'], 'shared'],
'backend': [UserComboOption, 'Backend to use', backendlist, 'ninja'],

@ -2970,6 +2970,33 @@ recommended as it is not supported on some platforms''')
# they used to fail this test with Meson 0.46 an earlier versions.
pass
def test_warning_level_0(self):
testdir = os.path.join(self.common_test_dir, '213 warning level 0')
# Verify default values when passing no args
self.init(testdir)
obj = mesonbuild.coredata.load(self.builddir)
self.assertEqual(obj.builtins['warning_level'].value, '0')
self.wipe()
# verify we can override w/ --warnlevel
self.init(testdir, extra_args=['--warnlevel=1'])
obj = mesonbuild.coredata.load(self.builddir)
self.assertEqual(obj.builtins['warning_level'].value, '1')
self.setconf('--warnlevel=0')
obj = mesonbuild.coredata.load(self.builddir)
self.assertEqual(obj.builtins['warning_level'].value, '0')
self.wipe()
# verify we can override w/ -Dwarning_level
self.init(testdir, extra_args=['-Dwarning_level=1'])
obj = mesonbuild.coredata.load(self.builddir)
self.assertEqual(obj.builtins['warning_level'].value, '1')
self.setconf('-Dwarning_level=0')
obj = mesonbuild.coredata.load(self.builddir)
self.assertEqual(obj.builtins['warning_level'].value, '0')
self.wipe()
def test_feature_check_usage_subprojects(self):
testdir = os.path.join(self.unit_test_dir, '41 featurenew subprojects')
out = self.init(testdir)

@ -0,0 +1,12 @@
#include <iostream>
#define PROJECT_NAME "demo"
int main(int argc, char **argv) {
if(argc != 1) {
std::cout << argv[0] << "takes no arguments.\n";
return 1;
}
std::cout << "This is project " << PROJECT_NAME << ".\n";
return 0;
}

@ -0,0 +1,3 @@
project('warning_level', 'cpp', default_options : ['warning_level=0'])
exe = executable('main', 'main.cpp', install : false)
Loading…
Cancel
Save