From 404eed3ee9ea1054e420d98985fbeb5d508f6354 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Mon, 25 Nov 2002 17:22:28 +0000 Subject: [PATCH] Make env.SideEffect work for Dir nodes. (Anthony Roach) git-svn-id: http://scons.tigris.org/svn/scons/trunk@505 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/engine/SCons/Environment.py | 5 ++++- src/engine/SCons/Node/FS.py | 4 ++-- test/SideEffect.py | 34 +++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/engine/SCons/Environment.py b/src/engine/SCons/Environment.py index c0b32551..ec8f1ebf 100644 --- a/src/engine/SCons/Environment.py +++ b/src/engine/SCons/Environment.py @@ -374,7 +374,10 @@ class Environment: targets = SCons.Node.arg2nodes(target, self.fs.File) for side_effect in side_effects: - if side_effect.builder is not None: + # A builder of 1 means the node is supposed to appear + # buildable without actually having a builder, so we allow + # it to be a side effect as well. + if side_effect.builder is not None and side_effect.builder != 1: raise UserError, "Multiple ways to build the same target were specified for: %s" % str(side_effect) side_effect.add_source(targets) side_effect.side_effect = 1 diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index d66b7771..59b8e636 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -644,7 +644,7 @@ class Dir(Entry): else: return self.entries['..'].root() - def all_children(self, scanner): + def all_children(self, scan): #XXX --random: randomize "dependencies?" keys = filter(lambda k: k != '.' and k != '..', self.entries.keys()) kids = map(lambda x, s=self: s.entries[x], keys) @@ -655,7 +655,7 @@ class Dir(Entry): return 1 return 0 kids.sort(c) - return kids + return kids + SCons.Node.Node.all_children(self, 0) def build(self): """A null "builder" for directories.""" diff --git a/test/SideEffect.py b/test/SideEffect.py index 6337f681..3f3b75d8 100644 --- a/test/SideEffect.py +++ b/test/SideEffect.py @@ -118,5 +118,39 @@ foo.in -> foo.out """ assert test.read('log.txt') == expect +test.write('SConstruct', +""" +import os.path +import os + +def copy(source, target): + print 'copy() < %s > %s' % (source, target) + open(target, "wb").write(open(source, "rb").read()) + +def build(env, source, target): + copy(str(source[0]), str(target[0])) + if target[0].side_effects: + try: os.mkdir('log') + except: pass + copy(str(target[0]), os.path.join('log', str(target[0]))) + +Build = Builder(action=build) +env = Environment(BUILDERS={'Build':Build}) +env.Build('foo.out', 'foo.in') +env.Build('bar.out', 'bar.in') +env.Build('blat.out', 'blat.in') +env.SideEffect(Dir('log'), ['foo.out', 'bar.out', 'blat.out']) +""") + +test.run(arguments='foo.out') + +test.fail_test(not os.path.exists(test.workpath('foo.out'))) +test.fail_test(not os.path.exists(test.workpath('log/foo.out'))) +test.fail_test(os.path.exists(test.workpath('log/bar.out'))) +test.fail_test(os.path.exists(test.workpath('log/blat.out'))) + +test.run(arguments='log') +test.fail_test(not os.path.exists(test.workpath('log/bar.out'))) +test.fail_test(not os.path.exists(test.workpath('log/blat.out'))) test.pass_test() -- 2.26.2