diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2017-03-12 22:13:26 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2017-04-02 00:07:23 +0300 |
commit | 319398f0749890a57a661ddb4524e93f86a0d41e (patch) | |
tree | 526d876fe6bc78f6411ea31dcb188bbe925202ce /mesonbuild/backend | |
parent | cf97c7af813ef39a7edf0693a4b127d30ad9cc55 (diff) | |
download | meson-319398f0749890a57a661ddb4524e93f86a0d41e.zip meson-319398f0749890a57a661ddb4524e93f86a0d41e.tar.gz meson-319398f0749890a57a661ddb4524e93f86a0d41e.tar.bz2 |
Proxy object for overriding options transparently.
Diffstat (limited to 'mesonbuild/backend')
-rw-r--r-- | mesonbuild/backend/backends.py | 22 | ||||
-rw-r--r-- | mesonbuild/backend/ninjabackend.py | 11 |
2 files changed, 31 insertions, 2 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 93a75ec..e8cbe5d 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -76,6 +76,24 @@ class TestSerialisation: self.workdir = workdir self.extra_paths = extra_paths +class OptionProxy: + def __init__(self, name, value): + self.name = name + self.value = value + +class OptionOverrideProxy: + '''Mimic an option list but transparently override +selected option values.''' + def __init__(self, overrides, options): + self.overrides = overrides + self.options = options + + def __getitem__(self, option_name): + base_opt = self.options[option_name] + if option_name in self.overrides: + return OptionProxy(base_opt.name, base_opt.validate_value(self.overrides[option_name])) + return base_opt + # This class contains the basic functionality that is needed by all backends. # Feel free to move stuff in and out of it as you see fit. class Backend: @@ -348,6 +366,8 @@ class Backend: # various sources in the order in which they must override each other # 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) # First, the trivial ones that are impossible to override. # # Add -nostdinc/-nostdinc++ if needed; can't be overriden @@ -368,7 +388,7 @@ class Backend: commands += compiler.get_werror_args() # Add compile args for c_* or cpp_* build options set on the # command-line or default_options inside project(). - commands += compiler.get_option_compile_args(self.environment.coredata.compiler_options) + commands += compiler.get_option_compile_args(copt_proxy) # Add buildtype args: optimization level, debugging, etc. commands += compiler.get_buildtype_args(self.get_option_for_target('buildtype', target)) # Add compile args added using add_project_arguments() diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index e1e239f..d54cacf 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1810,13 +1810,15 @@ 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) # 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) # Add compiler args for compiling this target derived from 'base' build # options passed on the command-line, in default_options, etc. # These have the lowest priority. - commands += compilers.get_base_compile_args(self.environment.coredata.base_options, + commands += compilers.get_base_compile_args(base_proxy, compiler) # The code generated by valac is usually crap and has tons of unused # variables and such, so disable warnings for Vala C sources. @@ -1888,6 +1890,13 @@ rule FORTRAN_DEP_HACK raise AssertionError('BUG: sources should not contain headers {!r}'.format(src)) if isinstance(src, RawFilename) and src.fname.endswith('.h'): raise AssertionError('BUG: sources should not contain headers {!r}'.format(src.fname)) + extra_orderdeps = [] + compiler = get_compiler_for_source(target.compilers.values(), src) + + if isinstance(src, str) and src.endswith('.h'): + raise AssertionError('BUG: sources should not contain headers {!r}'.format(src)) + if isinstance(src, RawFilename) and src.fname.endswith('.h'): + raise AssertionError('BUG: sources should not contain headers {!r}'.format(src.fname)) compiler = get_compiler_for_source(target.compilers.values(), src) key = (target, compiler, is_generated) if key in self.target_arg_cache: |