aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJones <info@brainelectronics.de>2020-11-12 19:43:17 +0100
committerGitHub <noreply@github.com>2020-11-12 20:43:17 +0200
commit8351e85bbd531411691ba54bbb0bac6d96ae5bfd (patch)
tree157380f0782a785e0c5a86588c470f20889068ed
parent06de675df2172b6c6f9908686540ebf57b20db4a (diff)
downloadmeson-8351e85bbd531411691ba54bbb0bac6d96ae5bfd.zip
meson-8351e85bbd531411691ba54bbb0bac6d96ae5bfd.tar.gz
meson-8351e85bbd531411691ba54bbb0bac6d96ae5bfd.tar.bz2
interpreter: Add get_keys function for configuration_data (#7887)
-rw-r--r--docs/markdown/Reference-manual.md6
-rw-r--r--docs/markdown/snippets/keys_of_configuration_data.md4
-rw-r--r--mesonbuild/interpreter.py5
-rw-r--r--test cases/common/14 configure file/meson.build1
4 files changed, 16 insertions, 0 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md
index 3af78ef..aeaeccb 100644
--- a/docs/markdown/Reference-manual.md
+++ b/docs/markdown/Reference-manual.md
@@ -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.
diff --git a/docs/markdown/snippets/keys_of_configuration_data.md b/docs/markdown/snippets/keys_of_configuration_data.md
new file mode 100644
index 0000000..c0cbfc2
--- /dev/null
+++ b/docs/markdown/snippets/keys_of_configuration_data.md
@@ -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.
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 28ac74f..104fcce 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -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()
diff --git a/test cases/common/14 configure file/meson.build b/test cases/common/14 configure file/meson.build
index f40dc52..f7e0eeb 100644
--- a/test cases/common/14 configure file/meson.build
+++ b/test cases/common/14 configure file/meson.build
@@ -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',