apenwarr-redo/redo-ifchange.py
Avery Pennarun c29de89051 Fix more trouble with .do scripts that cd to other directories.
The interaction of REDO_STARTDIR, REDO_PWD, and getcwd() are pretty
complicated.  In this case, we accidentally assumed that the current
instance of redo was running with getcwd() == REDO_STARTDIR+REDO_PWD, and so
the new target was REDO_STARTDIR+REDO_PWD+t, but this isn't the case if the
current .do script did chdir().

The correct answer is REDO_STARTDIR+getcwd()+t.
2010-11-25 06:37:24 -08:00

64 lines
1.8 KiB
Python
Executable file

#!/usr/bin/python
import sys, os, errno
import vars, state, builder, jwack
from helpers import debug, debug2, err, mkdirp, unlink
def dirty_deps(t, depth):
try:
st = os.stat(t)
realtime = st.st_mtime
except OSError:
st = None
realtime = 0
debug('%s?%s\n' % (depth, t))
if state.isbuilt(t):
debug('%s-- DIRTY (built)\n' % depth)
return True # has already been built during this session
if state.ismarked(t):
debug('%s-- CLEAN (marked)\n' % depth)
return False # has already been checked during this session
stamptime = state.stamped(t)
if stamptime == None:
debug('%s-- DIRTY (no stamp)\n' % depth)
return True
if stamptime != realtime:
debug('%s-- DIRTY (mtime)\n' % depth)
return True
for mode,name in state.deps(t):
if mode == 'c':
if os.path.exists(name):
debug('%s-- DIRTY (created)\n' % depth)
return True
elif mode == 'm':
if dirty_deps(os.path.join(vars.BASE, name), depth + ' '):
debug('%s-- DIRTY (sub)\n' % depth)
state.unstamp(t) # optimization for future callers
return True
state.mark(t)
return False
def should_build(t):
return not state.isbuilt(t) and dirty_deps(t, depth = '')
rv = 202
try:
me = os.path.join(vars.STARTDIR,
os.path.join(vars.PWD, vars.TARGET))
debug2('TARGET: %r %r %r\n' % (vars.STARTDIR, vars.PWD, vars.TARGET))
try:
targets = sys.argv[1:]
for t in targets:
state.add_dep(me, 'm', t)
rv = builder.main(targets, should_build)
finally:
jwack.force_return_tokens()
except KeyboardInterrupt:
sys.exit(200)
sys.exit(rv)