diff options
-rw-r--r-- | mesonbuild/interpreter.py | 8 | ||||
-rw-r--r-- | test cases/common/16 configure file/dumpprog.c | 12 | ||||
-rw-r--r-- | test cases/common/16 configure file/meson.build | 5 |
3 files changed, 24 insertions, 1 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 9584950..316f8c4 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -187,6 +187,7 @@ class ConfigurationDataHolder(InterpreterObject): self.held_object = build.ConfigurationData() self.methods.update({'set': self.set_method, 'set10': self.set10_method, + 'set_quoted': self.set_quoted_method, 'has' : self.has_method, }) @@ -211,6 +212,13 @@ class ConfigurationDataHolder(InterpreterObject): (name, val) = self.validate_args(args) 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): (name, val) = self.validate_args(args) if val: diff --git a/test cases/common/16 configure file/dumpprog.c b/test cases/common/16 configure file/dumpprog.c index e0c9868..685240c 100644 --- a/test cases/common/16 configure file/dumpprog.c +++ b/test cases/common/16 configure file/dumpprog.c @@ -17,6 +17,18 @@ int main(int argc, char **argv) { printf("String token defined wrong.\n"); 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) { printf("One defined incorrectly.\n"); return 1; diff --git a/test cases/common/16 configure file/meson.build b/test cases/common/16 configure file/meson.build index e1bdff3..c00af40 100644 --- a/test cases/common/16 configure file/meson.build +++ b/test cases/common/16 configure file/meson.build @@ -34,7 +34,10 @@ test('inctest2', executable('prog2', 'prog2.c')) # Generate a conf file without an input file. 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_DEFINED', true) dump.set('SHOULD_BE_UNDEFINED', false) |