Merge pull request #8898 from e820/interpreter-required-arguments

interpreter: Add checked kwarg to compiler.get_supported_arguments
pull/8912/head
Dylan Baker 3 years ago committed by GitHub
commit a44c1d18c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      docs/markdown/snippets/compiler_argument_checking.md
  2. 20
      mesonbuild/interpreter/compiler.py
  3. 2
      mesonbuild/interpreter/interpreter.py
  4. 4
      test cases/failing/115 compiler argument checking/meson.build
  5. 7
      test cases/failing/115 compiler argument checking/test.json

@ -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.

@ -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

@ -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)

@ -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')

@ -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\""
}
]
}
Loading…
Cancel
Save