From 03b86cdbed3cec9f60d3a683bcbde16c0a96ec1b Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sat, 11 Apr 2020 17:12:49 +0200 Subject: [PATCH] opts: Allow `-` and `not` in meson_options.txt (fixes #6948) --- mesonbuild/optinterpreter.py | 10 ++++++++++ test cases/common/43 options/meson.build | 4 ++++ test cases/common/43 options/meson_options.txt | 5 +++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/mesonbuild/optinterpreter.py b/mesonbuild/optinterpreter.py index 2695a269c..c13cc5da3 100644 --- a/mesonbuild/optinterpreter.py +++ b/mesonbuild/optinterpreter.py @@ -166,6 +166,16 @@ class OptionInterpreter: return arg.value elif isinstance(arg, mparser.ArrayNode): return [self.reduce_single(curarg) for curarg in arg.args.arguments] + elif isinstance(arg, mparser.UMinusNode): + res = self.reduce_single(arg.value) + if not isinstance(res, (int, float)): + raise OptionException('Token after "-" is not a number') + return -res + elif isinstance(arg, mparser.NotNode): + res = self.reduce_single(arg.value) + if not isinstance(res, bool): + raise OptionException('Token after "not" is not a a boolean') + return not res else: raise OptionException('Arguments may only be string, int, bool, or array of those.') diff --git a/test cases/common/43 options/meson.build b/test cases/common/43 options/meson.build index c6cf9c8cf..08c5cca94 100644 --- a/test cases/common/43 options/meson.build +++ b/test cases/common/43 options/meson.build @@ -30,4 +30,8 @@ if get_option('integer_opt') != 3 error('Incorrect value in integer option.') endif +if get_option('neg_int_opt') != -3 + error('Incorrect value in negative integer option.') +endif + assert(get_option('wrap_mode') == 'default', 'Wrap mode option is broken.') diff --git a/test cases/common/43 options/meson_options.txt b/test cases/common/43 options/meson_options.txt index 4e1c8d810..c5986baf8 100644 --- a/test cases/common/43 options/meson_options.txt +++ b/test cases/common/43 options/meson_options.txt @@ -1,6 +1,7 @@ option('testoption', type : 'string', value : 'optval', description : 'An option to do something') -option('other_one', type : 'boolean', value : false) +option('other_one', type : 'boolean', value : not (not (not (not false)))) option('combo_opt', type : 'combo', choices : ['one', 'two', 'combo'], value : 'combo') option('array_opt', type : 'array', choices : ['one', 'two', 'three'], value : ['one', 'two']) option('free_array_opt', type : 'array') -option('integer_opt', type : 'integer', min : 0, max : 5, value : 3) +option('integer_opt', type : 'integer', min : 0, max : -(-5), value : 3) +option('neg_int_opt', type : 'integer', min : -5, max : 5, value : -3)