From 7e8f1de063eea43bd9ff390e1573bd7ff475db54 Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Mon, 25 May 2020 10:06:41 +0200 Subject: [PATCH] opts: Allow string concatenation (fixes #7199) --- mesonbuild/optinterpreter.py | 7 +++++++ test cases/common/43 options/meson_options.txt | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/mesonbuild/optinterpreter.py b/mesonbuild/optinterpreter.py index dfbe6d7a7..81206abe6 100644 --- a/mesonbuild/optinterpreter.py +++ b/mesonbuild/optinterpreter.py @@ -177,6 +177,13 @@ class OptionInterpreter: if not isinstance(res, bool): raise OptionException('Token after "not" is not a a boolean') return not res + elif isinstance(arg, mparser.ArithmeticNode): + l = self.reduce_single(arg.left) + r = self.reduce_single(arg.right) + if not (arg.operation == 'add' and isinstance(l, str) and isinstance(r, str)): + raise OptionException('Only string concatenation with the "+" operator is allowed') + FeatureNew.single_use('string concatenation in meson_options.txt', '0.55.0', self.subproject) + return l + r else: raise OptionException('Arguments may only be string, int, bool, or array of those.') diff --git a/test cases/common/43 options/meson_options.txt b/test cases/common/43 options/meson_options.txt index c5986baf8..db649de66 100644 --- a/test cases/common/43 options/meson_options.txt +++ b/test cases/common/43 options/meson_options.txt @@ -1,7 +1,7 @@ -option('testoption', type : 'string', value : 'optval', description : 'An option to do something') +option('testoption', type : 'string', value : 'optval', description : 'An option ' + 'to do something') option('other_one', type : 'boolean', value : not (not (not (not false)))) -option('combo_opt', type : 'combo', choices : ['one', 'two', 'combo'], value : 'combo') +option('combo_opt', type : 'co' + 'mbo', 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('neg_int_opt', type : 'integer', min : -5, max : 5, value : -3) +option('neg' + '_' + 'int' + '_' + 'opt', type : 'integer', min : -5, max : 5, value : -3)