diff options
author | John Ericson <git@JohnEricson.me> | 2019-02-24 14:32:29 -0500 |
---|---|---|
committer | John Ericson <git@JohnEricson.me> | 2019-06-09 13:13:29 -0400 |
commit | 2ddb1af29462fb645d522aea31f4caba57311adf (patch) | |
tree | d064e45f6f1cd6652e24bd8ce6530e2687247253 | |
parent | 3b54f38c845e0b3330a2e1fe3985884eb005e856 (diff) | |
download | meson-2ddb1af29462fb645d522aea31f4caba57311adf.zip meson-2ddb1af29462fb645d522aea31f4caba57311adf.tar.gz meson-2ddb1af29462fb645d522aea31f4caba57311adf.tar.bz2 |
Simplify and dedup machine kwarg -> MachineChoice logic in the interpreter
-rw-r--r-- | mesonbuild/interpreter.py | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 5dddb22..673644b 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1035,12 +1035,8 @@ class CompilerHolder(InterpreterObject): idir = os.path.join(self.environment.get_source_dir(), i.held_object.get_curdir(), idir) args += self.compiler.get_include_args(idir, False) - native = kwargs.get('native', None) - if native: - for_machine = MachineChoice.BUILD - else: - for_machine = MachineChoice.HOST if not nobuiltins: + for_machine = Interpreter.machine_from_native_kwarg(kwargs) opts = self.environment.coredata.compiler_options[for_machine] args += self.compiler.get_option_compile_args(opts) if mode == 'link': @@ -1841,12 +1837,7 @@ class MesonMain(InterpreterObject): if len(args) != 1: raise InterpreterException('get_compiler_method must have one and only one argument.') cname = args[0] - native = kwargs.get('native', None) - if native is None: - if self.build.environment.is_cross_build(): - native = False - else: - native = True + native = kwargs.get('native', False) if not isinstance(native, bool): raise InterpreterException('Type of "native" must be a boolean.') clist = self.interpreter.coredata.compilers[MachineChoice.BUILD if native else MachineChoice.HOST] @@ -2937,7 +2928,7 @@ external dependencies (including libraries) must go to "dependencies".''') def _find_cached_dep(self, name, kwargs): # Check if we want this as a build-time / build machine or runt-time / # host machine dep. - for_machine = MachineChoice.BUILD if kwargs.get('native', False) else MachineChoice.HOST + for_machine = Interpreter.machine_from_native_kwarg(kwargs) identifier = dependencies.get_dep_identifier(name, kwargs) cached_dep = self.coredata.deps[for_machine].get(identifier) @@ -4086,10 +4077,7 @@ Try setting b_lundef to false instead.'''.format(self.coredata.base_options['b_s if not args: raise InterpreterException('Target does not have a name.') name, *sources = args - if kwargs.get('native', False): - for_machine = MachineChoice.BUILD - else: - for_machine = MachineChoice.HOST + for_machine = Interpreter.machine_from_native_kwarg(kwargs) if 'sources' in kwargs: sources += listify(kwargs['sources']) sources = self.source_strings_to_files(sources) @@ -4231,3 +4219,7 @@ This will become a hard error in the future.''', location=self.current_node) raise InvalidCode('Is_variable takes two arguments.') varname = args[0] return varname in self.variables + + @staticmethod + def machine_from_native_kwarg(kwargs): + return MachineChoice.BUILD if kwargs.get('native', False) else MachineChoice.HOST |