aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2017-11-13 22:54:39 +0200
committerGitHub <noreply@github.com>2017-11-13 22:54:39 +0200
commit49eb33ff5563e68bc89b399935923b892a99b54f (patch)
tree2e0abdfefe5f98a2ef596a6996ed94cce01e5a8e
parent897fd0bd169a5333b8b15af6b6e102ab53fe5cdf (diff)
parent26e731c7caf575799e88fe393ba8c2a3a7c42073 (diff)
downloadmeson-49eb33ff5563e68bc89b399935923b892a99b54f.zip
meson-49eb33ff5563e68bc89b399935923b892a99b54f.tar.gz
meson-49eb33ff5563e68bc89b399935923b892a99b54f.tar.bz2
Merge pull request #2000 from t-chaik/tchaik/wip/get-unquoted
config data: add .get_unquoted() convenience method to get quoted string unquoted
-rw-r--r--docs/markdown/Reference-manual.md5
-rwxr-xr-xdocs/markdown/snippets/get_unquoted.md4
-rw-r--r--mesonbuild/interpreter.py15
-rw-r--r--test cases/common/16 configure file/dumpprog.c7
-rw-r--r--test cases/common/16 configure file/meson.build6
5 files changed, 37 insertions, 0 deletions
diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md
index eee4405..92c8a1f 100644
--- a/docs/markdown/Reference-manual.md
+++ b/docs/markdown/Reference-manual.md
@@ -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
diff --git a/docs/markdown/snippets/get_unquoted.md b/docs/markdown/snippets/get_unquoted.md
new file mode 100755
index 0000000..5f8969d
--- /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.
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index c7a0fb7..6300f7f 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -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)
diff --git a/test cases/common/16 configure file/dumpprog.c b/test cases/common/16 configure file/dumpprog.c
index 685240c..39a215e 100644
--- a/test cases/common/16 configure file/dumpprog.c
+++ b/test cases/common/16 configure file/dumpprog.c
@@ -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;
diff --git a/test cases/common/16 configure file/meson.build b/test cases/common/16 configure file/meson.build
index 9dc5fb5..1e5a819 100644
--- a/test cases/common/16 configure file/meson.build
+++ b/test cases/common/16 configure file/meson.build
@@ -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)