diff options
-rw-r--r-- | docs/markdown/Build-options.md | 7 | ||||
-rw-r--r-- | docs/markdown/snippets/intopt.md | 6 | ||||
-rw-r--r-- | mesonbuild/coredata.py | 8 | ||||
-rw-r--r-- | mesonbuild/mintro.py | 2 | ||||
-rw-r--r-- | mesonbuild/optinterpreter.py | 11 | ||||
-rw-r--r-- | test cases/common/47 options/meson.build | 4 | ||||
-rw-r--r-- | test cases/common/47 options/meson_options.txt | 1 |
7 files changed, 38 insertions, 1 deletions
diff --git a/docs/markdown/Build-options.md b/docs/markdown/Build-options.md index cd7f07d..85e8274 100644 --- a/docs/markdown/Build-options.md +++ b/docs/markdown/Build-options.md @@ -16,6 +16,7 @@ Here is a simple option file. option('someoption', type : 'string', value : 'optval', description : 'An option') option('other_one', type : 'boolean', value : false) option('combo_opt', type : 'combo', choices : ['one', 'two', 'three'], value : 'three') +option('integer_opt', type : 'integer', min : 0, max : 5, value : 3) option('free_array_opt', type : 'array', value : ['one', 'two']) option('array_opt', type : 'array', choices : ['one', 'two', 'three'], value : ['one', 'two']) ``` @@ -39,6 +40,12 @@ A combo allows any one of the values in the `choices` parameter to be selected. If no default value is set then the first value will be the default. +## Integers + +An integer option contains a single integer with optional upper and +lower values that are specified with the `min` and `max` keyword +arguments. Available since Meson version 0.45.0. + ### Arrays Arrays represent an array of strings. By default the array can contain diff --git a/docs/markdown/snippets/intopt.md b/docs/markdown/snippets/intopt.md new file mode 100644 index 0000000..daf660b --- /dev/null +++ b/docs/markdown/snippets/intopt.md @@ -0,0 +1,6 @@ +## Integer options + +There is a new integer option type with optional minimum and maximum +values. It can be specified like this in the `meson_options.txt` file: + + option('integer_option', type : 'integer', min : 0, max : 5, value : 3) diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 0fdac8b..c96a09e 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -80,10 +80,16 @@ class UserBooleanOption(UserOption): class UserIntegerOption(UserOption): def __init__(self, name, description, min_value, max_value, value): - super().__init__(name, description, [True, False]) + super().__init__(name, description, None) self.min_value = min_value self.max_value = max_value self.set_value(value) + c = [] + if min_value is not None: + c.append('>=' + str(min_value)) + if max_value is not None: + c.append('<=' + str(max_value)) + self.choices = ', '.join(c) def set_value(self, newvalue): if isinstance(newvalue, str): diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index aaaf8fc..8cf66af 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -139,6 +139,8 @@ def add_keys(optlist, options): elif isinstance(opt, coredata.UserComboOption): optdict['choices'] = opt.choices typestr = 'combo' + elif isinstance(opt, coredata.UserIntegerOption): + typestr = 'integer' elif isinstance(opt, coredata.UserArrayOption): typestr = 'array' else: diff --git a/mesonbuild/optinterpreter.py b/mesonbuild/optinterpreter.py index df945ab..7eeaa48 100644 --- a/mesonbuild/optinterpreter.py +++ b/mesonbuild/optinterpreter.py @@ -85,6 +85,16 @@ def ComboParser(name, description, kwargs): raise OptionException('Combo choice elements must be strings.') return coredata.UserComboOption(name, description, choices, kwargs.get('value', choices[0])) +@permitted_kwargs({'value', 'min', 'max'}) +def IntegerParser(name, description, kwargs): + if 'value' not in kwargs: + raise OptionException('Integer option must contain value argument.') + return coredata.UserIntegerOption(name, + description, + kwargs.get('min', None), + kwargs.get('max', None), + kwargs['value']) + @permitted_kwargs({'value', 'choices'}) def string_array_parser(name, description, kwargs): if 'choices' in kwargs: @@ -105,6 +115,7 @@ def string_array_parser(name, description, kwargs): option_types = {'string': StringParser, 'boolean': BooleanParser, 'combo': ComboParser, + 'integer': IntegerParser, 'array': string_array_parser, } diff --git a/test cases/common/47 options/meson.build b/test cases/common/47 options/meson.build index 863703c..f177aa4 100644 --- a/test cases/common/47 options/meson.build +++ b/test cases/common/47 options/meson.build @@ -25,3 +25,7 @@ endif if get_option('includedir') != 'include' error('Incorrect value in builtin option.') endif + +if get_option('integer_opt') != 3 + error('Incorrect value in integer option.') +endif diff --git a/test cases/common/47 options/meson_options.txt b/test cases/common/47 options/meson_options.txt index 6bd0346..4e1c8d8 100644 --- a/test cases/common/47 options/meson_options.txt +++ b/test cases/common/47 options/meson_options.txt @@ -3,3 +3,4 @@ option('other_one', type : 'boolean', value : 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) |