aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2023-01-22 16:27:58 -0500
committerNirbheek Chauhan <nirbheek@centricular.com>2023-02-06 23:37:55 +0530
commit03e2c70525819a4896c788d91579bf2b201f5985 (patch)
tree367bdc59f1c25a4c81f929a1600a3fc1dbf34a38
parent073c2da21276c57726d0662d4a4b26cbe0f00f68 (diff)
downloadmeson-03e2c70525819a4896c788d91579bf2b201f5985.zip
meson-03e2c70525819a4896c788d91579bf2b201f5985.tar.gz
meson-03e2c70525819a4896c788d91579bf2b201f5985.tar.bz2
introspect: avoid crashing when add_languages for an optional language fails
Because that is what the real interpreter does, too. It logs a failure and carries on.
-rw-r--r--mesonbuild/ast/introspection.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/mesonbuild/ast/introspection.py b/mesonbuild/ast/introspection.py
index 722c908..194c15b 100644
--- a/mesonbuild/ast/introspection.py
+++ b/mesonbuild/ast/introspection.py
@@ -141,8 +141,8 @@ class IntrospectionInterpreter(AstInterpreter):
options = {k: v for k, v in self.environment.options.items() if k.is_backend()}
self.coredata.set_options(options)
- self._add_languages(proj_langs, MachineChoice.HOST)
- self._add_languages(proj_langs, MachineChoice.BUILD)
+ self._add_languages(proj_langs, True, MachineChoice.HOST)
+ self._add_languages(proj_langs, True, MachineChoice.BUILD)
def do_subproject(self, dirname: str) -> None:
subproject_dir_abs = os.path.join(self.environment.get_source_dir(), self.subproject_dir)
@@ -157,14 +157,17 @@ class IntrospectionInterpreter(AstInterpreter):
def func_add_languages(self, node: BaseNode, args: T.List[TYPE_nvar], kwargs: T.Dict[str, TYPE_nvar]) -> None:
kwargs = self.flatten_kwargs(kwargs)
+ required = kwargs.get('required', True)
+ if isinstance(required, cdata.UserFeatureOption):
+ required = required.is_enabled()
if 'native' in kwargs:
native = kwargs.get('native', False)
- self._add_languages(args, MachineChoice.BUILD if native else MachineChoice.HOST)
+ self._add_languages(args, required, MachineChoice.BUILD if native else MachineChoice.HOST)
else:
for for_machine in [MachineChoice.BUILD, MachineChoice.HOST]:
- self._add_languages(args, for_machine)
+ self._add_languages(args, required, for_machine)
- def _add_languages(self, raw_langs: T.List[TYPE_nvar], for_machine: MachineChoice) -> None:
+ def _add_languages(self, raw_langs: T.List[TYPE_nvar], required: bool, for_machine: MachineChoice) -> None:
langs = [] # type: T.List[str]
for l in self.flatten_args(raw_langs):
if isinstance(l, str):
@@ -175,7 +178,14 @@ class IntrospectionInterpreter(AstInterpreter):
for lang in sorted(langs, key=compilers.sort_clink):
lang = lang.lower()
if lang not in self.coredata.compilers[for_machine]:
- comp = detect_compiler_for(self.environment, lang, for_machine)
+ try:
+ comp = detect_compiler_for(self.environment, lang, for_machine)
+ except mesonlib.MesonException:
+ # do we even care about introspecting this language?
+ if required:
+ raise
+ else:
+ continue
if self.subproject:
options = {}
for k in comp.get_options():