From 51bbdc6c5a280de99b4cbc2c46d78a8f0494c13c Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Mon, 6 Dec 2010 03:12:53 -0800 Subject: [PATCH] If we can't find a .do file for a target, mark it as not is_generated. This allows files to transition from generated to not-generated if the .do file is ever removed (ie. the user is changing things and the file is now a source file, not a target). --- builder.py | 18 +++++++++++------- state.py | 6 ++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/builder.py b/builder.py index dd42154..8a8b5ba 100644 --- a/builder.py +++ b/builder.py @@ -58,19 +58,23 @@ class BuildJob: # target doesn't need to be built; skip the whole task return self._after2(0) if (os.path.exists(t) and not os.path.exists(t + '/.') - and not state.is_generated(t) - and not os.path.exists('%s.do' % t)): - # an existing source file that is not marked as a generated file. - # This step is mentioned by djb in his notes. It turns out to be - # important to prevent infinite recursion. For example, a rule - # called default.c.do could be used to try to produce hello.c, - # which is undesirable since hello.c existed already. + and not state.is_generated(t)): + # an existing source file that was not generated by us. + # This step is mentioned by djb in his notes. + # For example, a rule called default.c.do could be used to try + # to produce hello.c, but we don't want that to happen if + # hello.c was created by the end user. + # FIXME: always refuse to redo any file that was modified outside + # of redo? That would make it easy for someone to override a + # file temporarily, and could be undone by deleting the file. + state.unmark_as_generated(t) state.stamp_and_maybe_built(t) return self._after2(0) state.start(t) (dofile, basename, ext) = _find_do_file(t) if not dofile: if os.path.exists(t): + state.unmark_as_generated(t) state.stamp_and_maybe_built(t) return self._after2(0) else: diff --git a/state.py b/state.py index de7e681..2986c15 100644 --- a/state.py +++ b/state.py @@ -97,6 +97,12 @@ def stamp(t): def unstamp(t): unlink(_stampname(t)) + unlink(_sname('dep', t)) + + +def unmark_as_generated(t): + unstamp(t) + unlink(_sname('gen', t)) def stamped(t):