diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index 42d02e18e..ba86e48c7 100644 --- a/docs/markdown/Reference-manual.md +++ b/docs/markdown/Reference-manual.md @@ -847,6 +847,14 @@ The keyword arguments for this are the same as for [`executable`](#executable) w This function prints its argument to stdout. +### warning() + +``` meson + void warning(text) +``` + +This function prints its argument to stdout prefixed with WARNING:. + ### project() ``` meson diff --git a/docs/markdown/snippets/warning_function b/docs/markdown/snippets/warning_function new file mode 100644 index 000000000..537651ed5 --- /dev/null +++ b/docs/markdown/snippets/warning_function @@ -0,0 +1,6 @@ +# Added warning function + +This function prints its argument to the console prefixed by "WARNING:" in +yellow color. A simple example: + +warning('foo is deprecated, please use bar instead') diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 39c0de622..28cb5ad27 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1443,6 +1443,7 @@ class Interpreter(InterpreterBase): 'join_paths': self.func_join_paths, 'library': self.func_library, 'message': self.func_message, + 'warning': self.func_warning, 'option': self.func_option, 'project': self.func_project, 'run_target': self.func_run_target, @@ -1869,8 +1870,7 @@ to directly access options of other subprojects.''') def func_add_languages(self, node, args, kwargs): return self.add_languages(args, kwargs.get('required', True)) - @noKwargs - def func_message(self, node, args, kwargs): + def get_message_string_arg(self, node): # reduce arguments again to avoid flattening posargs (posargs, _) = self.reduce_arguments(node.args) if len(posargs) != 1: @@ -1886,8 +1886,18 @@ to directly access options of other subprojects.''') else: raise InvalidArguments('Function accepts only strings, integers, lists and lists thereof.') + return argstr + + @noKwargs + def func_message(self, node, args, kwargs): + argstr = self.get_message_string_arg(node) mlog.log(mlog.bold('Message:'), argstr) + @noKwargs + def func_warning(self, node, args, kwargs): + argstr = self.get_message_string_arg(node) + mlog.warning(argstr) + @noKwargs def func_error(self, node, args, kwargs): self.validate_arguments(args, 1, [str])