interpreter: Add get_keys function for configuration_data (#7887)

pull/7973/head
Jones 4 years ago committed by GitHub
parent 06de675df2
commit 8351e85bbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      docs/markdown/Reference-manual.md
  2. 4
      docs/markdown/snippets/keys_of_configuration_data.md
  3. 5
      mesonbuild/interpreter.py
  4. 1
      test cases/common/14 configure file/meson.build

@ -2409,6 +2409,12 @@ page](Configuration.md) It has three methods:
- `has(varname)`: returns `true` if the specified variable is set
- `keys()`*(since 0.57.0)*: returns an array of keys of
the configuration data object.
You can iterate over this array with the [`foreach`
statement](Syntax.md#foreach-statements).
- `merge_from(other)` *(since 0.42.0)*: takes as argument a different
configuration data object and copies all entries from that object to
the current.

@ -0,0 +1,4 @@
## Get keys of configuration data object
All keys of the `configuration_data` object can be obtained with the `keys()`
method as an alphabetically sorted array.

@ -308,6 +308,7 @@ class ConfigurationDataHolder(MutableInterpreterObject, ObjectHolder):
'set_quoted': self.set_quoted_method,
'has': self.has_method,
'get': self.get_method,
'keys': self.keys_method,
'get_unquoted': self.get_unquoted_method,
'merge_from': self.merge_from_method,
})
@ -401,6 +402,10 @@ class ConfigurationDataHolder(MutableInterpreterObject, ObjectHolder):
def get(self, name):
return self.held_object.values[name] # (val, desc)
@FeatureNew('configuration_data.keys()', '0.57.0')
def keys_method(self, args, kwargs):
return sorted(self.keys())
def keys(self):
return self.held_object.values.keys()

@ -10,6 +10,7 @@ conf.set('BE_TRUE', true)
assert(conf.get('var') == 'mystring', 'Get function is not working.')
assert(conf.get('var', 'default') == 'mystring', 'Get function is not working.')
assert(conf.get('notthere', 'default') == 'default', 'Default value getting is not working.')
assert(conf.keys() == ['BE_TRUE', 'other', 'second', 'var'], 'Keys function is not working')
cfile = configure_file(input : 'config.h.in',
output : 'config.h',

Loading…
Cancel
Save