1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-26 10:04:02 +03:00
samba-mirror/buildtools/wafsamba/configure_file.py
Thomas Nagy 2666d06f29 build:wafsamba: removed most import * statements
The 'import *' statements make it more difficult to reason about
the modules and tends to conceal bugs. These changes enable running
pyflakes against most of the build scripts.

Signed-off-by: Thomas Nagy <tnagy@waf.io>
Reviewed-by: Andrew Bartlet <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>

Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Wed Oct 28 12:52:17 CET 2015 on sn-devel-104
2015-10-28 12:52:17 +01:00

40 lines
1.2 KiB
Python

# handle substitution of variables in .in files
import re, os
import Build, sys, 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('(@\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)
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