summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/Sig
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/SCons/Sig')
-rw-r--r--src/engine/SCons/Sig/SigTests.py84
-rw-r--r--src/engine/SCons/Sig/__init__.py68
2 files changed, 65 insertions, 87 deletions
diff --git a/src/engine/SCons/Sig/SigTests.py b/src/engine/SCons/Sig/SigTests.py
index b42e464..2122fe7 100644
--- a/src/engine/SCons/Sig/SigTests.py
+++ b/src/engine/SCons/Sig/SigTests.py
@@ -52,6 +52,8 @@ class DummyNode:
self.builder = file.builder
self.depends = []
self.use_signature = 1
+ self.oldtime = 0
+ self.oldsig = 0
def get_contents(self):
# a file that doesn't exist has no contents:
@@ -85,6 +87,9 @@ class DummyNode:
def get_signature(self):
return self.sig
+ def get_oldentry(self):
+ return (self.oldtime, self.oldsig)
+
def create_files(test):
args = [(test.workpath('f1.c'), 'blah blah', 111, 0), #0
@@ -119,6 +124,15 @@ def create_nodes(files):
nodes[10].sources = [nodes[9]]
return nodes
+
+def current(calc, node):
+ s = calc.get_signature(node)
+ return calc.current(node, s)
+
+def write(calc, nodes):
+ for node in nodes:
+ node.oldtime = node.file.timestamp
+ node.oldsig = calc.get_signature(node)
class SigTestBase:
@@ -140,79 +154,77 @@ class SigTestBase:
calc = SCons.Sig.Calculator(self.module)
for node in nodes:
- self.failUnless(not calc.current(node), "none of the nodes should be current")
+ self.failUnless(not current(calc, node), "none of the nodes should be current")
# simulate a build:
self.files[1].modify('built', 222)
self.files[7].modify('built', 222)
self.files[9].modify('built', 222)
self.files[10].modify('built', 222)
-
- calc.write(nodes)
def test_built(self):
nodes = create_nodes(self.files)
calc = SCons.Sig.Calculator(self.module)
+
+ write(calc, nodes)
for node in nodes:
- self.failUnless(calc.current(node), "all of the nodes should be current")
-
- calc.write(nodes)
+ self.failUnless(current(calc, node), "all of the nodes should be current")
def test_modify(self):
nodes = create_nodes(self.files)
+ calc = SCons.Sig.Calculator(self.module)
+
+ write(calc, nodes)
+
#simulate a modification of some files
self.files[0].modify('blah blah blah', 333)
self.files[3].modify('blah blah blah', 333)
self.files[6].modify('blah blah blah', 333)
self.files[8].modify('blah blah blah', 333)
- calc = SCons.Sig.Calculator(self.module)
-
- self.failUnless(not calc.current(nodes[0]), "modified directly")
- self.failUnless(not calc.current(nodes[1]), "direct source modified")
- self.failUnless(calc.current(nodes[2]))
- self.failUnless(not calc.current(nodes[3]), "modified directly")
- self.failUnless(calc.current(nodes[4]))
- self.failUnless(calc.current(nodes[5]))
- self.failUnless(not calc.current(nodes[6]), "modified directly")
- self.failUnless(not calc.current(nodes[7]), "indirect source modified")
- self.failUnless(not calc.current(nodes[8]), "modified directory")
- self.failUnless(not calc.current(nodes[9]), "direct source modified")
- self.failUnless(not calc.current(nodes[10]), "indirect source modified")
-
- calc.write(nodes)
+ self.failUnless(not current(calc, nodes[0]), "modified directly")
+ self.failUnless(not current(calc, nodes[1]), "direct source modified")
+ self.failUnless(current(calc, nodes[2]))
+ self.failUnless(not current(calc, nodes[3]), "modified directly")
+ self.failUnless(current(calc, nodes[4]))
+ self.failUnless(current(calc, nodes[5]))
+ self.failUnless(not current(calc, nodes[6]), "modified directly")
+ self.failUnless(not current(calc, nodes[7]), "indirect source modified")
+ self.failUnless(not current(calc, nodes[8]), "modified directory")
+ self.failUnless(not current(calc, nodes[9]), "direct source modified")
+ self.failUnless(not current(calc, nodes[10]), "indirect source modified")
def test_delete(self):
nodes = create_nodes(self.files)
+
+ calc = SCons.Sig.Calculator(self.module)
+
+ write(calc, nodes)
#simulate the deletion of some files
self.files[1].modify(None, 0)
self.files[7].modify(None, 0)
self.files[9].modify(None, 0)
-
- calc = SCons.Sig.Calculator(self.module)
- self.failUnless(calc.current(nodes[0]))
- self.failUnless(not calc.current(nodes[1]), "deleted")
- self.failUnless(calc.current(nodes[2]))
- self.failUnless(calc.current(nodes[3]))
- self.failUnless(calc.current(nodes[4]))
- self.failUnless(calc.current(nodes[5]))
- self.failUnless(calc.current(nodes[6]))
- self.failUnless(not calc.current(nodes[7]), "deleted")
- self.failUnless(calc.current(nodes[8]))
- self.failUnless(not calc.current(nodes[9]), "deleted")
- self.failUnless(calc.current(nodes[10]),
+ self.failUnless(current(calc, nodes[0]))
+ self.failUnless(not current(calc, nodes[1]), "deleted")
+ self.failUnless(current(calc, nodes[2]))
+ self.failUnless(current(calc, nodes[3]))
+ self.failUnless(current(calc, nodes[4]))
+ self.failUnless(current(calc, nodes[5]))
+ self.failUnless(current(calc, nodes[6]))
+ self.failUnless(not current(calc, nodes[7]), "deleted")
+ self.failUnless(current(calc, nodes[8]))
+ self.failUnless(not current(calc, nodes[9]), "deleted")
+ self.failUnless(current(calc, nodes[10]),
"current even though it's source was deleted")
- calc.write(nodes)
-
class MD5TestCase(unittest.TestCase, SigTestBase):
"""Test MD5 signatures"""
diff --git a/src/engine/SCons/Sig/__init__.py b/src/engine/SCons/Sig/__init__.py
index 8e4ed56..36bceba 100644
--- a/src/engine/SCons/Sig/__init__.py
+++ b/src/engine/SCons/Sig/__init__.py
@@ -32,6 +32,15 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import os.path
import string
+
+#XXX Get rid of the global array so this becomes re-entrant.
+sig_files = []
+
+def write():
+ global sig_files
+ for sig_file in sig_files:
+ sig_file.write()
+
class SConsignFile:
"""
Encapsulates reading and writing a .sconsign file.
@@ -56,6 +65,9 @@ class SConsignFile:
time, signature = map(string.strip, string.split(rest, " "))
self.entries[filename] = (int(time), module.from_string(signature))
+ global sig_files
+ sig_files.append(self)
+
def get(self, filename):
"""
Get the signature for a file
@@ -103,7 +115,6 @@ class Calculator:
module - the signature module to use for signature calculations
"""
self.module = module
- self.sig_files = {}
def collect(self, node, signatures):
@@ -116,24 +127,11 @@ class Calculator:
"""
for source_node in node.children():
if not signatures.has_key(source_node):
- signature = self.signature(source_node)
+ signature = self.get_signature(source_node)
signatures[source_node] = signature
self.collect(source_node, signatures)
- def get_sig_file(self, dir):
- """
- Get a sconsign file from the cache, or add it to the cache.
-
- dir - the dir for the sconsign file
- returns - the sconsign file
- """
- if self.sig_files.has_key(dir):
- return self.sig_files[dir]
- else:
- self.sig_files[dir] = SConsignFile(dir, self.module)
- return self.sig_files[dir]
-
- def signature(self, node):
+ def get_signature(self, node):
"""
Get the signature for a node.
@@ -141,7 +139,7 @@ class Calculator:
returns - the signature or None if the signature could not
be computed.
- This method also stores the signature in the node and
+ This method does not store the signature in the node and
in the .sconsign file.
"""
@@ -163,22 +161,9 @@ class Calculator:
# XXX handle nodes that are not under the source root
sig = self.module.signature(node)
- node.set_signature(sig)
-
- dir, filename = os.path.split(node.path)
- if node.exists():
- timestamp = node.get_timestamp()
- else:
- timestamp = 0
-
- self.get_sig_file(dir).set(filename,
- timestamp,
- sig,
- self.module)
-
return sig
- def current(self, node):
+ def current(self, node, newsig):
"""
Check if a node is up to date.
@@ -196,30 +181,11 @@ class Calculator:
# that doesn't exist, or a directory.
return c
- dir, filename = os.path.split(node.path)
- oldtime, oldsig = self.get_sig_file(dir).get(filename)
+ oldtime, oldsig = node.get_oldentry()
newtime = node.get_timestamp()
if not node.builder and newtime == oldtime:
newsig = oldsig
- else:
- newsig = self.signature(node)
return self.module.current(newsig, oldsig)
-
- def write(self, nodes):
- """
- Write out all of the signature files.
-
- nodes - the nodes whose signatures may have changed durring
- the build
- """
-
- # make sure all the signatures have been calculated:
- for node in nodes:
- self.signature(node)
-
- for sig_file in self.sig_files.values():
- sig_file.write()
-