Merge pull request #2000 from t-chaik/tchaik/wip/get-unquoted

config data: add .get_unquoted() convenience method to get quoted string unquoted
pull/2624/head
Jussi Pakkanen 7 years ago committed by GitHub
commit 49eb33ff55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      docs/markdown/Reference-manual.md
  2. 4
      docs/markdown/snippets/get_unquoted.md
  3. 15
      mesonbuild/interpreter.py
  4. 7
      test cases/common/16 configure file/dumpprog.c
  5. 6
      test cases/common/16 configure file/meson.build

@ -1556,6 +1556,11 @@ page](Configuration.md) It has three methods:
value has not been set returns `default_value` if it is defined
*(added 0.38.0)* and errors out if not
- `get_unquoted(varname, default_value)` returns the value of `varname`
but without surrounding double quotes (`"`). If the value has not been
set returns `default_value` if it is defined and errors out if not.
Available since 0.43.0
- `has(varname)`, returns `true` if the specified variable is set
- `merge_from(other)` takes as argument a different configuration data

@ -0,0 +1,4 @@
# `get_unquoted()` mehod for the `configuration` data object
New convenience method that allow reusing a variable value
defined quoted. Useful in C for config.h strings for example.

@ -177,6 +177,7 @@ class ConfigurationDataHolder(MutableInterpreterObject, ObjectHolder):
'set_quoted': self.set_quoted_method,
'has': self.has_method,
'get': self.get_method,
'get_unquoted': self.get_unquoted_method,
'merge_from': self.merge_from_method,
})
@ -232,6 +233,20 @@ class ConfigurationDataHolder(MutableInterpreterObject, ObjectHolder):
return args[1]
raise InterpreterException('Entry %s not in configuration data.' % name)
def get_unquoted_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:
val = self.held_object.get(name)[0]
elif len(args) > 1:
val = args[1]
else:
raise InterpreterException('Entry %s not in configuration data.' % name)
if val[0] == '"' and val[-1] == '"':
return val[1:-1]
return val
def get(self, name):
return self.held_object.values[name] # (val, desc)

@ -12,7 +12,14 @@
#error Token did not get defined
#endif
#define stringify(s) str(s)
#define str(s) #s
int main(int argc, char **argv) {
#if !(SHOULD_BE_UNQUOTED_STRING == string)
printf("String token (unquoted) defined wrong.\n");
return 1;
#endif
if(strcmp(SHOULD_BE_STRING, "string") != 0) {
printf("String token defined wrong.\n");
return 1;

@ -70,6 +70,12 @@ dump.set('SHOULD_BE_UNDEFINED', false)
dump.set('SHOULD_BE_ONE', 1)
dump.set('SHOULD_BE_ZERO', 0, description : 'Absolutely zero')
dump.set('SHOULD_BE_QUOTED_ONE', '"1"')
dump.set_quoted('INTEGER_AS_STRING', '12')
if dump.get_unquoted('INTEGER_AS_STRING').to_int() == 12
dump.set('SHOULD_BE_UNQUOTED_STRING', dump.get_unquoted('SHOULD_BE_STRING'))
endif
configure_file(output : 'config3.h',
configuration : dump)

Loading…
Cancel
Save