diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index a8e816484..58c3c0877 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 @@ -126,6 +131,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] @@ -449,7 +468,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 660b1a595..fed2b54c8 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -2101,8 +2101,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 034fef4eb..43b2336a3 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