aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/snippets/compiler_argument_checking.md6
-rw-r--r--docs/markdown/snippets/required_project_arguments.md8
-rw-r--r--mesonbuild/interpreter/compiler.py19
-rw-r--r--mesonbuild/interpreter/interpreter.py21
-rw-r--r--mesonbuild/interpreter/kwargs.py1
-rw-r--r--test cases/failing/115 compiler argument checking/meson.build4
-rw-r--r--test cases/failing/115 compiler argument checking/test.json7
-rw-r--r--test cases/failing/115 required project arguments/meson.build3
-rw-r--r--test cases/failing/115 required project arguments/test.json7
9 files changed, 35 insertions, 41 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/docs/markdown/snippets/required_project_arguments.md b/docs/markdown/snippets/required_project_arguments.md
deleted file mode 100644
index 40af830..0000000
--- a/docs/markdown/snippets/required_project_arguments.md
+++ /dev/null
@@ -1,8 +0,0 @@
-## 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.
diff --git a/mesonbuild/interpreter/compiler.py b/mesonbuild/interpreter/compiler.py
index bf32be3..9a6beeb 100644
--- a/mesonbuild/interpreter/compiler.py
+++ b/mesonbuild/interpreter/compiler.py
@@ -1,4 +1,5 @@
import functools
+from mesonbuild.interpreterbase.decorators import typed_kwargs, KwargInfo
from .interpreterobjects import (extract_required_kwarg, extract_search_dirs)
@@ -684,12 +685,24 @@ class CompilerHolder(ObjectHolder['Compiler']):
return result
@FeatureNew('compiler.get_supported_arguments', '0.43.0')
- @permittedKwargs({})
- def get_supported_arguments_method(self, args, kwargs):
+ @FeatureNewKwargs('compiler.get_supported_arguments', '0.59.0', ['checked'])
+ @typed_kwargs('compiler.get_supported_arguments', KwargInfo('checked', str, default='off'))
+ 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')
+
+ if checked not in ['warn', 'require', 'off']:
+ raise mesonlib.MesonException('"checked" kwarg must be one of "warn", "require" or "off"')
+
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 95537fd..5be99b4 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -2321,9 +2321,8 @@ 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, KwargInfo('required', bool, default=False))
+ @typed_kwargs('add_global_arguments', _NATIVE_KW, _LANGUAGE_KW)
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)
@@ -2332,9 +2331,8 @@ 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_project_arguments', _NATIVE_KW, _LANGUAGE_KW, KwargInfo('required', bool, default=False))
+ @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)
@@ -2400,21 +2398,6 @@ 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'] == MachineChoice.BUILD \
- else self.coredata.compilers.host.values()
-
- for c in compilers:
- if not c.language in kwargs['language']:
- continue
-
- 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
diff --git a/mesonbuild/interpreter/kwargs.py b/mesonbuild/interpreter/kwargs.py
index e1ff2a8..1cc2082 100644
--- a/mesonbuild/interpreter/kwargs.py
+++ b/mesonbuild/interpreter/kwargs.py
@@ -27,7 +27,6 @@ class FuncAddProjectArgs(TypedDict):
native: MachineChoice
language: T.List[str]
- required: bool
class BaseTest(TypedDict):
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\""
+ }
+ ]
+}
diff --git a/test cases/failing/115 required project arguments/meson.build b/test cases/failing/115 required project arguments/meson.build
deleted file mode 100644
index a871cdf..0000000
--- a/test cases/failing/115 required project arguments/meson.build
+++ /dev/null
@@ -1,3 +0,0 @@
-project('add_project_arguments test', 'c')
-
-add_project_arguments('-meson-goober-arg-for-testing', language : 'c', required : true)
diff --git a/test cases/failing/115 required project arguments/test.json b/test cases/failing/115 required project arguments/test.json
deleted file mode 100644
index e7e0c60..0000000
--- a/test cases/failing/115 required project arguments/test.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "stdout": [
- {
- "line": "test cases/failing/115 required project arguments/meson.build:3:0: ERROR: C compiler does not support \"-meson-goober-arg-for-testing\""
- }
- ]
-}