From 072efde35b4b50813df8cece7c463cf11e1c5b3a Mon Sep 17 00:00:00 2001 From: stevenknight Date: Tue, 11 Dec 2001 06:54:13 +0000 Subject: [PATCH] Track implicit (scanned) dependencies separately from the others. git-svn-id: http://scons.tigris.org/svn/scons/trunk@142 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- src/engine/SCons/Node/FS.py | 7 ++--- src/engine/SCons/Node/FSTests.py | 13 ++++------ src/engine/SCons/Node/NodeTests.py | 41 ++++++++++++++++++++++++++++++ src/engine/SCons/Node/__init__.py | 21 +++++++++++---- 4 files changed, 66 insertions(+), 16 deletions(-) diff --git a/src/engine/SCons/Node/FS.py b/src/engine/SCons/Node/FS.py index b170ef62..cd12f6d8 100644 --- a/src/engine/SCons/Node/FS.py +++ b/src/engine/SCons/Node/FS.py @@ -466,10 +466,11 @@ class File(Entry): return self.dir.sconsign().get(self.name) def scan(self): - if not self.scanned and self.env: + if not self.scanned.has_key(self.scanner) and self.env: if self.scanner: - self.add_dependency(self.scanner.scan(self.path, self.env)) - self.scanned = 1 + self.add_implicit(self.scanner.scan(self.path, self.env), + self.scanner) + self.scanned[self.scanner] = 1 def __createDir(self): # ensure that the directories for this node are diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index fc58c4a9..aecbfb40 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -303,16 +303,13 @@ class FSTestCase(unittest.TestCase): # Test scanning f1.scanner = Scanner() f1.scan() - assert f1.depends[0].path_ == os.path.join("d1", "f1") - f1.scanner = None - f1.scanned = None + assert f1.implicit[f1.scanner][0].path_ == os.path.join("d1", "f1") + del f1.implicit[f1.scanner] f1.scan() - assert f1.depends[0].path_ == os.path.join("d1", "f1") - f1.scanner = None - f1.scanned = None - f1.depends = [] + assert len(f1.implicit) == 0, f1.implicit + del f1.scanned[f1.scanner] f1.scan() - assert not f1.depends + assert f1.implicit[f1.scanner][0].path_ == os.path.join("d1", "f1") # Test building a file whose directory is not there yet... f1 = fs.File(test.workpath("foo/bar/baz/ack")) diff --git a/src/engine/SCons/Node/NodeTests.py b/src/engine/SCons/Node/NodeTests.py index a3590a1c..46cfad45 100644 --- a/src/engine/SCons/Node/NodeTests.py +++ b/src/engine/SCons/Node/NodeTests.py @@ -218,6 +218,47 @@ class NodeTestCase(unittest.TestCase): assert three.get_parents() == [node] assert four.get_parents() == [node] + def test_add_implicit(self): + """Test adding implicit (scanned) dependencies to a Node's list. + """ + node = SCons.Node.Node() + assert node.implicit == {} + + zero = SCons.Node.Node() + try: + node.add_source(zero) + except TypeError: + pass + else: + assert 0 + + one = SCons.Node.Node() + two = SCons.Node.Node() + three = SCons.Node.Node() + four = SCons.Node.Node() + + node.add_implicit([one], 1) + assert node.implicit[1] == [one] + node.add_implicit([two, three], 1) + assert node.implicit[1] == [one, two, three] + node.add_implicit([three, four, one], 1) + assert node.implicit[1] == [one, two, three, four] + + assert zero.get_parents() == [] + assert one.get_parents() == [node] + assert two.get_parents() == [node] + assert three.get_parents() == [node] + assert four.get_parents() == [node] + + node.add_implicit([one], 2) + node.add_implicit([two, three], 3) + node.add_implicit([three, four, one], 4) + + assert node.implicit[1] == [one, two, three, four] + assert node.implicit[2] == [one] + assert node.implicit[3] == [two, three] + assert node.implicit[4] == [three, four, one] + def test_children(self): """Test fetching the "children" of a Node. """ diff --git a/src/engine/SCons/Node/__init__.py b/src/engine/SCons/Node/__init__.py index d444c3de..8ee98e73 100644 --- a/src/engine/SCons/Node/__init__.py +++ b/src/engine/SCons/Node/__init__.py @@ -55,12 +55,13 @@ class Node: """ def __init__(self): - self.sources = [] - self.depends = [] + self.sources = [] # source files used to build node + self.depends = [] # explicit dependencies (from Depends) + self.implicit = {} # implicit (scanned) dependencies self.parents = [] self.builder = None self.scanner = None - self.scanned = 0 + self.scanned = {} self.env = None self.state = None self.bsig = None @@ -101,7 +102,7 @@ class Node: self.scanner = scanner def scan(self): - self.scanned = 1 + self.scanned[self.scanner] = 1 def env_set(self, env, safe=0): if safe and self.env: @@ -134,6 +135,13 @@ class Node: """Adds sources. The source argument must be a list.""" self._add_child(self.sources, source) + def add_implicit(self, implicit, key): + """Adds implicit (scanned) dependencies. The implicit + argument must be a list.""" + if not self.implicit.has_key(key): + self.implicit[key] = [] + self._add_child(self.implicit[key], implicit) + def _add_child(self, collection, child): """Adds 'child' to 'collection'. The 'child' argument must be a list""" if type(child) is not type([]): @@ -151,7 +159,10 @@ class Node: if parent not in self.parents: self.parents.append(parent) def children(self): - return self.sources + self.depends + #XXX Need to remove duplicates from this + return self.sources \ + + self.depends \ + + reduce(lambda x, y: x + y, self.implicit.values(), []) def get_parents(self): return self.parents -- 2.26.2