Merge pull request #782 from tp-m/config-data-set-quoted

config data: add .set_quoted() convenience method to set quoted string
pull/783/head
Jussi Pakkanen 8 years ago committed by GitHub
commit 8fd8c16a87
  1. 8
      mesonbuild/interpreter.py
  2. 12
      test cases/common/16 configure file/dumpprog.c
  3. 5
      test cases/common/16 configure file/meson.build

@ -187,6 +187,7 @@ class ConfigurationDataHolder(InterpreterObject):
self.held_object = build.ConfigurationData() self.held_object = build.ConfigurationData()
self.methods.update({'set': self.set_method, self.methods.update({'set': self.set_method,
'set10': self.set10_method, 'set10': self.set10_method,
'set_quoted': self.set_quoted_method,
'has' : self.has_method, 'has' : self.has_method,
}) })
@ -211,6 +212,13 @@ class ConfigurationDataHolder(InterpreterObject):
(name, val) = self.validate_args(args) (name, val) = self.validate_args(args)
self.held_object.values[name] = val self.held_object.values[name] = val
def set_quoted_method(self, args, kwargs):
(name, val) = self.validate_args(args)
if not isinstance(val, str):
raise InterpreterException("Second argument to set_quoted must be a string.")
escaped_val = '\\"'.join(val.split('"'))
self.held_object.values[name] = '"' + escaped_val + '"'
def set10_method(self, args, kwargs): def set10_method(self, args, kwargs):
(name, val) = self.validate_args(args) (name, val) = self.validate_args(args)
if val: if val:

@ -17,6 +17,18 @@ int main(int argc, char **argv) {
printf("String token defined wrong.\n"); printf("String token defined wrong.\n");
return 1; return 1;
} }
if(strcmp(SHOULD_BE_STRING2, "A \"B\" C") != 0) {
printf("String token 2 defined wrong.\n");
return 1;
}
if(strcmp(SHOULD_BE_STRING3, "A \"\" C") != 0) {
printf("String token 3 defined wrong.\n");
return 1;
}
if(strcmp(SHOULD_BE_STRING4, "A \" C") != 0) {
printf("String token 4 defined wrong.\n");
return 1;
}
if(SHOULD_BE_ONE != 1) { if(SHOULD_BE_ONE != 1) {
printf("One defined incorrectly.\n"); printf("One defined incorrectly.\n");
return 1; return 1;

@ -34,7 +34,10 @@ test('inctest2', executable('prog2', 'prog2.c'))
# Generate a conf file without an input file. # Generate a conf file without an input file.
dump = configuration_data() dump = configuration_data()
dump.set('SHOULD_BE_STRING', '"string"') dump.set_quoted('SHOULD_BE_STRING', 'string')
dump.set_quoted('SHOULD_BE_STRING2', 'A "B" C')
dump.set_quoted('SHOULD_BE_STRING3', 'A "" C')
dump.set_quoted('SHOULD_BE_STRING4', 'A " C')
dump.set('SHOULD_BE_RETURN', 'return') dump.set('SHOULD_BE_RETURN', 'return')
dump.set('SHOULD_BE_DEFINED', true) dump.set('SHOULD_BE_DEFINED', true)
dump.set('SHOULD_BE_UNDEFINED', false) dump.set('SHOULD_BE_UNDEFINED', false)

Loading…
Cancel
Save