apenwarr-redo/redo-ifchange.py
Avery Pennarun f6d11d5411 If a user manually changes a generated file, don't ever overwrite it.
That way the user can modify an auto-generated 'compile' script, for
example, and it'll stay modified.

If they delete the file, we can then generate it for them again.

Also, we have to warn whenever we're doing this, or people might think it's
a bug.
2010-12-10 22:43:11 -08:00

71 lines
2.1 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.failed_runid:
debug('%s-- DIRTY (failed last time)\n' % depth)
return True
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
if f.is_override:
builder.warn_override(f.name)
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)