Support multiple args in error()
Seems it got forgotten when that was added to warnings() and message(). Fixes: #8414.
This commit is contained in:
parent
4e5efd3897
commit
cef5cab23c
|
@ -580,6 +580,9 @@ Returns a [disabler object](#disabler-object).
|
||||||
|
|
||||||
Print the argument string and halts the build process.
|
Print the argument string and halts the build process.
|
||||||
|
|
||||||
|
*(since 0.58.0)* Can take more than one argument that will be separated by
|
||||||
|
space.
|
||||||
|
|
||||||
### environment()
|
### environment()
|
||||||
|
|
||||||
``` meson
|
``` meson
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
## `error()` with multiple arguments
|
||||||
|
|
||||||
|
Just like `warning()` and `message()`, `error()` can now take more than one
|
||||||
|
argument that will be separated by space.
|
|
@ -61,16 +61,16 @@ permitted_method_kwargs = {
|
||||||
'sources'},
|
'sources'},
|
||||||
}
|
}
|
||||||
|
|
||||||
def stringifyUserArguments(args):
|
def stringifyUserArguments(args, quote=False):
|
||||||
if isinstance(args, list):
|
if isinstance(args, list):
|
||||||
return '[%s]' % ', '.join([stringifyUserArguments(x) for x in args])
|
return '[%s]' % ', '.join([stringifyUserArguments(x, True) for x in args])
|
||||||
elif isinstance(args, dict):
|
elif isinstance(args, dict):
|
||||||
return '{%s}' % ', '.join(['%s : %s' % (stringifyUserArguments(k), stringifyUserArguments(v)) for k, v in args.items()])
|
return '{%s}' % ', '.join(['%s : %s' % (stringifyUserArguments(k, True), stringifyUserArguments(v, True)) for k, v in args.items()])
|
||||||
elif isinstance(args, int):
|
elif isinstance(args, int):
|
||||||
return str(args)
|
return str(args)
|
||||||
elif isinstance(args, str):
|
elif isinstance(args, str):
|
||||||
return "'%s'" % args
|
return f"'{args}'" if quote else args
|
||||||
raise InvalidArguments('Function accepts only strings, integers, lists and lists thereof.')
|
raise InvalidArguments('Function accepts only strings, integers, lists, dictionaries and lists thereof.')
|
||||||
|
|
||||||
|
|
||||||
class OverrideProgram(dependencies.ExternalProgram):
|
class OverrideProgram(dependencies.ExternalProgram):
|
||||||
|
@ -3276,26 +3276,12 @@ external dependencies (including libraries) must go to "dependencies".''')
|
||||||
success &= self.add_languages(args, required, MachineChoice.HOST)
|
success &= self.add_languages(args, required, MachineChoice.HOST)
|
||||||
return success
|
return success
|
||||||
|
|
||||||
def get_message_string_arg(self, arg):
|
|
||||||
if isinstance(arg, list):
|
|
||||||
argstr = stringifyUserArguments(arg)
|
|
||||||
elif isinstance(arg, dict):
|
|
||||||
argstr = stringifyUserArguments(arg)
|
|
||||||
elif isinstance(arg, str):
|
|
||||||
argstr = arg
|
|
||||||
elif isinstance(arg, int):
|
|
||||||
argstr = str(arg)
|
|
||||||
else:
|
|
||||||
raise InvalidArguments('Function accepts only strings, integers, lists and lists thereof.')
|
|
||||||
|
|
||||||
return argstr
|
|
||||||
|
|
||||||
@noArgsFlattening
|
@noArgsFlattening
|
||||||
@noKwargs
|
@noKwargs
|
||||||
def func_message(self, node, args, kwargs):
|
def func_message(self, node, args, kwargs):
|
||||||
if len(args) > 1:
|
if len(args) > 1:
|
||||||
FeatureNew.single_use('message with more than one argument', '0.54.0', self.subproject)
|
FeatureNew.single_use('message with more than one argument', '0.54.0', self.subproject)
|
||||||
args_str = [self.get_message_string_arg(i) for i in args]
|
args_str = [stringifyUserArguments(i) for i in args]
|
||||||
self.message_impl(args_str)
|
self.message_impl(args_str)
|
||||||
|
|
||||||
def message_impl(self, args):
|
def message_impl(self, args):
|
||||||
|
@ -3357,13 +3343,16 @@ external dependencies (including libraries) must go to "dependencies".''')
|
||||||
def func_warning(self, node, args, kwargs):
|
def func_warning(self, node, args, kwargs):
|
||||||
if len(args) > 1:
|
if len(args) > 1:
|
||||||
FeatureNew.single_use('warning with more than one argument', '0.54.0', self.subproject)
|
FeatureNew.single_use('warning with more than one argument', '0.54.0', self.subproject)
|
||||||
args_str = [self.get_message_string_arg(i) for i in args]
|
args_str = [stringifyUserArguments(i) for i in args]
|
||||||
mlog.warning(*args_str, location=node)
|
mlog.warning(*args_str, location=node)
|
||||||
|
|
||||||
|
@noArgsFlattening
|
||||||
@noKwargs
|
@noKwargs
|
||||||
def func_error(self, node, args, kwargs):
|
def func_error(self, node, args, kwargs):
|
||||||
self.validate_arguments(args, 1, [str])
|
if len(args) > 1:
|
||||||
raise InterpreterException('Problem encountered: ' + args[0])
|
FeatureNew.single_use('error with more than one argument', '0.58.0', self.subproject)
|
||||||
|
args_str = [stringifyUserArguments(i) for i in args]
|
||||||
|
raise InterpreterException('Problem encountered: ' + ' '.join(args_str))
|
||||||
|
|
||||||
@noKwargs
|
@noKwargs
|
||||||
@noPosargs
|
@noPosargs
|
||||||
|
|
|
@ -5864,6 +5864,11 @@ class FailureTests(BasePlatformTests):
|
||||||
"meson.override_dependency('zlib', declare_dependency())",
|
"meson.override_dependency('zlib', declare_dependency())",
|
||||||
"""Tried to override dependency 'zlib' which has already been resolved or overridden""")
|
"""Tried to override dependency 'zlib' which has already been resolved or overridden""")
|
||||||
|
|
||||||
|
def test_error_func(self):
|
||||||
|
self.assertMesonRaises("error('a', 'b', ['c', ['d', {'e': 'f'}]], 'g')",
|
||||||
|
"Problem encountered: a b \['c', \['d', {'e' : 'f'}\]\] g")
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(is_windows() or is_cygwin(), "requires Windows (or Windows via Cygwin)")
|
@unittest.skipUnless(is_windows() or is_cygwin(), "requires Windows (or Windows via Cygwin)")
|
||||||
class WindowsTests(BasePlatformTests):
|
class WindowsTests(BasePlatformTests):
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in New Issue