aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/ast/introspection.py33
-rwxr-xr-xrun_unittests.py8
-rw-r--r--test cases/unit/83 cross only introspect/meson.build2
3 files changed, 31 insertions, 12 deletions
diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py
index c91bf40..f03f7d2 100644
--- a/mesonbuild/ast/introspection.py
+++ b/mesonbuild/ast/introspection.py
@@ -128,7 +128,8 @@ class IntrospectionInterpreter(AstInterpreter):
options = {k: v for k, v in self.environment.meson_options.host[''].items() if k.startswith('backend_')}
self.coredata.set_options(options)
- self.func_add_languages(None, proj_langs, None)
+ self._add_languages(proj_langs, MachineChoice.HOST)
+ self._add_languages(proj_langs, MachineChoice.BUILD)
def do_subproject(self, dirname: str) -> None:
subproject_dir_abs = os.path.join(self.environment.get_source_dir(), self.subproject_dir)
@@ -142,17 +143,25 @@ class IntrospectionInterpreter(AstInterpreter):
return
def func_add_languages(self, node: BaseNode, args: T.List[TYPE_nvar], kwargs: T.Dict[str, TYPE_nvar]) -> None:
- args = self.flatten_args(args)
- for for_machine in [MachineChoice.BUILD, MachineChoice.HOST]:
- for lang in sorted(args, key=compilers.sort_clink):
- if isinstance(lang, StringNode):
- assert isinstance(lang.value, str)
- lang = lang.value
- if not isinstance(lang, str):
- continue
- lang = lang.lower()
- if lang not in self.coredata.compilers[for_machine]:
- self.environment.detect_compiler_for(lang, for_machine)
+ kwargs = self.flatten_kwargs(kwargs)
+ if 'native' in kwargs:
+ native = kwargs.get('native', False)
+ self._add_languages(args, MachineChoice.BUILD if native else MachineChoice.HOST)
+ else:
+ for for_machine in [MachineChoice.BUILD, MachineChoice.HOST]:
+ self._add_languages(args, for_machine)
+
+ def _add_languages(self, langs: T.List[TYPE_nvar], for_machine: MachineChoice) -> None:
+ langs = self.flatten_args(langs)
+ for lang in sorted(langs, key=compilers.sort_clink):
+ if isinstance(lang, StringNode):
+ assert isinstance(lang.value, str)
+ lang = lang.value
+ if not isinstance(lang, str):
+ continue
+ lang = lang.lower()
+ if lang not in self.coredata.compilers[for_machine]:
+ self.environment.detect_compiler_for(lang, for_machine)
def func_dependency(self, node: BaseNode, args: T.List[TYPE_nvar], kwargs: T.Dict[str, TYPE_nvar]) -> None:
args = self.flatten_args(args)
diff --git a/run_unittests.py b/run_unittests.py
index 2510fce..efe1e29 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -4251,6 +4251,14 @@ recommended as it is not supported on some platforms''')
testdir = os.path.join(self.unit_test_dir, '59 introspect buildoptions')
self._run(self.mconf_command + [testdir])
+ def test_introspect_buildoptions_cross_only(self):
+ testdir = os.path.join(self.unit_test_dir, '83 cross only introspect')
+ testfile = os.path.join(testdir, 'meson.build')
+ res = self.introspect_directory(testfile, ['--buildoptions'] + self.meson_args)
+ optnames = [o['name'] for o in res]
+ self.assertIn('c_args', optnames)
+ self.assertNotIn('build.c_args', optnames)
+
def test_introspect_json_dump(self):
testdir = os.path.join(self.unit_test_dir, '57 introspection')
self.init(testdir)
diff --git a/test cases/unit/83 cross only introspect/meson.build b/test cases/unit/83 cross only introspect/meson.build
new file mode 100644
index 0000000..ed25441
--- /dev/null
+++ b/test cases/unit/83 cross only introspect/meson.build
@@ -0,0 +1,2 @@
+project('cross only introspect')
+add_languages('c', native: false)