Fix dependency scans of generated files. (John Johnson)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 16 Sep 2003 06:39:36 +0000 (06:39 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Tue, 16 Sep 2003 06:39:36 +0000 (06:39 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@797 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/Builder.py
src/engine/SCons/BuilderTests.py
src/engine/SCons/Node/FS.py
src/engine/SCons/Node/__init__.py
test/HeaderGen.py [new file with mode: 0644]
test/HeaderInstall.py [new file with mode: 0644]

index 72491cb6f29c044ecce460356bde06ad157a9398..a2f94c1574da4fbc6e12fee96fc38975686fd636 100644 (file)
@@ -30,6 +30,11 @@ RELEASE X.XX - XXX
     can be used to avoid cluttering each directory with an individual
     .sconsign file.
 
+  From John Johnson:
+
+  - Fix (re-)scanning of dependencies in generated or installed
+    header files.
+
   From Steven Knight:
 
   - The -Q option suppressed too many messages; fix it so that it only
index fe017aeb79e88c2fa578610a99bd977a5e8b2056..08c35c8c16e4e3b8f13253bc70b48fd7e8df75b4 100644 (file)
@@ -207,13 +207,13 @@ def _init_nodes(builder, env, overrides, tlist, slist):
         t.set_executor(executor)
         if builder.scanner:
             t.target_scanner = builder.scanner
+        if not hasattr(t, 'source_scanner'):
+            t.source_scanner = env.get_scanner(t.scanner_key())
 
     # Last, add scanners from the Environment to the source Nodes.
     for s in slist:
-        src_key = s.scanner_key()        # the file suffix
-        scanner = env.get_scanner(src_key)
-        if scanner:
-            s.source_scanner = scanner
+        if not hasattr(s, 'source_scanner'):
+             s.source_scanner = env.get_scanner(s.scanner_key())
 
 class EmitterProxy:
     """This is a callable class that can act as a
index b51eb9fa475a4b8347dd319fae89d3be02fe46a2..23f18c43cd8c1c833c59ca1a7c67db2b5df0ae98 100644 (file)
@@ -752,10 +752,10 @@ class BuilderTestCase(unittest.TestCase):
         env_scanner = TestScanner()
         env = Environment()
         builder = SCons.Builder.Builder(action='action')
-        tgt = builder(env, target='foo.x', source='bar')
+        tgt = builder(env, target='foo.x', source='bar.y')
         src = tgt.sources[0]
         assert tgt.target_scanner != env_scanner, tgt.target_scanner
-        assert src.source_scanner == env_scanner
+        assert src.source_scanner == env_scanner, src.source_scanner
 
     def test_Builder_Args(self):
         """Testing passing extra args to a builder."""
index a78a2c905e7be82f671566c99849f9c9f97c8e3c..0abc21b494350209c05dbd489013324f86c516b1 100644 (file)
@@ -924,6 +924,7 @@ class Dir(Base):
         self.abspath_ = self.abspath + os.sep
         self.repositories = []
         self.srcdir = None
+        self.source_scanner = None
         
         self.entries = {}
         self.entries['.'] = self
index 3802aad4fe5a48c3466aa7be2f0c2b87e352ee72..4dd0bd9e4949f4897422764313592dbbe10a07e8 100644 (file)
@@ -111,9 +111,13 @@ class Node:
         self.implicit = None    # implicit (scanned) dependencies (None means not scanned yet)
         self.parents = {}
         self.wkids = None       # Kids yet to walk, when it's an array
-        self.source_scanner = None      # implicit scanner from scanner map
         self.target_scanner = None      # explicit scanner from this node's Builder
 
+        # If/when this attribute exists, it's an implicit scanner from
+        # the scanner map for an environment.  The attribute is created
+        # when we select the scanner, a value of None means there is none.
+        #self.source_scanner = None
+
         self.env = None
         self.state = None
         self.precious = None
@@ -197,16 +201,21 @@ class Node:
         # Clear out the implicit dependency caches:
         # XXX this really should somehow be made more general and put
         #     under the control of the scanners.
-        if self.source_scanner:
-            self.found_includes = {}
-            self.includes = None
+        try:
+            scanner = self.source_scanner
+        except AttributeError:
+            pass
+        else:
+            if scanner:
+                self.found_includes = {}
+                self.includes = None
 
-            def get_parents(node, parent): return node.get_parents()
-            def clear_cache(node, parent):
-                node.implicit = None
-                node.del_bsig()
-            w = Walker(self, get_parents, ignore_cycle, clear_cache)
-            while w.next(): pass
+                def get_parents(node, parent): return node.get_parents()
+                def clear_cache(node, parent):
+                    node.implicit = None
+                    node.del_bsig()
+                w = Walker(self, get_parents, ignore_cycle, clear_cache)
+                while w.next(): pass
 
         # clear out the content signature, since the contents of this
         # node were presumably just changed:
@@ -384,11 +393,17 @@ class Node:
         build_env = self.get_build_env()
 
         for child in self.children(scan=0):
-            self._add_child(self.implicit,
-                            self.implicit_dict,
-                            child.get_implicit_deps(build_env,
-                                                    child.source_scanner,
-                                                    self))
+            try:
+                scanner = child.source_scanner
+            except AttributeError:
+                pass
+            else:
+                if scanner:
+                    self._add_child(self.implicit,
+                                    self.implicit_dict,
+                                    child.get_implicit_deps(build_env,
+                                                            scanner,
+                                                            self))
 
         # scan this node itself for implicit dependencies
         self._add_child(self.implicit,
diff --git a/test/HeaderGen.py b/test/HeaderGen.py
new file mode 100644 (file)
index 0000000..9a3a6ab
--- /dev/null
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Test that dependencies in generated header files get re-scanned correctly.
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """\
+def writeFile(target, contents):
+    file = open(str(target[0]), 'wb')
+    file.write(contents)
+    file.close()
+    return 0
+
+env = Environment()
+libgen = env.StaticLibrary('gen', 'gen.cpp')
+Default(libgen)
+env.Command('gen2.h', [],
+            lambda env,target,source: writeFile(target, 'int foo = 3;\\n'))
+env.Command('gen.h', [],
+            lambda env,target,source: writeFile(target, '#include "gen2.h"\\n'))
+env.Command('gen.cpp', [],
+            lambda env,target,source: writeFile(target, '#include "gen.h"\\n'))
+""")
+
+test.run()
+
+test.up_to_date(arguments = '.')
+
+test.pass_test()
diff --git a/test/HeaderInstall.py b/test/HeaderInstall.py
new file mode 100644 (file)
index 0000000..523044c
--- /dev/null
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Test that dependencies in installed header files get re-scanned correctly.
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """
+env = Environment(CPPPATH=['#include'])
+Export('env')
+SConscript('dist/SConscript')
+libfoo = env.StaticLibrary('foo', ['foo.c'])
+Default(libfoo)
+""")
+
+test.write('foo.c', """
+#include <h1.h>
+""")
+
+test.subdir('dist')
+
+test.write(['dist', 'SConscript'], """\
+Import('env')
+env.Install('#include', ['h1.h', 'h2.h', 'h3.h'])
+""")
+
+test.write(['dist', 'h1.h'], """\
+#include "h2.h"
+""")
+
+test.write(['dist', 'h2.h'], """\
+#include "h3.h"
+""")
+
+test.write(['dist', 'h3.h'], """\
+int foo = 3;
+""")
+
+test.run(arguments = ".")
+
+test.up_to_date(arguments = ".")
+
+test.pass_test()