Expose integer options to build option files.

pull/2864/head
Jussi Pakkanen 7 years ago
parent 20c1cb7d02
commit 0204895143
  1. 7
      docs/markdown/Build-options.md
  2. 6
      docs/markdown/snippets/intopt.md
  3. 8
      mesonbuild/coredata.py
  4. 2
      mesonbuild/mintro.py
  5. 11
      mesonbuild/optinterpreter.py
  6. 4
      test cases/common/47 options/meson.build
  7. 1
      test cases/common/47 options/meson_options.txt

@ -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

@ -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)

@ -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):

@ -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:

@ -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,
}

@ -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

@ -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)

Loading…
Cancel
Save