2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-25 03:09:30 +01:00

extend bld.subst for the copy case

This commit is contained in:
Thomas Nagy 2012-03-29 00:04:34 +02:00
parent a496ba124e
commit 640ad5b61d
2 changed files with 36 additions and 13 deletions

View File

@ -27,6 +27,9 @@ def build(bld):
dct = {'BINDIR': '/opt'} dct = {'BINDIR': '/opt'}
tg.__dict__.update(dct) tg.__dict__.update(dct)
# if you want a file copy, pass "is_copy=True"
bld(features='subst', source='wscript', target='wscript', is_copy=True)
# this one is just a reminder that simple files can be created (and a test too) # this one is just a reminder that simple files can be created (and a test too)
#bld(rule='echo "การไฟ่" > ${TGT}', target='foo.txt') #bld(rule='echo "การไฟ่" > ${TGT}', target='foo.txt')

View File

@ -659,6 +659,12 @@ class subst_pc(Task.Task):
def run(self): def run(self):
"Substitutes variables in a .in file" "Substitutes variables in a .in file"
if getattr(self.generator, 'is_copy', None):
self.outputs[0].write(self.inputs[0].read('rb'), 'wb')
if getattr(self.generator, 'chmod', None):
os.chmod(self.outputs[0].abspath(), self.generator.chmod)
return
code = self.inputs[0].read() code = self.inputs[0].read()
# replace all % by %% to prevent errors by % signs # replace all % by %% to prevent errors by % signs
@ -746,24 +752,38 @@ def process_subst(self):
This method overrides the processing by :py:meth:`waflib.TaskGen.process_source`. This method overrides the processing by :py:meth:`waflib.TaskGen.process_source`.
""" """
src = self.to_nodes(getattr(self, 'source', []))
tgt = getattr(self, 'target', [])
if isinstance(tgt, self.path.__class__):
tgt = [tgt]
else:
tgt = [isinstance(x, self.path.__class__) and x or self.path.find_or_declare(x) for x in Utils.to_list(tgt)]
src = Utils.to_list(getattr(self, 'source', []))
tgt = Utils.to_list(getattr(self, 'target', []))
if len(src) != len(tgt): if len(src) != len(tgt):
raise Errors.WafError('invalid source or target for %r' % self) raise Errors.WafError('invalid number of source/target for %r' % self)
for x, y in zip(src, tgt): for x, y in zip(src, tgt):
if not (x and y): if not x or not y:
raise Errors.WafError('invalid source or target for %r' % self) raise Errors.WafError('null source or target for %r' % self)
tsk = self.create_task('subst', x, y) a, b = None, None
for a in ('after', 'before', 'ext_in', 'ext_out'):
val = getattr(self, a, None) if isinstance(x, str) and isinstance(y, str) and x == y:
a = self.path.find_node(x)
b = self.path.get_bld().make_node(y)
else:
if isinstance(x, str):
a = self.path.find_resource(x)
elif isinstance(x, Node.Node):
a = x
if isinstance(y, str):
b = self.path.find_or_declare(y)
elif isinstance(y, Node.Node):
b = y
if not a:
raise Errors.WafError('cound not find %r for %r' % (x, self))
tsk = self.create_task('subst', a, b)
for k in ('after', 'before', 'ext_in', 'ext_out'):
val = getattr(self, k, None)
if val: if val:
setattr(tsk, a, val) setattr(tsk, k, val)
inst_to = getattr(self, 'install_path', None) inst_to = getattr(self, 'install_path', None)
if inst_to: if inst_to: