3 The Signature package for the scons software construction utility.
7 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
14 Encapsulates reading and writing a .sconsign file.
17 def __init__(self, dir, module):
19 dir - the directory for the file
20 module - the signature module being used
23 self.path = os.path.join(dir, '.sconsign')
27 file = open(self.path, 'rt')
31 for line in file.readlines():
32 filename, rest = map(string.strip, string.split(line, ":"))
33 time, signature = map(string.strip, string.split(rest, " "))
34 self.entries[filename] = (int(time), module.from_string(signature))
36 def get(self, filename):
38 Get the signature for a file
40 filename - the filename whose signature will be returned
41 returns - (timestamp, signature)
45 return self.entries[filename]
49 def set(self, filename, timestamp, signature, module):
51 Set the signature for a file
53 filename - the filename whose signature will be set
54 timestamp - the timestamp
55 signature - the signature
56 module - the signature module being used
58 self.entries[filename] = (timestamp, module.to_string(signature))
62 Write the .sconsign file to disk.
65 file = open(self.path, 'wt')
66 for item in self.entries.items():
67 file.write("%s: %d %s\n" % (item[0], item[1][0], item[1][1]))
72 Encapsulates signature calculations and .sconsign file generating
76 def __init__(self, module):
78 Initialize the calculator.
80 module - the signature module to use for signature calculations
86 def collect(self, node, signatures):
88 Collect the signatures of the node's sources.
90 node - the node whose sources will be collected
91 signatures - the dictionary that the signatures will be
94 for source_node in node.sources + node.depends:
95 if not signatures.has_key(source_node):
96 signature = self.signature(source_node)
97 signatures[source_node] = signature
98 self.collect(source_node, signatures)
100 def get_sig_file(self, dir):
102 Get a sconsign file from the cache, or add it to the cache.
104 dir - the dir for the sconsign file
105 returns - the sconsign file
107 if self.sig_files.has_key(dir):
108 return self.sig_files[dir]
110 self.sig_files[dir] = SConsignFile(dir, self.module)
111 return self.sig_files[dir]
113 def signature(self, node):
115 Get the signature for a node.
118 returns - the signature or None if the signature could not
121 This method also stores the signature in the node and
122 in the .sconsign file.
125 if node.has_signature():
126 sig = node.get_signature()
129 self.collect(node, signatures)
130 signatures = filter(lambda x: not x is None, signatures.values())
131 sig = self.module.collect(signatures)
133 if not node.exists():
136 # XXX handle nodes that are not under the source root
137 sig = self.module.signature(node)
139 node.set_signature(sig)
141 dir, filename = os.path.split(node.path)
143 timestamp = node.get_timestamp()
147 self.get_sig_file(dir).set(filename,
154 def current(self, node):
156 Check if a node is up to date.
158 node - the node whose signature will be checked
160 returns - 0 if the signature has changed since the last invocation,
164 if not node.exists():
167 dir, filename = os.path.split(node.path)
168 oldtime, oldsig = self.get_sig_file(dir).get(filename)
170 newtime = node.get_timestamp()
172 if not node.derived and newtime == oldtime:
175 newsig = self.signature(node)
177 return newsig == oldsig
179 def write(self, nodes):
181 Write out all of the signature files.
183 nodes - the nodes whose signatures may have changed durring
187 # make sure all the signatures have been calculated:
191 for sig_file in self.sig_files.values():