Fix setting the source_scanner if a source if used by more than one environment.
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 20 Sep 2003 14:36:55 +0000 (14:36 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 20 Sep 2003 14:36:55 +0000 (14:36 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@803 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Builder.py
src/engine/SCons/BuilderTests.py
src/engine/SCons/Node/__init__.py

index 08c35c8c16e4e3b8f13253bc70b48fd7e8df75b4..17d661ca21b39d8ee3088e683caa128a40fc71ff 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'):
+        if not 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:
-        if not hasattr(s, 'source_scanner'):
-             s.source_scanner = env.get_scanner(s.scanner_key())
+        if not 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 23f18c43cd8c1c833c59ca1a7c67db2b5df0ae98..cf11f6b0dd64ccee1592508e2a3960df07083bfa 100644 (file)
@@ -55,7 +55,6 @@ outfile = test.workpath('outfile')
 outfile2 = test.workpath('outfile2')
 
 show_string = None
-env_scanner = None
 
 scons_env = SCons.Environment.Environment()
 
@@ -71,6 +70,7 @@ class Environment:
             self.d[k] = v
         global env_arg2nodes_called
         env_arg2nodes_called = None
+        self.scanner = None
     def subst(self, s):
         if not SCons.Util.is_String(s):
             return s
@@ -94,7 +94,7 @@ class Environment:
             list.append(a)
         return list
     def get_scanner(self, ext):
-        return env_scanner
+        return self.scanner
     def Dictionary(self):
         return {}
     def autogenerate(self, dir=''):
@@ -130,6 +130,7 @@ class MyNode_without_target_from_source:
         self.sources = []
         self.builder = None
         self.side_effect = 0
+        self.source_scanner = None
     def __str__(self):
         return self.name
     def builder_set(self, builder):
@@ -743,19 +744,30 @@ class BuilderTestCase(unittest.TestCase):
 
     def test_src_scanner(slf):
         """Testing ability to set a source file scanner through a builder."""
-        global env_scanner
         class TestScanner:
             def key(self, env):
                  return 'TestScannerkey'
             def instance(self, env):
                  return self
-        env_scanner = TestScanner()
-        env = Environment()
+
+        scanner = TestScanner()
         builder = SCons.Builder.Builder(action='action')
-        tgt = builder(env, target='foo.x', source='bar.y')
+
+        # With no scanner specified, source_scanner is None.
+        env1 = Environment()
+        tgt = builder(env1, target='foo1.x', source='bar.y')
+        src = tgt.sources[0]
+        assert tgt.target_scanner != scanner, tgt.target_scanner
+        assert src.source_scanner is None, src.source_scanner
+
+        # Later use of the same source file with an environment that
+        # has a scanner must still set the scanner.
+        env2 = Environment()
+        env2.scanner = scanner
+        tgt = builder(env2, target='foo2.x', source='bar.y')
         src = tgt.sources[0]
-        assert tgt.target_scanner != env_scanner, tgt.target_scanner
-        assert src.source_scanner == env_scanner, src.source_scanner
+        assert tgt.target_scanner != scanner, tgt.target_scanner
+        assert src.source_scanner == scanner, src.source_scanner
 
     def test_Builder_Args(self):
         """Testing passing extra args to a builder."""
index 4dd0bd9e4949f4897422764313592dbbe10a07e8..dbcc4f08a75dfa13adca10355f02b4412e902baa 100644 (file)
@@ -112,11 +112,7 @@ class Node:
         self.parents = {}
         self.wkids = None       # Kids yet to walk, when it's an array
         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.source_scanner = None      # source scanner
 
         self.env = None
         self.state = None
@@ -201,21 +197,16 @@ 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.
-        try:
-            scanner = self.source_scanner
-        except AttributeError:
-            pass
-        else:
-            if scanner:
-                self.found_includes = {}
-                self.includes = None
+        if self.source_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:
@@ -393,17 +384,13 @@ class Node:
         build_env = self.get_build_env()
 
         for child in self.children(scan=0):
-            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))
+            scanner = child.source_scanner
+            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,