Fix b_ndebug=if-release silently not working

pull/3288/head
Jussi Pakkanen 7 years ago committed by GitHub
commit 12bac512f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      mesonbuild/backend/backends.py
  2. 3
      mesonbuild/backend/ninjabackend.py
  3. 4
      mesonbuild/compilers/compilers.py
  4. 14
      run_unittests.py
  5. 15
      test cases/common/185 ndebug if-release enabled/main.c
  6. 11
      test cases/common/185 ndebug if-release enabled/meson.build
  7. 7
      test cases/common/186 ndebug if-release disabled/main.c
  8. 11
      test cases/common/186 ndebug if-release disabled/meson.build
  9. 11
      test cases/unit/25 ndebug if-release/main.c
  10. 7
      test cases/unit/25 ndebug if-release/meson.build

@ -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

@ -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)

@ -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

@ -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):
'''

@ -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;
}

@ -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'))

@ -0,0 +1,7 @@
#include <assert.h>
#include <stdlib.h>
int main(void) {
assert(0);
return EXIT_SUCCESS;
}

@ -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'))

@ -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;
}

@ -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')
Loading…
Cancel
Save