aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/mesonlib.py11
-rw-r--r--test cases/common/16 configure file/config5.h.in1
-rw-r--r--test cases/common/16 configure file/meson.build11
-rw-r--r--test cases/common/16 configure file/prog5.c6
4 files changed, 23 insertions, 6 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index 83bfdbe..e9cf6cf 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -403,9 +403,9 @@ def get_library_dirs():
def do_replacement(regex, line, confdata):
- match = re.search(regex, line)
missing_variables = set()
- while match:
+
+ def variable_replace(match):
varname = match.group(1)
if varname in confdata:
(var, desc) = confdata.get(varname)
@@ -418,9 +418,8 @@ def do_replacement(regex, line, confdata):
else:
missing_variables.add(varname)
var = ''
- line = line.replace('@' + varname + '@', var)
- match = re.search(regex, line)
- return line, missing_variables
+ return var
+ return re.sub(regex, variable_replace, line), missing_variables
def do_mesondefine(line, confdata):
arr = line.split()
@@ -452,7 +451,7 @@ def do_conf_file(src, dst, confdata):
raise MesonException('Could not read input file %s: %s' % (src, str(e)))
# Only allow (a-z, A-Z, 0-9, _, -) as valid characters for a define
# Also allow escaping '@' with '\@'
- regex = re.compile(r'[^\\]?@([-a-zA-Z0-9_]+)@')
+ regex = re.compile(r'(?<!\\)@([-a-zA-Z0-9_]+)@')
result = []
missing_variables = set()
for line in data:
diff --git a/test cases/common/16 configure file/config5.h.in b/test cases/common/16 configure file/config5.h.in
new file mode 100644
index 0000000..323bec6
--- /dev/null
+++ b/test cases/common/16 configure file/config5.h.in
@@ -0,0 +1 @@
+#define MESSAGE "@var@"
diff --git a/test cases/common/16 configure file/meson.build b/test cases/common/16 configure file/meson.build
index 1e5a819..4264d07 100644
--- a/test cases/common/16 configure file/meson.build
+++ b/test cases/common/16 configure file/meson.build
@@ -109,3 +109,14 @@ configs = [
foreach c : configs
test('@0@'.format(c), file_contains_py, args: [ c, test_string ])
endforeach
+
+# Test variable is substituted only once
+conf5 = configuration_data()
+conf5.set('var', '@var2@')
+conf5.set('var2', 'error')
+configure_file(
+ input : 'config5.h.in',
+ output : '@BASENAME@',
+ configuration : conf5
+)
+test('test5', executable('prog5', 'prog5.c'))
diff --git a/test cases/common/16 configure file/prog5.c b/test cases/common/16 configure file/prog5.c
new file mode 100644
index 0000000..42c08f9
--- /dev/null
+++ b/test cases/common/16 configure file/prog5.c
@@ -0,0 +1,6 @@
+#include <string.h>
+#include <config5.h>
+
+int main(int argc, char **argv) {
+ return strcmp(MESSAGE, "@var2@");
+}