From fa1fee568621fa226532eebd79c67db5185bea02 Mon Sep 17 00:00:00 2001 From: Martin Blanchard Date: Mon, 26 Jun 2017 17:21:58 +0200 Subject: [PATCH 1/6] get-unquoted: Implement a get_unquoted() method for ConfigurationData --- mesonbuild/interpreter.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 2bcf198a2..11d513129 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -168,6 +168,7 @@ class ConfigurationDataHolder(MutableInterpreterObject): '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, }) @@ -223,6 +224,20 @@ class ConfigurationDataHolder(MutableInterpreterObject): 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:len(val)-1] + return val + def get(self, name): return self.held_object.values[name] # (val, desc) From 6b517475f517cb5d74c0ebff1edaf39c1e48b5c7 Mon Sep 17 00:00:00 2001 From: Martin Blanchard Date: Mon, 26 Jun 2017 18:24:46 +0200 Subject: [PATCH 2/6] get-unquoted: Add test case for new get_unquoted() method --- .../common/16 configure file/dumpprog.c | 19 +++++++++++++++++++ .../common/16 configure file/meson.build | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/test cases/common/16 configure file/dumpprog.c b/test cases/common/16 configure file/dumpprog.c index 685240ced..4c21e874d 100644 --- a/test cases/common/16 configure file/dumpprog.c +++ b/test cases/common/16 configure file/dumpprog.c @@ -12,6 +12,9 @@ #error Token did not get defined #endif +#define stringify(s) str(s) +#define str(s) #s + int main(int argc, char **argv) { if(strcmp(SHOULD_BE_STRING, "string") != 0) { printf("String token defined wrong.\n"); @@ -29,6 +32,22 @@ int main(int argc, char **argv) { printf("String token 4 defined wrong.\n"); return 1; } +#if !(SHOULD_BE_UNQUOTED_STRING == string) + printf("String token (unquoted) defined wrong.\n"); + return 1; +#endif + if(strcmp(stringify(SHOULD_BE_UNQUOTED_STRING2), "A \"B\" C") != 0) { + printf("String token 2 (unquoted) defined wrong.\n"); + return 1; + } + if(strcmp(stringify(SHOULD_BE_UNQUOTED_STRING3), "A \"\" C") != 0) { + printf("String token 3 (unquoted) defined wrong.\n"); + return 1; + } + if(strcmp(stringify(SHOULD_BE_UNQUOTED_STRING4), "A \" C") != 0) { + printf("String token 4 (unquoted) 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 9dc5fb55e..0861bcc1d 100644 --- a/test cases/common/16 configure file/meson.build +++ b/test cases/common/16 configure file/meson.build @@ -64,6 +64,10 @@ dump.set_quoted('SHOULD_BE_STRING', 'string', description : 'A 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_UNQUOTED_STRING', dump.get_unquoted('SHOULD_BE_STRING')) +dump.set('SHOULD_BE_UNQUOTED_STRING2', dump.get_unquoted('SHOULD_BE_STRING2')) +dump.set('SHOULD_BE_UNQUOTED_STRING3', dump.get_unquoted('SHOULD_BE_STRING3')) +dump.set('SHOULD_BE_UNQUOTED_STRING4', dump.get_unquoted('SHOULD_BE_STRING4')) dump.set('SHOULD_BE_RETURN', 'return') dump.set('SHOULD_BE_DEFINED', true) dump.set('SHOULD_BE_UNDEFINED', false) From 71deffab18c0d3b0b54f604f68c743a33c655f9d Mon Sep 17 00:00:00 2001 From: Martin Blanchard Date: Sun, 2 Jul 2017 12:53:08 +0200 Subject: [PATCH 3/6] get-unquoted: Fix indentation and remove useless arithmetic --- mesonbuild/interpreter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 11d513129..e0aebc1b2 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -235,7 +235,7 @@ class ConfigurationDataHolder(MutableInterpreterObject): else: raise InterpreterException('Entry %s not in configuration data.' % name) if val[0] == '"' and val[-1] == '"': - return val[1:len(val)-1] + return val[1:-1] return val def get(self, name): From 105507a173ba4429cef3266cefb5e812202db5f8 Mon Sep 17 00:00:00 2001 From: Martin Blanchard Date: Sun, 2 Jul 2017 15:06:39 +0200 Subject: [PATCH 4/6] get-unquoted: Rework test case for msvc (make it more realistic) --- .../common/16 configure file/dumpprog.c | 20 ++++--------------- .../common/16 configure file/meson.build | 10 ++++++---- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/test cases/common/16 configure file/dumpprog.c b/test cases/common/16 configure file/dumpprog.c index 4c21e874d..39a215ee8 100644 --- a/test cases/common/16 configure file/dumpprog.c +++ b/test cases/common/16 configure file/dumpprog.c @@ -16,6 +16,10 @@ #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; @@ -32,22 +36,6 @@ int main(int argc, char **argv) { printf("String token 4 defined wrong.\n"); return 1; } -#if !(SHOULD_BE_UNQUOTED_STRING == string) - printf("String token (unquoted) defined wrong.\n"); - return 1; -#endif - if(strcmp(stringify(SHOULD_BE_UNQUOTED_STRING2), "A \"B\" C") != 0) { - printf("String token 2 (unquoted) defined wrong.\n"); - return 1; - } - if(strcmp(stringify(SHOULD_BE_UNQUOTED_STRING3), "A \"\" C") != 0) { - printf("String token 3 (unquoted) defined wrong.\n"); - return 1; - } - if(strcmp(stringify(SHOULD_BE_UNQUOTED_STRING4), "A \" C") != 0) { - printf("String token 4 (unquoted) 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 0861bcc1d..1e5a8196e 100644 --- a/test cases/common/16 configure file/meson.build +++ b/test cases/common/16 configure file/meson.build @@ -64,16 +64,18 @@ dump.set_quoted('SHOULD_BE_STRING', 'string', description : 'A 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_UNQUOTED_STRING', dump.get_unquoted('SHOULD_BE_STRING')) -dump.set('SHOULD_BE_UNQUOTED_STRING2', dump.get_unquoted('SHOULD_BE_STRING2')) -dump.set('SHOULD_BE_UNQUOTED_STRING3', dump.get_unquoted('SHOULD_BE_STRING3')) -dump.set('SHOULD_BE_UNQUOTED_STRING4', dump.get_unquoted('SHOULD_BE_STRING4')) dump.set('SHOULD_BE_RETURN', 'return') dump.set('SHOULD_BE_DEFINED', true) 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) From 777cd24063cc9991defef275b5c13637a9072049 Mon Sep 17 00:00:00 2001 From: Martin Blanchard Date: Fri, 15 Sep 2017 22:43:01 +0200 Subject: [PATCH 5/6] get-unquoted: Mention get_unquoted() in reference manual --- docs/markdown/Reference-manual.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index 1bed44d01..9d9111ec3 100644 --- a/docs/markdown/Reference-manual.md +++ b/docs/markdown/Reference-manual.md @@ -1522,6 +1522,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 From 26e731c7caf575799e88fe393ba8c2a3a7c42073 Mon Sep 17 00:00:00 2001 From: Martin Blanchard Date: Fri, 15 Sep 2017 23:24:15 +0200 Subject: [PATCH 6/6] get-unquoted: Queue a release note entry mentioning the new method --- docs/markdown/snippets/get_unquoted.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 docs/markdown/snippets/get_unquoted.md diff --git a/docs/markdown/snippets/get_unquoted.md b/docs/markdown/snippets/get_unquoted.md new file mode 100755 index 000000000..5f8969d22 --- /dev/null +++ b/docs/markdown/snippets/get_unquoted.md @@ -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.