Smarter sync'ing of the .sconsign file when it's written out at the end. (Stephen...
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 23 Oct 2004 13:20:11 +0000 (13:20 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sat, 23 Oct 2004 13:20:11 +0000 (13:20 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@1138 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/CHANGES.txt
src/engine/SCons/SConsign.py
src/engine/SCons/SConsignTests.py

index 4cfc71c46bb0a943f2acce398df6e8f1d11cc26f..69519f1a6261e496f7f1d43fccf2db2069f92510 100644 (file)
@@ -41,6 +41,11 @@ RELEASE 0.97 - XXX
     check for the build engine in the parent directory of the Python
     library directory (/usr/lib64 instead of /usr/lib).
 
+  From Stephen Kennedy:
+
+  - Speed up writing the .sconsign file at the end of a run by only
+    calling sync() once at the end, not after every entry.
+
   From Steven Knight:
 
   - When compiling with Microsoft Visual Studio, don't include the ATL and
index b7b06fe51809b436717c2a6d18c774939e9b4317..6610eafea88f2559da246945dd1007623bd8acc0 100644 (file)
@@ -46,7 +46,14 @@ database = None
 def write():
     global sig_files
     for sig_file in sig_files:
-        sig_file.write()
+        sig_file.write(sync=0)
+    if database:
+        try:
+            syncmethod = database.sync
+        except AttributeError:
+            pass # Not all anydbm modules have sync() methods.
+        else:
+            syncmethod()
 
 class Base:
     """
@@ -109,15 +116,18 @@ class DB(Base):
         global sig_files
         sig_files.append(self)
 
-    def write(self):
+    def write(self, sync=1):
         if self.dirty:
             global database
             database[self.dir.path] = cPickle.dumps(self.entries, 1)
-            try:
-                database.sync()
-            except AttributeError:
-                # Not all anydbm modules have sync() methods.
-                pass
+            if sync:
+                try:
+                    syncmethod = database.sync
+                except AttributeError:
+                    # Not all anydbm modules have sync() methods.
+                    pass
+                else:
+                    syncmethod()
 
 class Dir(Base):
     def __init__(self, fp=None, module=None):
@@ -162,7 +172,7 @@ class DirFile(Dir):
         global sig_files
         sig_files.append(self)
 
-    def write(self):
+    def write(self, sync=1):
         """
         Write the .sconsign file to disk.
 
index 16ef81640e1c19bd0e877a05431668b84c79322f..c2c05ac52210e97667a34d96de4677a8e246c065 100644 (file)
@@ -32,16 +32,16 @@ class BuildInfo:
     def __init__(self, name):
         self.name = name
 
+class DummyModule:
+    def to_string(self, sig):
+        return str(sig)
+
+    def from_string(self, sig):
+        return int(sig)
+
 class BaseTestCase(unittest.TestCase):
 
     def runTest(self):
-        class DummyModule:
-            def to_string(self, sig):
-                return str(sig)
-
-            def from_string(self, sig):
-                return int(sig)
-            
         class DummyNode:
             path = 'not_a_valid_path'
 
@@ -124,13 +124,6 @@ class SConsignDBTestCase(unittest.TestCase):
 class SConsignDirFileTestCase(unittest.TestCase):
 
     def runTest(self):
-        class DummyModule:
-            def to_string(self, sig):
-                return str(sig)
-
-            def from_string(self, sig):
-                return int(sig)
-            
         class DummyNode:
             path = 'not_a_valid_path'
 
@@ -193,6 +186,39 @@ class SConsignFileTestCase(unittest.TestCase):
         assert fake_dbm.mode == "c", fake_dbm.mode
 
 
+class writeTestCase(unittest.TestCase):
+
+    def runTest(self):
+
+        class DummyNode:
+            path = 'not_a_valid_path'
+
+        test = TestCmd.TestCmd(workdir = '')
+        file = test.workpath('sconsign_file')
+
+        class Fake_DBM:
+            def __setitem__(self, key, value):
+                pass
+            def open(self, name, mode):
+                self.sync_count = 0
+                return self
+            def sync(self):
+                self.sync_count = self.sync_count + 1
+
+        fake_dbm = Fake_DBM()
+
+        SCons.SConsign.database = None
+        SCons.SConsign.File(file, fake_dbm)
+
+        f = SCons.SConsign.DirFile(DummyNode(), DummyModule())
+
+        f.set_entry('foo', BuildInfo('foo'))
+        f.set_entry('bar', BuildInfo('bar'))
+
+        SCons.SConsign.write()
+
+        assert fake_dbm.sync_count == 1, fake_dbm.sync_count
+
 
 def suite():
     suite = unittest.TestSuite()
@@ -200,6 +226,7 @@ def suite():
     suite.addTest(SConsignDBTestCase())
     suite.addTest(SConsignDirFileTestCase())
     suite.addTest(SConsignFileTestCase())
+    suite.addTest(writeTestCase())
     return suite
 
 if __name__ == "__main__":