Print a better message when detecting pre-existing cyclic dependencies.
We already printed an error at build time, but added the broken dependency anyway. If the .do script decided to succeed despite redo-ifchange aborting, the target would be successfully created and we'd end up with an infinite loop when running isdirty() later. The result was still "correct", because python helpfully aborted the infinite loop after the recursion got too deep. But let's explicitly detect it and print a better error message. (Thanks to Nils Dagsson Moskopp's redo-testcases repo for exposing this problem. If you put a #!/bin/sh header on your .do script means you need to run 'set -e' yourself if you want .do scripts to abort after an error, which you almost always do, and those testcases don't, which exposed this bug if you ran the tests twice.)
This commit is contained in:
parent
d143cca7da
commit
711b05766f
5 changed files with 17 additions and 3 deletions
|
|
@ -86,7 +86,11 @@ class BuildJob:
|
||||||
def start(self):
|
def start(self):
|
||||||
assert(self.lock.owned)
|
assert(self.lock.owned)
|
||||||
try:
|
try:
|
||||||
dirty = self.shouldbuildfunc(self.t)
|
try:
|
||||||
|
dirty = self.shouldbuildfunc(self.t)
|
||||||
|
except state.CyclicDependencyError:
|
||||||
|
err('cyclic dependency while checking %s\n' % _nice(self.t))
|
||||||
|
raise ImmediateReturn(208)
|
||||||
if not dirty:
|
if not dirty:
|
||||||
# target doesn't need to be built; skip the whole task
|
# target doesn't need to be built; skip the whole task
|
||||||
return self._after2(0)
|
return self._after2(0)
|
||||||
|
|
|
||||||
8
deps.py
8
deps.py
|
|
@ -6,8 +6,15 @@ CLEAN = 0
|
||||||
DIRTY = 1
|
DIRTY = 1
|
||||||
|
|
||||||
def isdirty(f, depth, max_changed,
|
def isdirty(f, depth, max_changed,
|
||||||
|
already_checked,
|
||||||
is_checked=state.File.is_checked,
|
is_checked=state.File.is_checked,
|
||||||
set_checked=state.File.set_checked_save):
|
set_checked=state.File.set_checked_save):
|
||||||
|
if f.id in already_checked:
|
||||||
|
raise state.CyclicDependencyError()
|
||||||
|
# make a copy of the list, so upon returning, our parent's copy
|
||||||
|
# is unaffected
|
||||||
|
already_checked = list(already_checked) + [f.id]
|
||||||
|
|
||||||
if vars.DEBUG >= 1:
|
if vars.DEBUG >= 1:
|
||||||
debug('%s?%s\n' % (depth, f.nicename()))
|
debug('%s?%s\n' % (depth, f.nicename()))
|
||||||
|
|
||||||
|
|
@ -50,6 +57,7 @@ def isdirty(f, depth, max_changed,
|
||||||
sub = isdirty(f2, depth = depth + ' ',
|
sub = isdirty(f2, depth = depth + ' ',
|
||||||
max_changed = max(f.changed_runid,
|
max_changed = max(f.changed_runid,
|
||||||
f.checked_runid),
|
f.checked_runid),
|
||||||
|
already_checked=already_checked,
|
||||||
is_checked=is_checked, set_checked=set_checked)
|
is_checked=is_checked, set_checked=set_checked)
|
||||||
if sub:
|
if sub:
|
||||||
debug('%s-- DIRTY (sub)\n' % depth)
|
debug('%s-- DIRTY (sub)\n' % depth)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@ def should_build(t):
|
||||||
f = state.File(name=t)
|
f = state.File(name=t)
|
||||||
if f.is_failed():
|
if f.is_failed():
|
||||||
raise builder.ImmediateReturn(32)
|
raise builder.ImmediateReturn(32)
|
||||||
dirty = deps.isdirty(f, depth = '', max_changed = vars.RUNID)
|
dirty = deps.isdirty(f, depth = '', max_changed = vars.RUNID,
|
||||||
|
already_checked=[])
|
||||||
return dirty==[f] and deps.DIRTY or dirty
|
return dirty==[f] and deps.DIRTY or dirty
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,5 +24,6 @@ def set_checked(f):
|
||||||
for f in state.files():
|
for f in state.files():
|
||||||
if f.is_generated and f.read_stamp() != state.STAMP_MISSING:
|
if f.is_generated and f.read_stamp() != state.STAMP_MISSING:
|
||||||
if deps.isdirty(f, depth='', max_changed=vars.RUNID,
|
if deps.isdirty(f, depth='', max_changed=vars.RUNID,
|
||||||
|
already_checked=[],
|
||||||
is_checked=is_checked, set_checked=set_checked):
|
is_checked=is_checked, set_checked=set_checked):
|
||||||
print f.nicename()
|
print f.nicename()
|
||||||
|
|
|
||||||
2
state.py
2
state.py
|
|
@ -365,7 +365,7 @@ class Lock:
|
||||||
assert(not self.owned)
|
assert(not self.owned)
|
||||||
if str(self.fid) in vars.get_locks():
|
if str(self.fid) in vars.get_locks():
|
||||||
# Lock already held by parent: cyclic dependence
|
# Lock already held by parent: cyclic dependence
|
||||||
raise CyclicDependencyError
|
raise CyclicDependencyError()
|
||||||
fcntl.lockf(self.lockfile, fcntl.LOCK_EX, 0, 0)
|
fcntl.lockf(self.lockfile, fcntl.LOCK_EX, 0, 0)
|
||||||
self.owned = True
|
self.owned = True
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue