1. SCons
  2. Core
  3. SCons

Commits

Steven Knight  committed c2acb50

Track implicit (scanned) dependencies separately from the others.

  • Participants
  • Parent commits 280f7b7
  • Branches default

Comments (0)

Files changed (4)

File src/engine/SCons/Node/FS.py

View file
         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

File src/engine/SCons/Node/FSTests.py

View file
         # 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"))

File src/engine/SCons/Node/NodeTests.py

View file
         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.
 	"""

File src/engine/SCons/Node/__init__.py

View file
     """
 
     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
         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:
 	"""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([]):
         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