aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2016-09-14 22:16:09 +0300
committerGitHub <noreply@github.com>2016-09-14 22:16:09 +0300
commit8fd8c16a879742a840b8f3a431539a261b8552ba (patch)
tree98d12ebbd5143ccba9cfac9e4e9591469bf9f076
parent7d24f96d2dd4d4120cd619008454a0101531744d (diff)
parent09fdc7f815d8b6dede94a14a15a0c05fd1a621c1 (diff)
downloadmeson-8fd8c16a879742a840b8f3a431539a261b8552ba.zip
meson-8fd8c16a879742a840b8f3a431539a261b8552ba.tar.gz
meson-8fd8c16a879742a840b8f3a431539a261b8552ba.tar.bz2
Merge pull request #782 from tp-m/config-data-set-quoted
config data: add .set_quoted() convenience method to set quoted string
-rw-r--r--mesonbuild/interpreter.py8
-rw-r--r--test cases/common/16 configure file/dumpprog.c12
-rw-r--r--test cases/common/16 configure file/meson.build5
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)