From cbe804947482998cc767bfb0c169e6263a6ef097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 7 Nov 2019 11:32:26 +0100 Subject: [PATCH 1/3] meson: avoid bogus meson warning With meson-0.52.0-1.module_f31+6771+f5d842eb.noarch I get: src/test/meson.build:19: WARNING: Overriding previous value of environment variable 'PATH' with a new one When we're using *prepend*, the whole point is to modify an existing variable, so meson shouldn't warn. But let's set avoid the warning and shorten things by setting the final value immediately. --- src/test/meson.build | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/meson.build b/src/test/meson.build index 6179607a43..1057082565 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -11,12 +11,11 @@ test_hashmap_ordered_c = custom_target( test_include_dir = include_directories('.') -path = run_command('sh', ['-c', 'echo "$PATH"']).stdout() +path = run_command('sh', ['-c', 'echo "$PATH"']).stdout().strip() test_env = environment() test_env.set('SYSTEMD_KBD_MODEL_MAP', kbd_model_map) test_env.set('SYSTEMD_LANGUAGE_FALLBACK_MAP', language_fallback_map) -test_env.set('PATH', path) -test_env.prepend('PATH', meson.build_root()) +test_env.set('PATH', '@0@:@1@'.format(meson.build_root(), path)) ############################################################ From 827ca90986d755b008e0002f0cd80edfc7271659 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 10 Nov 2019 11:39:15 +0100 Subject: [PATCH 2/3] meson: use warning_level=2 by default Let's bump up the warning level, and not add by -Wextra by hand. This is the approach recommended by meson. The idea is that all projects should be as similar as possible to make it easier for users to switch between projects. --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 56b7bfea70..b7017f4f40 100644 --- a/meson.build +++ b/meson.build @@ -8,6 +8,7 @@ project('systemd', 'c', 'prefix=/usr', 'sysconfdir=/etc', 'localstatedir=/var', + 'warning_level=2', ], meson_version : '>= 0.46', ) @@ -323,7 +324,6 @@ elif want_fuzzbuzz endif possible_cc_flags = [ - '-Wextra', '-Werror=undef', '-Wlogical-op', '-Wmissing-include-dirs', From e9f4f5667d18470da0e1b045d36ecebbacca0d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sun, 10 Nov 2019 12:16:41 +0100 Subject: [PATCH 3/3] meson: apply our -Wno-* options also in c++ calls We compile some c++ code for tests. We would simply use the default options for those. When the previous commit raised the default warning level, we started getting warnings from c++ code. Let's add the most important options to the c++ command, so that we get a compilation without any warnings again. I don't think it makes sense to add *all* the options that we add for c to the c++ flags, because testing them takes quite a while, and the c++ compilations are for small amounts of code, mostly to check that the headers have compatible syntax. --- meson.build | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/meson.build b/meson.build index b7017f4f40..61c2d6aa95 100644 --- a/meson.build +++ b/meson.build @@ -303,7 +303,8 @@ install_tests = get_option('install-tests') if add_languages('cpp', required : fuzzer_build) # Used only for tests - cxx_cmd = ' '.join(meson.get_compiler('cpp').cmd_array()) + cxx = meson.get_compiler('cpp') + cxx_cmd = ' '.join(cxx.cmd_array()) else cxx_cmd = '' endif @@ -323,6 +324,24 @@ elif want_fuzzbuzz fuzzing_engine = meson.get_compiler('cpp').find_library(get_option('fuzzbuzz-engine'), dirs: get_option('fuzzbuzz-engine-dir')) endif +# Those generate many false positives, and we do not want to change the code to +# avoid them. +basic_disabled_warnings = [ + '-Wno-unused-parameter', + '-Wno-missing-field-initializers', + '-Wno-unused-result', + '-Wno-format-signedness', +] +if get_option('b_ndebug') == 'true' + # With asserts disabled with get a bunch of warnings about variables which + # are used only in the asserts. This is not useful at all, so let's just silence + # those warnings. + basic_disabled_warnings += [ + '-Wno-unused-variable', + '-Wno-unused-but-set-variable', + ] +endif + possible_cc_flags = [ '-Werror=undef', '-Wlogical-op', @@ -353,10 +372,6 @@ possible_cc_flags = [ '-Wnested-externs', # negative arguments are correctly detected starting with meson 0.46. - '-Wno-unused-parameter', - '-Wno-missing-field-initializers', - '-Wno-unused-result', - '-Wno-format-signedness', '-Wno-error=#warnings', # clang '-Wno-string-plus-int', # clang @@ -401,16 +416,7 @@ if get_option('buildtype') != 'debug' possible_link_flags += '-Wl,--gc-sections' endif -if get_option('b_ndebug') == 'true' - # With asserts disabled with get a bunch of warnings about variables which - # are used only in the asserts. This is not useful at all, so let's just silence - # those warnings. - possible_cc_flags += [ - '-Wno-unused-variable', - '-Wno-unused-but-set-variable', - ] -endif - +add_project_arguments(cc.get_supported_arguments(basic_disabled_warnings), language : 'c') add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'c') add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language : 'c') @@ -427,6 +433,10 @@ if cc.compiles(''' add_project_arguments('-Werror=shadow', language : 'c') endif +if cxx_cmd != '' + add_project_arguments(cxx.get_supported_arguments(basic_disabled_warnings), language : 'cpp') +endif + cpp = ' '.join(cc.cmd_array()) + ' -E' has_wstringop_truncation = cc.has_argument('-Wstringop-truncation')