From 2b8136b95269602bffeb8f1fabf4d895b1ee2568 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Mon, 28 Jan 2002 12:45:30 +0000 Subject: [PATCH] Fix so Nodes don't get removed by ListBuilder after they're built. git-svn-id: http://scons.tigris.org/svn/scons/trunk@227 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/engine/SCons/Node/NodeTests.py | 51 ++++++++++++++++++++++++++++++ src/engine/SCons/Node/__init__.py | 24 ++++++++------ 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/src/engine/SCons/Node/NodeTests.py b/src/engine/SCons/Node/NodeTests.py index bcaf1a0a..9dc2105a 100644 --- a/src/engine/SCons/Node/NodeTests.py +++ b/src/engine/SCons/Node/NodeTests.py @@ -52,6 +52,17 @@ class NoneBuilder(Builder): apply(Builder.execute, (self,), kw) return None +class ListBuilder(Builder): + def __init__(self, *nodes): + self.nodes = nodes + def execute(self, **kw): + if hasattr(self, 'status'): + return self.status + for n in self.nodes: + n.remove() + kw['target'] = self.nodes[0] + self.status = apply(Builder.execute, (self,), kw) + class FailBuilder: def execute(self, **kw): return 1 @@ -117,8 +128,13 @@ class NodeTestCase(unittest.TestCase): global built_it class MyNode(SCons.Node.Node): + def __init__(self, **kw): + apply(SCons.Node.Node.__init__, (self,), kw) + self.remove_count = 0 def __str__(self): return self.path + def remove(self): + self.remove_count= self.remove_count+ 1 # Make sure it doesn't blow up if no builder is set. node = MyNode() node.build() @@ -147,6 +163,41 @@ class NodeTestCase(unittest.TestCase): assert str(built_target) == "qqq", str(built_target) assert built_source == ["rrr", "sss"], built_source + fff = MyNode() + ggg = MyNode() + lb = ListBuilder(fff, ggg) + e = Environment() + fff.builder_set(lb) + fff.env_set(e) + fff.path = "fff" + ggg.builder_set(lb) + ggg.env_set(e) + ggg.path = "ggg" + fff.sources = ["hhh", "iii"] + ggg.sources = ["hhh", "iii"] + + built_it = None + fff.build() + assert built_it + ggg.build() + assert ggg.remove_count== 1, ggg.remove_count + assert type(built_target) == type(MyNode()), type(built_target) + assert str(built_target) == "fff", str(built_target) + assert built_source == ["hhh", "iii"], built_source + + delattr(lb, 'status') + fff.remove_count = 0 + ggg.remove_count = 0 + + built_it = None + ggg.build() + #assert built_it + fff.build() + assert fff.remove_count== 1, fff.remove_count + assert type(built_target) == type(MyNode()), type(built_target) + assert str(built_target) == "fff", str(built_target) + assert built_source == ["hhh", "iii"], built_source + def test_builder_set(self): """Test setting a Node's Builder """ diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py index 02c14bba..504c6d1f 100644 --- a/src/engine/SCons/Node/__init__.py +++ b/src/engine/SCons/Node/__init__.py @@ -76,16 +76,22 @@ class Node: """Actually build the node. Return the status from the build.""" if not self.builder: return None - if not self.precious: - self.remove() try: - stat = self.builder.execute(env = self.env.Dictionary(), - target = self, source = self.sources) - except: - raise BuildError(self, "Exception", - sys.exc_type, - sys.exc_value, - sys.exc_traceback) + # If this Builder instance has already been called, + # there will already be an associated status. + stat = self.builder.status + except AttributeError: + if not self.precious: + self.remove() + try: + stat = self.builder.execute(env = self.env.Dictionary(), + target = self, + source = self.sources) + except: + raise BuildError(self, "Exception", + sys.exc_type, + sys.exc_value, + sys.exc_traceback) if stat: raise BuildError(node = self, errstr = "Error %d" % stat) -- 2.26.2