Track implicit (scanned) dependencies separately from the others.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 11 Dec 2001 06:54:13 +0000 (06:54 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 11 Dec 2001 06:54:13 +0000 (06:54 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@142 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Node/FS.py
src/engine/SCons/Node/FSTests.py
src/engine/SCons/Node/NodeTests.py
src/engine/SCons/Node/__init__.py

index b170ef623c7d8fae9b6447217886f961a88e39b4..cd12f6d810e720a5c68ccb85add6cf5b1a4ad098 100644 (file)
@@ -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
index fc58c4a90f313e062f06276a16e03b88dd3c208c..aecbfb40c2da989a7dea1de71980955b9172b12f 100644 (file)
@@ -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"))
index a3590a1c8b604f342f38860220e9419872813a05..46cfad457b365603bfc5278fcb2ec33128988814 100644 (file)
@@ -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.
        """
index d444c3de28edc7199c67381fad16cc7ad9713f33..8ee98e737b99163a74865b29c6aeee376e42ea3e 100644 (file)
@@ -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