diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 7d3a5c4d2..037b1956f 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 ec82ec95d..67ee6583e 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 ae3ad27e2..0c5b98158 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)