interpreter: Add warning function
This commit is contained in:
parent
7b9843da02
commit
1540e615f1
|
@ -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
|
||||
|
|
|
@ -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')
|
|
@ -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])
|
||||
|
|
Loading…
Reference in New Issue