apenwarr-redo/redo-ifchange.py
Avery Pennarun 0126f6be1e Don't wipe the timestamp when a target fails to redo.
It's really a separate condition.  And since we're not removing the target
*file* in case of error - we update it atomically, and keeping it is better
than losing it - there's no reason to wipe the timestamp in that case
either.

However, we do need to know that the build failed, so that anybody else
(especially in a parallel build) who looks at that target knows that it
died.  So add a separate flag just for that.
2010-12-10 22:41:11 -08:00

66 lines
1.9 KiB
Python
Executable file

#!/usr/bin/python
import sys, os, errno, stat
import vars, state, builder, jwack
from helpers import debug, debug2, err, unlink
def dirty_deps(f, depth, max_changed):
if vars.DEBUG >= 1: debug('%s?%s\n' % (depth, f.name))
if f.changed_runid == None:
debug('%s-- DIRTY (never built)\n' % depth)
return True
if f.changed_runid > max_changed:
debug('%s-- DIRTY (built)\n' % depth)
return True # has been built more recently than parent
if f.is_checked():
if vars.DEBUG >= 1: debug('%s-- CLEAN (checked)\n' % depth)
return False # has already been checked during this session
if not f.stamp:
debug('%s-- DIRTY (no stamp)\n' % depth)
return True
if f.stamp != f.read_stamp():
debug('%s-- DIRTY (mtime)\n' % depth)
return True
for mode,f2 in f.deps():
if mode == 'c':
if os.path.exists(os.path.join(vars.BASE, f2.name)):
debug('%s-- DIRTY (created)\n' % depth)
return True
elif mode == 'm':
if dirty_deps(f2, depth = depth + ' ',
max_changed = f.changed_runid):
debug('%s-- DIRTY (sub)\n' % depth)
return True
f.set_checked()
f.save()
return False
def should_build(t):
f = state.File(name=t)
if f.is_failed():
raise builder.ImmediateReturn(32)
return dirty_deps(f, depth = '', max_changed = vars.RUNID)
rv = 202
try:
me = os.path.join(vars.STARTDIR,
os.path.join(vars.PWD, vars.TARGET))
f = state.File(name=me)
debug2('TARGET: %r %r %r\n' % (vars.STARTDIR, vars.PWD, vars.TARGET))
try:
targets = sys.argv[1:]
for t in targets:
f.add_dep('m', t)
f.save()
rv = builder.main(targets, should_build)
finally:
jwack.force_return_tokens()
except KeyboardInterrupt:
sys.exit(200)
sys.exit(rv)