wafsamba: Add a CONFIGURE_FILE option.
authorAndreas Schneider <asn@samba.org>
Thu, 6 Sep 2012 10:14:34 +0000 (12:14 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 7 Sep 2012 08:48:57 +0000 (10:48 +0200)
buildtools/wafsamba/configure_file.py [new file with mode: 0644]
buildtools/wafsamba/wafsamba.py

diff --git a/buildtools/wafsamba/configure_file.py b/buildtools/wafsamba/configure_file.py
new file mode 100644 (file)
index 0000000..8e2ba3b
--- /dev/null
@@ -0,0 +1,44 @@
+# handle substitution of variables in .in files
+
+import Build, sys, Logs
+from samba_utils import *
+
+def subst_at_vars(task):
+    '''substiture @VAR@ style variables in a file'''
+
+    env = task.env
+    src = task.inputs[0].srcpath(env)
+    tgt = task.outputs[0].bldpath(env)
+
+    f = open(src, 'r')
+    s = f.read()
+    f.close()
+    # split on the vars
+    a = re.split('(@\w+@)', s)
+    out = []
+    for v in a:
+        if re.match('@\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)
+    f = open(tgt, 'w')
+    s = f.write(contents)
+    f.close()
+    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
index 1fb12410246b8c381413562bbfd8860b9ea600cb..64624d71d5f677c91b31ba0579a51ad164f07b4d 100644 (file)
@@ -31,6 +31,7 @@ import samba_wildcard
 import stale_files
 import symbols
 import pkgconfig
+import configure_file
 
 # some systems have broken threading in python
 if os.environ.get('WAF_NOTHREADS') == '1':
@@ -579,6 +580,12 @@ def SAMBA_GENERATOR(bld, name, rule, source='', target='',
     if not enabled:
         return
 
+    dep_vars = []
+    if isinstance(vars, dict):
+        dep_vars = vars.keys()
+    elif isinstance(vars, list):
+        dep_vars = vars
+
     bld.SET_BUILD_GROUP(group)
     t = bld(
         rule=rule,
@@ -589,7 +596,7 @@ def SAMBA_GENERATOR(bld, name, rule, source='', target='',
         before='cc',
         ext_out='.c',
         samba_type='GENERATOR',
-        dep_vars = [rule] + (vars or []),
+        dep_vars = [rule] + dep_vars,
         name=name)
 
     if always: