Half-support for using file checksums instead of stamps.
A new redo-stamp program takes whatever you give it as stdin and uses it to calculate a checksum for the current target. If that checksum is the same as last time, then we consider the target to be unchanged, and we set checked_runid and stamp, but leave changed_runid alone. That will make future callers of redo-ifchange see this target as unmodified. However, this is only "half" support because by the time we run the .do script that calls redo-stamp, it's too late; the caller is a dependant of the stamped program, which is already being rebuilt, even if redo-stamp turns out to say that this target is unchanged. The other half is coming up.
This commit is contained in:
parent
ca67f5e71a
commit
22617d335c
12 changed files with 117 additions and 16 deletions
43
redo-stamp.py
Executable file
43
redo-stamp.py
Executable file
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/python
|
||||
import sys, os
|
||||
import vars, state
|
||||
from helpers import err, debug2
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
err('%s: no arguments expected.\n' % sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
# hashlib is only available in python 2.5 or higher, but the 'sha' module
|
||||
# produces a DeprecationWarning in python 2.6 or higher. We want to support
|
||||
# python 2.4 and above without any stupid warnings, so let's try using hashlib
|
||||
# first, and downgrade if it fails.
|
||||
try:
|
||||
import hashlib
|
||||
except ImportError:
|
||||
import sha
|
||||
sh = sha.sha()
|
||||
else:
|
||||
sh = hashlib.sha1()
|
||||
|
||||
while 1:
|
||||
b = os.read(0, 4096)
|
||||
sh.update(b)
|
||||
if not b: break
|
||||
|
||||
f = state.File(name=vars.TARGET)
|
||||
csum = sh.hexdigest()
|
||||
changed = (csum != f.csum)
|
||||
debug2('%s: old = %s\n' % (f.name, f.csum))
|
||||
debug2('%s: sum = %s (%s)\n' % (f.name, csum,
|
||||
changed and 'changed' or 'unchanged'))
|
||||
f.is_generated = True
|
||||
f.is_override = False
|
||||
f.failed_runid = None
|
||||
if changed:
|
||||
f.set_changed() # update_stamp might not do this if the mtime is identical
|
||||
f.csum = csum
|
||||
else:
|
||||
# unchanged
|
||||
f.set_checked()
|
||||
f.save()
|
||||
state.commit()
|
||||
Loading…
Add table
Add a link
Reference in a new issue