diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2021-06-22 09:50:24 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-22 09:50:24 -0700 |
commit | a44c1d18c19b607d443e0ee6247c97a42545c6f4 (patch) | |
tree | b0fd11a1ea1b0c8b1e8031a02e135f863792ff1d | |
parent | bee4dc9f78ad6f6d81df34816d28c06520e972a1 (diff) | |
parent | 281f5abee342b7b53ea50dd8280df4a410382f75 (diff) | |
download | meson-a44c1d18c19b607d443e0ee6247c97a42545c6f4.zip meson-a44c1d18c19b607d443e0ee6247c97a42545c6f4.tar.gz meson-a44c1d18c19b607d443e0ee6247c97a42545c6f4.tar.bz2 |
Merge pull request #8898 from e820/interpreter-required-arguments
interpreter: Add checked kwarg to compiler.get_supported_arguments
5 files changed, 35 insertions, 4 deletions
diff --git a/docs/markdown/snippets/compiler_argument_checking.md b/docs/markdown/snippets/compiler_argument_checking.md new file mode 100644 index 0000000..0e038ec --- /dev/null +++ b/docs/markdown/snippets/compiler_argument_checking.md @@ -0,0 +1,6 @@ +## Compiler argument checking for `get_supported_arguments` + +The compiler method `get_supported_arguments` now supports +a new keyword argument named `checked` that can be set to +one of `warn`, `require` or `off` (defaults to `off`) to +enforce argument checks. diff --git a/mesonbuild/interpreter/compiler.py b/mesonbuild/interpreter/compiler.py index bf32be3..b1eef2f 100644 --- a/mesonbuild/interpreter/compiler.py +++ b/mesonbuild/interpreter/compiler.py @@ -1,5 +1,7 @@ import functools +from ..interpreterbase.decorators import typed_kwargs, KwargInfo + from .interpreterobjects import (extract_required_kwarg, extract_search_dirs) from .. import mesonlib @@ -684,12 +686,24 @@ class CompilerHolder(ObjectHolder['Compiler']): return result @FeatureNew('compiler.get_supported_arguments', '0.43.0') - @permittedKwargs({}) - def get_supported_arguments_method(self, args, kwargs): + @typed_kwargs( + 'compiler.get_supported_arguments', + KwargInfo('checked', str, default='off', since='0.59.0', + validator=lambda s: 'must be one of "warn", "require" or "off"' if s not in ['warn', 'require', 'off'] else None) + ) + def get_supported_arguments_method(self, args: T.Sequence[str], kwargs: T.Dict[str, T.Any]): args = mesonlib.stringlistify(args) supported_args = [] + checked = kwargs.pop('checked') + for arg in args: - if self.has_argument_method(arg, kwargs): + if not self.has_argument_method(arg, kwargs): + msg = f'Compiler for {self.compiler.get_display_language()} does not support "{arg}"' + if checked == 'warn': + mlog.warning(msg) + elif checked == 'require': + raise mesonlib.MesonException(msg) + else: supported_args.append(arg) return supported_args diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index be17c9a..5be99b4 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -2332,7 +2332,7 @@ This will become a hard error in the future.''' % kwargs['input'], location=self self._add_global_arguments(node, self.build.global_link_args[kwargs['native']], args[0], kwargs) @typed_pos_args('add_project_arguments', varargs=str) - @typed_kwargs('add_global_arguments', _NATIVE_KW, _LANGUAGE_KW) + @typed_kwargs('add_project_arguments', _NATIVE_KW, _LANGUAGE_KW) def func_add_project_arguments(self, node: mparser.FunctionNode, args: T.Tuple[T.List[str]], kwargs: 'kwargs.FuncAddProjectArgs') -> None: self._add_project_arguments(node, self.build.projects_args[kwargs['native']], args[0], kwargs) diff --git a/test cases/failing/115 compiler argument checking/meson.build b/test cases/failing/115 compiler argument checking/meson.build new file mode 100644 index 0000000..bb1f447 --- /dev/null +++ b/test cases/failing/115 compiler argument checking/meson.build @@ -0,0 +1,4 @@ +project('compiler argument checking test', 'c') + +cc = meson.get_compiler('c') +add_project_arguments(cc.get_supported_arguments('-meson-goober-arg-for-testing', checked : 'require'), language : 'c') diff --git a/test cases/failing/115 compiler argument checking/test.json b/test cases/failing/115 compiler argument checking/test.json new file mode 100644 index 0000000..93f9476 --- /dev/null +++ b/test cases/failing/115 compiler argument checking/test.json @@ -0,0 +1,7 @@ +{ + "stdout": [ + { + "line": "test cases/failing/115 compiler argument checking/meson.build:4:0: ERROR: Compiler for C does not support \"-meson-goober-arg-for-testing\"" + } + ] +} |