aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/build.py7
-rw-r--r--mesonbuild/interpreter.py13
-rw-r--r--test cases/common/16 configure file/meson.build4
3 files changed, 21 insertions, 3 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 7d3a5c4..037b195 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -1,4 +1,4 @@
-# Copyright 2012-2014 The Meson development team
+# Copyright 2012-2017 The Meson development team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -1487,8 +1487,11 @@ class ConfigurationData():
def __repr__(self):
return repr(self.values)
+ def __contains__(self, value):
+ return value in self.values
+
def get(self, name):
- return self.values[name] # (val, desc)
+ return self.values[name] # (val, desc)
def keys(self):
return self.values.keys()
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index ec82ec9..67ee658 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1,4 +1,4 @@
-# Copyright 2012-2016 The Meson development team
+# Copyright 2012-2017 The Meson development team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -163,6 +163,7 @@ class ConfigurationDataHolder(MutableInterpreterObject):
'set10': self.set10_method,
'set_quoted': self.set_quoted_method,
'has': self.has_method,
+ 'get': self.get_method,
})
def is_used(self):
@@ -207,6 +208,16 @@ class ConfigurationDataHolder(MutableInterpreterObject):
def has_method(self, args, kwargs):
return args[0] in self.held_object.values
+ def get_method(self, args, kwargs):
+ if len(args) < 1 or len(args) > 2:
+ raise InterpreterException('Get method takes one or two arguments.')
+ name = args[0]
+ if name in self.held_object:
+ return self.held_object.get(name)[0]
+ if len(args) > 1:
+ return args[1]
+ raise InterpreterException('Entry %s not in configuration data.' % name)
+
def get(self, name):
return self.held_object.values[name] # (val, desc)
diff --git a/test cases/common/16 configure file/meson.build b/test cases/common/16 configure file/meson.build
index ae3ad27..0c5b981 100644
--- a/test cases/common/16 configure file/meson.build
+++ b/test cases/common/16 configure file/meson.build
@@ -7,6 +7,10 @@ conf.set('other', 'string 2')
conf.set('second', ' bonus')
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.')
+
cfile = configure_file(input : 'config.h.in',
output : 'config.h',
configuration : conf)