interprter: Add required kwarg to add_(project|global)_arguments

To avoid manual compiler support checks add_project_arguments and
add_global_arguments receive a new keyword argument to perform
them automatically.
pull/8898/head
Laurin-Luis Lehning 3 years ago
parent 2e8729a7e6
commit c9ad98ef5e
  1. 8
      docs/markdown/snippets/required_project_arguments.md
  2. 18
      mesonbuild/interpreter/interpreter.py
  3. 1
      mesonbuild/interpreter/kwargs.py
  4. 3
      test cases/failing/115 required project arguments/meson.build
  5. 7
      test cases/failing/115 required project arguments/test.json

@ -0,0 +1,8 @@
# Required project & global arguments
The `add_global_arguments` & `add_project_arguments` functions now
support an optional keyword argument named `required`. Setting it
to `true` will cause Meson to perform compiler support checks on
each of the passed arguments as if by calling `has_argument`, which
means manual checks can now be avoided and instead expressed more
tersely.

@ -2321,8 +2321,9 @@ This will become a hard error in the future.''' % kwargs['input'], location=self
self.build.test_setups[setup_name] = build.TestSetup(exe_wrapper, gdb, timeout_multiplier, env,
exclude_suites)
@FeatureNewKwargs('add_global_arguments', '0.59.0', ['required'])
@typed_pos_args('add_global_arguments', varargs=str)
@typed_kwargs('add_global_arguments', _NATIVE_KW, _LANGUAGE_KW)
@typed_kwargs('add_global_arguments', _NATIVE_KW, _LANGUAGE_KW, KwargInfo('required', bool, default=False))
def func_add_global_arguments(self, node: mparser.FunctionNode, args: T.Tuple[T.List[str]], kwargs: 'kwargs.FuncAddProjectArgs') -> None:
self._add_global_arguments(node, self.build.global_args[kwargs['native']], args[0], kwargs)
@ -2331,8 +2332,9 @@ This will become a hard error in the future.''' % kwargs['input'], location=self
def func_add_global_link_arguments(self, node: mparser.FunctionNode, args: T.Tuple[T.List[str]], kwargs: 'kwargs.FuncAddProjectArgs') -> None:
self._add_global_arguments(node, self.build.global_link_args[kwargs['native']], args[0], kwargs)
@FeatureNewKwargs('add_project_arguments', '0.59.0', ['required'])
@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, KwargInfo('required', bool, default=False))
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)
@ -2398,6 +2400,18 @@ This will become a hard error in the future.''' % kwargs['input'], location=self
self._warn_about_builtin_args(args)
try:
if kwargs['required']:
compilers = self.coredata.compilers.build.values() if kwargs['native'] \
else self.coredata.compilers.host.values()
for c in compilers:
for arg in args:
if not c.has_multi_arguments([arg], self.environment)[0]:
raise mesonlib.MesonException(f'C compiler does not support "{arg}"')
except KeyError:
pass
for lang in kwargs['language']:
argsdict[lang] = argsdict.get(lang, []) + args

@ -27,6 +27,7 @@ class FuncAddProjectArgs(TypedDict):
native: MachineChoice
language: T.List[str]
required: bool
class BaseTest(TypedDict):

@ -0,0 +1,3 @@
project('add_project_arguments test', 'c')
add_project_arguments('-meson-goober-arg-for-testing', language : 'c', required : true)

@ -0,0 +1,7 @@
{
"stdout": [
{
"line": "test cases/failing/115 required project arguments/meson.build:3:0: ERROR: C compiler does not support \"-meson-goober-arg-for-testing\""
}
]
}
Loading…
Cancel
Save