From 640ad5b61d51b7b2158505af53b794672f0fc962 Mon Sep 17 00:00:00 2001 From: Thomas Nagy Date: Thu, 29 Mar 2012 00:04:34 +0200 Subject: [PATCH] extend bld.subst for the copy case --- demos/subst/wscript | 3 +++ waflib/TaskGen.py | 46 ++++++++++++++++++++++++++++++++------------- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/demos/subst/wscript b/demos/subst/wscript index 739a22a1..0922ca11 100644 --- a/demos/subst/wscript +++ b/demos/subst/wscript @@ -27,6 +27,9 @@ def build(bld): dct = {'BINDIR': '/opt'} 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) #bld(rule='echo "การไฟ่" > ${TGT}', target='foo.txt') diff --git a/waflib/TaskGen.py b/waflib/TaskGen.py index 04dd201e..378ec2db 100644 --- a/waflib/TaskGen.py +++ b/waflib/TaskGen.py @@ -659,6 +659,12 @@ class subst_pc(Task.Task): def run(self): "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() # 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`. """ - 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): - 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): - if not (x and y): - raise Errors.WafError('invalid source or target for %r' % self) - tsk = self.create_task('subst', x, y) - for a in ('after', 'before', 'ext_in', 'ext_out'): - val = getattr(self, a, None) + if not x or not y: + raise Errors.WafError('null source or target for %r' % self) + a, b = None, 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: - setattr(tsk, a, val) + setattr(tsk, k, val) inst_to = getattr(self, 'install_path', None) if inst_to: