aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mensinger <daniel@mensinger-ka.de>2020-04-11 17:12:49 +0200
committerXavier Claessens <xclaesse@gmail.com>2020-04-11 18:58:26 -0400
commit03b86cdbed3cec9f60d3a683bcbde16c0a96ec1b (patch)
tree303ae82b8fb63d26843a8ca1ed3aeee1ec82f6d9
parenta54506fe46da7e5a1a4760a4e4eebda262bf585e (diff)
downloadmeson-03b86cdbed3cec9f60d3a683bcbde16c0a96ec1b.zip
meson-03b86cdbed3cec9f60d3a683bcbde16c0a96ec1b.tar.gz
meson-03b86cdbed3cec9f60d3a683bcbde16c0a96ec1b.tar.bz2
opts: Allow `-` and `not` in meson_options.txt (fixes #6948)
-rw-r--r--mesonbuild/optinterpreter.py10
-rw-r--r--test cases/common/43 options/meson.build4
-rw-r--r--test cases/common/43 options/meson_options.txt5
3 files changed, 17 insertions, 2 deletions
diff --git a/mesonbuild/optinterpreter.py b/mesonbuild/optinterpreter.py
index 2695a26..c13cc5d 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 c6cf9c8..08c5cca 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 4e1c8d8..c5986ba 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)