Move the set_state(EXECUTED) call associated with pulling things
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 22 Feb 2009 06:34:14 +0000 (06:34 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 22 Feb 2009 06:34:14 +0000 (06:34 +0000)
out of a CacheDir from CacheDir.py to Taskmaster.py.  Ripple effects
include adding a Node.FS.push_to_cache() method, so that logic can
be invoked separately from the Node.built() method.

git-svn-id: http://scons.tigris.org/svn/scons/trunk@4035 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/CacheDir.py
src/engine/SCons/CacheDirTests.py
src/engine/SCons/Node/FS.py
src/engine/SCons/Node/NodeTests.py
src/engine/SCons/Node/__init__.py
src/engine/SCons/SConfTests.py
src/engine/SCons/Taskmaster.py
src/engine/SCons/TaskmasterTests.py

index c5ec14e09fd60c648b6760817a8e0143d2f681d4..73bfe6be3473c322cd63ac267199f11670ff6cc5 100644 (file)
@@ -190,22 +190,16 @@ class CacheDir:
         if not self.is_enabled():
             return False
 
-        retrieved = False
-
+        env = node.get_build_env()
         if cache_show:
-            if CacheRetrieveSilent(node, [], node.get_build_env(), execute=1) == 0:
+            if CacheRetrieveSilent(node, [], env, execute=1) == 0:
                 node.build(presub=0, execute=0)
-                retrieved = 1
+                return True
         else:
-            if CacheRetrieve(node, [], node.get_build_env(), execute=1) == 0:
-                retrieved = 1
-        if retrieved:
-            # Record build signature information, but don't
-            # push it out to cache.  (We just got it from there!)
-            node.set_state(SCons.Node.executed)
-            SCons.Node.Node.built(node)
-
-        return retrieved
+            if CacheRetrieve(node, [], env, execute=1) == 0:
+                return True
+
+        return False
 
     def push(self, node):
         if not self.is_enabled():
index fd36cceaff3d2b8c16ee9dbc186603732f04873b..5e63548ab2055a500e64306a9a353451b636b9dd 100644 (file)
@@ -194,10 +194,10 @@ class FileTestCase(BaseTestCase):
 
             cd_f3 = self.test.workpath("cd.f3")
             f3 = self.File(cd_f3)
-            f3.built()
+            f3.push_to_cache()
             assert self.pushed == [], self.pushed
             self.test.write(cd_f3, "cd.f3\n")
-            f3.built()
+            f3.push_to_cache()
             assert self.pushed == [f3], self.pushed
 
             self.pushed = []
@@ -240,7 +240,7 @@ class FileTestCase(BaseTestCase):
 
             warn_caught = 0
             try:
-                f7.built()
+                f7.push_to_cache()
             except SCons.Errors.BuildError, e:
                 assert e.exc_info[0] == SCons.Warnings.CacheWriteErrorWarning
                 warn_caught = 1
index 62d39dd954802652c3b0ce3b58736a372976eb1b..a4036ab3a3d8d6a3e0b7a4ac790efb6940dc2f2b 100644 (file)
@@ -2562,6 +2562,22 @@ class File(Base):
         # created.
         self.dir._create()
 
+    def push_to_cache(self):
+        """Try to push the node into a cache
+        """
+        # This should get called before the Nodes' .built() method is
+        # called, which would clear the build signature if the file has
+        # a source scanner.
+        #
+        # We have to clear the local memoized values *before* we push
+        # the node to cache so that the memoization of the self.exists()
+        # return value doesn't interfere.
+        if self.nocache:
+            return
+        self.clear_memoized_values()
+        if self.exists():
+            self.get_build_env().get_CacheDir().push(self)
+
     def retrieve_from_cache(self):
         """Try to retrieve the node's content from a cache
 
@@ -2577,22 +2593,6 @@ class File(Base):
             return None
         return self.get_build_env().get_CacheDir().retrieve(self)
 
-    def built(self):
-        """
-        Called just after this node is successfully built.
-        """
-        # Push this file out to cache before the superclass Node.built()
-        # method has a chance to clear the build signature, which it
-        # will do if this file has a source scanner.
-        #
-        # We have to clear the memoized values *before* we push it to
-        # cache so that the memoization of the self.exists() return
-        # value doesn't interfere.
-        self.clear_memoized_values()
-        if self.exists():
-            self.get_build_env().get_CacheDir().push(self)
-        SCons.Node.Node.built(self)
-
     def visited(self):
         if self.exists():
             self.get_build_env().get_CacheDir().push_if_forced(self)
index ce56d5a5b7f4b4798caa320a15cdf6a886056532..4612d3f796e21c583b62ca9032980a493bd14145 100644 (file)
@@ -435,6 +435,12 @@ class NodeTestCase(unittest.TestCase):
         assert n.cleared, n.cleared
         assert n.ninfo.updated, n.ninfo.cleared
 
+    def test_push_to_cache(self):
+        """Test the base push_to_cache() method"""
+        n = SCons.Node.Node()
+        r = n.push_to_cache()
+        assert r is None, r
+
     def test_retrieve_from_cache(self):
         """Test the base retrieve_from_cache() method"""
         n = SCons.Node.Node()
index 6852f69bc3ddc47ccff1a5d5b761ae4c54e0b9b4..ee9083ce267c3774048a259876a59f5b9090cdc2 100644 (file)
@@ -297,6 +297,11 @@ class Node:
         except AttributeError:
             pass
 
+    def push_to_cache(self):
+        """Try to push a node into a cache
+        """
+        pass
+
     def retrieve_from_cache(self):
         """Try to retrieve the node's content from a cache
 
index 24cfb8d6478fc5e8a76bb9703b1277908bdb41de..2fa173d930ee5b0c2fe7cae9aa5d9190381dd369 100644 (file)
@@ -207,6 +207,8 @@ class SConfTestCase(unittest.TestCase):
                         return None
                     def prepare(self):
                         pass
+                    def push_to_cache(self):
+                        pass
                     def retrieve_from_cache(self):
                         return 0
                     def build(self, **kw):
index 8e71be96358c3da596437ca884f3a19424c376d3..91eac358682b93873eef7830b4f0f82bf79bcee7 100644 (file)
@@ -223,7 +223,14 @@ class Task:
         try:
             everything_was_cached = 1
             for t in self.targets:
-                if not t.retrieve_from_cache():
+                if t.retrieve_from_cache():
+                    # Call the .built() method without calling the
+                    # .push_to_cache() method, since we just got the
+                    # target from the cache and don't need to push
+                    # it back there.
+                    t.set_state(NODE_EXECUTED)
+                    t.built()
+                else:
                     everything_was_cached = 0
                     break
             if not everything_was_cached:
@@ -279,6 +286,7 @@ class Task:
                 for side_effect in t.side_effects:
                     side_effect.set_state(NODE_NO_STATE)
                 t.set_state(NODE_EXECUTED)
+                t.push_to_cache()
                 t.built()
             t.visited()
 
index 282f4dff65c5576687873a4b5a8dd831c5d46dac..6c8023020753441f92734641a1b56ffbde03ad06 100644 (file)
@@ -69,6 +69,9 @@ class Node:
     def disambiguate(self):
         return self
 
+    def push_to_cache(self):
+        pass
+
     def retrieve_from_cache(self):
         global cache_text
         if self.cached:
@@ -87,7 +90,8 @@ class Node:
 
     def built(self):
         global built_text
-        built_text = built_text + " really"
+        if not self.cached:
+            built_text = built_text + " really"
 
     def has_builder(self):
         return not self.builder is None