Can get values in ConfigurationData objects.

pull/1292/head
Jussi Pakkanen 8 years ago
parent 8f3616e72e
commit 00f62d0755
  1. 7
      mesonbuild/build.py
  2. 13
      mesonbuild/interpreter.py
  3. 4
      test cases/common/16 configure file/meson.build

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

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

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

Loading…
Cancel
Save