summaryrefslogtreecommitdiffstats
path: root/buildtools/wafsamba/configure_file.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 17:44:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 17:44:55 +0000
commitbfe2e03d5ecddce1b9666a58a57e66078a737ea1 (patch)
tree4a4130aca118d9aaaf1494e0e6a5015a0aa409b5 /buildtools/wafsamba/configure_file.py
parentInitial commit. (diff)
downloadtevent-bfe2e03d5ecddce1b9666a58a57e66078a737ea1.tar.xz
tevent-bfe2e03d5ecddce1b9666a58a57e66078a737ea1.zip
Adding upstream version 0.14.1.upstream/0.14.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'buildtools/wafsamba/configure_file.py')
-rw-r--r--buildtools/wafsamba/configure_file.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/buildtools/wafsamba/configure_file.py b/buildtools/wafsamba/configure_file.py
new file mode 100644
index 0000000..98a58a4
--- /dev/null
+++ b/buildtools/wafsamba/configure_file.py
@@ -0,0 +1,41 @@
+# handle substitution of variables in .in files
+
+import sys
+import re
+import os
+from waflib import Build, Logs
+from samba_utils import SUBST_VARS_RECURSIVE
+
+def subst_at_vars(task):
+ '''substiture @VAR@ style variables in a file'''
+
+ env = task.env
+ s = task.inputs[0].read()
+
+ # split on the vars
+ a = re.split(r'(@\w+@)', s)
+ out = []
+ for v in a:
+ if re.match(r'@\w+@', v):
+ vname = v[1:-1]
+ if not vname in task.env and vname.upper() in task.env:
+ vname = vname.upper()
+ if not vname in task.env:
+ Logs.error("Unknown substitution %s in %s" % (v, task.name))
+ sys.exit(1)
+ v = SUBST_VARS_RECURSIVE(task.env[vname], task.env)
+ out.append(v)
+ contents = ''.join(out)
+ task.outputs[0].write(contents)
+ return 0
+
+def CONFIGURE_FILE(bld, in_file, **kwargs):
+ '''configure file'''
+
+ base=os.path.basename(in_file)
+ t = bld.SAMBA_GENERATOR('INFILE_%s' % base,
+ rule = subst_at_vars,
+ source = in_file + '.in',
+ target = in_file,
+ vars = kwargs)
+Build.BuildContext.CONFIGURE_FILE = CONFIGURE_FILE