diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2018-03-21 21:26:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-21 21:26:16 +0200 |
commit | 12bac512f6497e46ada8ed980cbcb1631506691c (patch) | |
tree | 1dfac37976c17672df41f83f3bf6562f2f92e25f | |
parent | 30827b5644b00aa01c14a116a0c8fec72e63592e (diff) | |
parent | 6910f604ed60ffc5da37b86c4ab6d3f2da618c60 (diff) | |
download | meson-12bac512f6497e46ada8ed980cbcb1631506691c.zip meson-12bac512f6497e46ada8ed980cbcb1631506691c.tar.gz meson-12bac512f6497e46ada8ed980cbcb1631506691c.tar.bz2 |
Fix b_ndebug=if-release silently not working
-rw-r--r-- | mesonbuild/backend/backends.py | 25 | ||||
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 3 | ||||
-rw-r--r-- | mesonbuild/compilers/compilers.py | 4 | ||||
-rwxr-xr-x | run_unittests.py | 14 | ||||
-rw-r--r-- | test cases/common/185 ndebug if-release enabled/main.c | 15 | ||||
-rw-r--r-- | test cases/common/185 ndebug if-release enabled/meson.build | 11 | ||||
-rw-r--r-- | test cases/common/186 ndebug if-release disabled/main.c | 7 | ||||
-rw-r--r-- | test cases/common/186 ndebug if-release disabled/meson.build | 11 | ||||
-rw-r--r-- | test cases/unit/25 ndebug if-release/main.c | 11 | ||||
-rw-r--r-- | test cases/unit/25 ndebug if-release/meson.build | 7 |
10 files changed, 102 insertions, 6 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index b8ca71f..ad45204 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -89,12 +89,17 @@ class OptionProxy: class OptionOverrideProxy: '''Mimic an option list but transparently override selected option values.''' - def __init__(self, overrides, options): + def __init__(self, overrides, *options): self.overrides = overrides self.options = options def __getitem__(self, option_name): - base_opt = self.options[option_name] + for opts in self.options: + if option_name in opts: + return self._get_override(option_name, opts[option_name]) + raise KeyError('Option not found', option_name) + + def _get_override(self, option_name, base_opt): if option_name in self.overrides: return OptionProxy(base_opt.name, base_opt.validate_value(self.overrides[option_name])) return base_opt @@ -123,6 +128,20 @@ class Backend: def get_target_filename_abs(self, target): return os.path.join(self.environment.get_build_dir(), self.get_target_filename(target)) + def get_builtin_options_for_target(self, target): + return OptionOverrideProxy(target.option_overrides, + self.environment.coredata.builtins) + + def get_base_options_for_target(self, target): + return OptionOverrideProxy(target.option_overrides, + self.environment.coredata.builtins, + self.environment.coredata.base_options) + + def get_compiler_options_for_target(self, target): + return OptionOverrideProxy(target.option_overrides, + # no code depends on builtins for now + self.environment.coredata.compiler_options) + def get_option_for_target(self, option_name, target): if option_name in target.option_overrides: override = target.option_overrides[option_name] @@ -444,7 +463,7 @@ class Backend: # starting from hard-coded defaults followed by build options and so on. commands = CompilerArgs(compiler) - copt_proxy = OptionOverrideProxy(target.option_overrides, self.environment.coredata.compiler_options) + copt_proxy = self.get_compiler_options_for_target(target) # First, the trivial ones that are impossible to override. # # Add -nostdinc/-nostdinc++ if needed; can't be overridden diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index f0ea09b..39e4ce9 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -2137,8 +2137,7 @@ rule FORTRAN_DEP_HACK return incs def _generate_single_compile(self, target, compiler, is_generated=False): - base_proxy = backends.OptionOverrideProxy(target.option_overrides, - self.environment.coredata.base_options) + base_proxy = self.get_base_options_for_target(target) # Create an empty commands list, and start adding arguments from # various sources in the order in which they must override each other commands = CompilerArgs(compiler) diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index f8dfc96..65c942b 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -315,7 +315,9 @@ def get_base_compile_args(options, compiler): except KeyError: pass try: - if options['b_ndebug'].value == 'true' or (options['b_ndebug'].value == 'if-release' and options['buildtype'] == 'release'): + if (options['b_ndebug'].value == 'true' or + (options['b_ndebug'].value == 'if-release' and + options['buildtype'].value == 'release')): args += ['-DNDEBUG'] except KeyError: pass diff --git a/run_unittests.py b/run_unittests.py index b6367c1..94e39c8 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -1895,6 +1895,20 @@ int main(int argc, char **argv) { exception_raised = True self.assertTrue(exception_raised, 'Double locking did not raise exception.') + def test_ndebug_if_release_disabled(self): + testdir = os.path.join(self.unit_test_dir, '25 ndebug if-release') + self.init(testdir, extra_args=['--buildtype=release', '-Db_ndebug=if-release']) + self.build() + exe = os.path.join(self.builddir, 'main') + self.assertEqual(b'NDEBUG=1', subprocess.check_output(exe).strip()) + + def test_ndebug_if_release_enabled(self): + testdir = os.path.join(self.unit_test_dir, '25 ndebug if-release') + self.init(testdir, extra_args=['--buildtype=debugoptimized', '-Db_ndebug=if-release']) + self.build() + exe = os.path.join(self.builddir, 'main') + self.assertEqual(b'NDEBUG=0', subprocess.check_output(exe).strip()) + class FailureTests(BasePlatformTests): ''' diff --git a/test cases/common/185 ndebug if-release enabled/main.c b/test cases/common/185 ndebug if-release enabled/main.c new file mode 100644 index 0000000..984ebca --- /dev/null +++ b/test cases/common/185 ndebug if-release enabled/main.c @@ -0,0 +1,15 @@ +#include <assert.h> +#include <stdlib.h> + +int meson_test_side_effect = EXIT_FAILURE; + +int meson_test_set_side_effect(void) { + meson_test_side_effect = EXIT_SUCCESS; + return 1; +} + +int main(void) { + // meson_test_side_effect is set only if assert is executed + assert(meson_test_set_side_effect()); + return meson_test_side_effect; +} diff --git a/test cases/common/185 ndebug if-release enabled/meson.build b/test cases/common/185 ndebug if-release enabled/meson.build new file mode 100644 index 0000000..ac4f0e7 --- /dev/null +++ b/test cases/common/185 ndebug if-release enabled/meson.build @@ -0,0 +1,11 @@ +project('ndebug enabled', 'c', + default_options : [ + 'buildtype=debugoptimized', + 'b_ndebug=if-release', + ]) + +if meson.get_compiler('c').get_id() == 'msvc' + error('MESON_SKIP_TEST b_ndebug is not supported on Visual Studio') +endif + +test('exe', executable('main', 'main.c')) diff --git a/test cases/common/186 ndebug if-release disabled/main.c b/test cases/common/186 ndebug if-release disabled/main.c new file mode 100644 index 0000000..cb3ec3f --- /dev/null +++ b/test cases/common/186 ndebug if-release disabled/main.c @@ -0,0 +1,7 @@ +#include <assert.h> +#include <stdlib.h> + +int main(void) { + assert(0); + return EXIT_SUCCESS; +} diff --git a/test cases/common/186 ndebug if-release disabled/meson.build b/test cases/common/186 ndebug if-release disabled/meson.build new file mode 100644 index 0000000..f2678ed --- /dev/null +++ b/test cases/common/186 ndebug if-release disabled/meson.build @@ -0,0 +1,11 @@ +project('ndebug disabled', 'c', + default_options : [ + 'buildtype=release', + 'b_ndebug=if-release', + ]) + +if meson.get_compiler('c').get_id() == 'msvc' + error('MESON_SKIP_TEST b_ndebug is not supported on Visual Studio') +endif + +test('exe', executable('main', 'main.c')) diff --git a/test cases/unit/25 ndebug if-release/main.c b/test cases/unit/25 ndebug if-release/main.c new file mode 100644 index 0000000..70b3d04 --- /dev/null +++ b/test cases/unit/25 ndebug if-release/main.c @@ -0,0 +1,11 @@ +#include <stdio.h> +#include <stdlib.h> + +int main(void) { +#ifdef NDEBUG + printf("NDEBUG=1\n"); +#else + printf("NDEBUG=0\n"); +#endif + return 0; +} diff --git a/test cases/unit/25 ndebug if-release/meson.build b/test cases/unit/25 ndebug if-release/meson.build new file mode 100644 index 0000000..d45bd86 --- /dev/null +++ b/test cases/unit/25 ndebug if-release/meson.build @@ -0,0 +1,7 @@ +project('ndebug enabled', 'c') + +if meson.get_compiler('c').get_id() == 'msvc' + error('MESON_SKIP_TEST b_ndebug is not supported on Visual Studio') +endif + +executable('main', 'main.c') |