Commit graph

43 commits

Author SHA1 Message Date
Avery Pennarun
711b05766f 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.)
2018-11-02 02:20:52 -04:00
Avery Pennarun
613625b580 Add more assertions about uncommitted sqlite transactions.
I think we were sometimes leaving half-done sqlite transactions sitting
around for a long time (eg. across sub-calls to .do files).  This
seemed to be okay on Linux, but caused sqlite deadlocks on MacOS.  Most
likely it's not the operating system, but the sqlite version and
journal mode in use.

In any case, the correct thing to do is to actually commit or rollback
transactions, not leave them hanging around.

...unfortunately this doesn't actually fix my MacOS deadlocks, which
makes me rather nervous.
2018-10-06 05:06:19 -04:00
Joseph Garvin
e8790145be Use /usr/bin/env to detect python location
...in case it's installed in a nonstandard location.
2011-02-23 01:21:27 -08:00
Avery Pennarun
ea7057d9b6 redo-ifchange: remove special case for zero arguments.
Not sure why I put there, but special cases aren't worth the hassle.
2011-02-21 03:55:18 -08:00
Avery Pennarun
df85b3d163 Move dependency checking from redo-ifchange into deps.py.
In preparation for sharing between multiple commands.
2010-12-19 03:50:38 -08:00
Avery Pennarun
1cb000ece1 redo.py: report when you're trying to rebuild a static file.
In redo-ifchange, this might be a good idea, since you might just want to
set a dependency on it, so we won't say anything from inside builder.py.
But if you're calling redo.py, that means you expect it to be rebuilt, since
there's no other reason to try.  So print a warning.

(This is what make does, more or less.)
2010-12-11 21:19:15 -08:00
Avery Pennarun
fba684ee07 redo-ifchange can now be run even if there's no parent redo. 2010-12-11 19:08:53 -08:00
Avery Pennarun
e18fa85d58 The only thing in helpers.py that needed vars.py was the log stuff.
So put it in its own file.  Now it's safer to import and use helpers even if
you can't safely touch vars.
2010-12-11 18:34:02 -08:00
Avery Pennarun
0da5c7c082 Add a redo-always command: it adds an "always dirty" dependency to your target.
This is mostly useless except when combined with redo-stamp... I think.
2010-12-11 07:02:45 -08:00
Avery Pennarun
1d26d99e0c Fix a deadlock with redo-oob.
If a checksummed target A used to exist but is now missing, and we tried to
redo-ifchange that exact file, we would unnecessarily run 'redo-oob A A';
that is, we have to build A in order to determine if A needs to be built.

The sub-targets of redo-oob aren't run with REDO_UNLOCKED, so this would
deadlock instantly.

Add an assertion to redo-oob to ensure we never try to redo-ifchange the
primary target (thus converting the deadlock into an exception).  And skip
doing redo-oob when the target is already the same as the thing we have to
check.
2010-12-11 06:16:32 -08:00
Avery Pennarun
e7f7119f2e If a checksummed file is deleted, we should still use redo-oob.
We were giving up and rebuilding the toplevel object, which did eventually
rebuild our checksummed file, but then the file turned out to be identical
to what it was before, so that nobody *else* who depended on it ended up
getting rebuilt.  So the results were indeterminate.

Now we treat it as if its dirtiness is unknown, so we build it using
redo-oob before building any of its dependencies.
2010-12-11 05:54:39 -08:00
Avery Pennarun
f702417ef3 The second half of redo-stamp: out-of-order building.
If a depends on b depends on c, and c is dirty but b uses redo-stamp
checksums, then 'redo-ifchange a' is indeterminate: we won't know if we need
to run a.do unless we first build b, but the script that *normally* runs
'redo-ifchange b' is a.do, and we don't want to run that yet, because we
don't know for sure if b is dirty, and we shouldn't build a unless one of
its dependencies is dirty.  Eek!

Luckily, there's a safe solution.  If we *know* a is dirty - eg. because
a.do or one of its children has definitely changed - then we can just run
a.do immediately and there's no problem, even if b is indeterminate, because
we were going to run a.do anyhow.

If a's dependencies are *not* definitely dirty, and all we have is
indeterminate ones like b, then that means a's build process *hasn't
changed*, which means its tree of dependencies still includes b, which means
we can deduce that if we *did* run a.do, it would end up running b.do.

Since we know that anyhow, we can safely just run b.do, which will either
b.set_checked() or b.set_changed().  Once that's done, we can re-parse a's
dependencies and this time conclusively tell if it needs to be redone or
not.  Even if it does, b is already up-to-date, so the 'redo-ifchange b'
line in a.do will be fast.

...now take all the above and do it recursively to handle nested
dependencies, etc, and you're done.
2010-12-11 05:54:39 -08:00
Avery Pennarun
1355ade7c7 Correctly handle a checksummed file that depends on a non-checksummed file.
We were rebuilding the checksummed file every time because redo-ifchange was
incorrectly assuming that a child's changed_runid that's greater than my
changed_runid means I'm dirty.  But if my checked_runid is >= the child's
checked_runid, then I'm clean, because my checksum didn't change.

Clear as mud?
2010-12-11 05:54:39 -08:00
Avery Pennarun
ca67f5e71a redo-ifchange: fix relative pathnames printed in debug messages. 2010-12-11 02:15:42 -08:00
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
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
Avery Pennarun
10afd9000f Add some conditionals around some high-bandwidth debug statements.
When you have lots of unmodified dependencies, building these printout
strings (which aren't even printed unless you're using -d) ends up taking
something like 5% of the runtime.
2010-12-10 00:50:53 -08:00
Avery Pennarun
3ef2bd7300 Don't check as often whether the .redo directory exists.
Just check it once after running a subprocess: that's the only way it ought
to be able to disappear (ie. in a 'make clean' setup).
2010-12-10 00:50:52 -08:00
Avery Pennarun
fb79851530 Calculate dependencies with fewer sqlite queries. 2010-12-10 00:50:52 -08:00
Avery Pennarun
a62bd50d44 Switch state.py to use sqlite3 instead of filesystem-based stamps.
It passes all tests when run serialized, but still gives weird errors
(OperationalError: database is locked) when run with -j5.  sqlite3 shouldn't
be barfing just because the database is locked, since the default timeout is
5 seconds, and it's dying *way* faster than that.
2010-12-10 00:50:52 -08:00
Avery Pennarun
4669903887 The mtime of a directory is kind of useless, so don't use it. 2010-12-05 03:58:20 -08:00
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
Avery Pennarun
60f5446733 Correctly handle dependencies for "cd somewhere; redo-ifchange somefile"
We would build 'somefile' correctly the first time, but we wouldn't
attach the dependency on somefile to the right $TARGET, so our target would
not auto-rebuild in the future based on somefile.
2010-11-24 03:06:33 -08:00
Avery Pennarun
984ad747f8 Remove special case for "dirname" -> "dirname/all"
It actually decreases readability of the .do files - by not making it
explicit when you're going into a subdir.

Plus it adds ambiguity: what if there's a dirname.do *and* a dirname/all?
We could resolve the ambiguity if we wanted, but that adds more code, while
taking out this special case makes *less* code and improves readability.
I think it's the right way to go.
2010-11-24 02:48:27 -08:00
Avery Pennarun
cd853fccfb test.do would run all its subtasks even though it used 'redo-ifchange'.
The behaviour is what we wanted, but it shouldn't have worked.  So fix the
bug in redo-ifchange, then change test.do to use 'redo' instead so it
continues to do what we want, only for the right reason.

(The bug is that 'redo-ifchange dirname', which runs dirname/all.do, didn't
result in stamps getting checked correctly.)
2010-11-23 01:08:32 -08:00
Avery Pennarun
dd937d6102 redo-if{change,create}: print a useful message if REDO isn't set.
Again, I forgot to make vars.py not crash if the variables aren't set, so we
can print a useful error message.  But this time I have the right solution:
vars.py will do the checking for itself, and abort with a nice message.
2010-11-22 02:45:00 -08:00
Avery Pennarun
3209316856 builder.py: now the only exported function is main().
We can also avoid forking altogether if should_build() returns false.  This
doesn't seem to result in any noticeable speedup, but it's cleaner at least.
2010-11-21 23:36:29 -08:00
Avery Pennarun
9b800ca29f redo-ifchange.py: don't forget to release jwack tokens on exit.
This only really matters if it exited abnormally... but it still matters.
2010-11-21 21:15:24 -08:00
Avery Pennarun
840a8da1ef redo-ifchange: return nonzero if one of the dependencies fails to build.
Oops!  We were just always returning 0 (success) in that case.
2010-11-21 07:15:48 -08:00
Avery Pennarun
d6c5c06364 redo-ifchange: unstamp() was in the wrong spot, causing unnecessary rebuilds.
dirty_deps() changed its meaning now that we also have to check
state.isbuilt().  Now, just because dirty_deps() returns true doesn't mean
that the file should be unstamped (which forces a rebuild); this might have
happened because of state.isbuilt, which means someone already *did* do a
rebuild.

If we get past state.isbuilt() and into looking at the children, however,
and one of the children is dirty, then we should definitely unstamp the
current target.
2010-11-21 05:34:02 -08:00
Avery Pennarun
47edb9527d state.py: remove all the ugly fromdir= stuff.
Instead, just change the target name to be more specific, in the one place
in redo-ifchange that actually needed it.
2010-11-21 04:57:04 -08:00
Avery Pennarun
0652bc9911 Oops, earlier state.mark() stuff was a little too radical.
If someone else built and marked one of our dependencies, then that
dependency would show up as *clean* in a later redo-ifchange, so other
dependents of that file wouldn't be rebuilt.

We actually have to track two session-specific variables: whether the file
has been checked, and whether it was rebuilt.  (Or alternatively, whether it
was dirty when we checked it the first time.  But we store the former.)
2010-11-21 04:39:28 -08:00
Avery Pennarun
2f604b2c8f Don't re-check dependencies in a single run.
If a depends on b depends on c, then if when we consider building a, we have
to check b and c.  If we then are asked about a2 which depends on b, there
is no reason to re-check b and its dependencies; we already know it's done.

This takes the time to do 'redo t/curse/all' the *second* time down from
1.0s to 0.13s.  (make can still do it in 0.07s.)

'redo t/curse/all' the first time is down from 5.4s to to 4.6s.  With -j4,
from 3.0s to 2.5s.
2010-11-21 01:29:55 -08:00
Avery Pennarun
22f8cb48f4 redo-ifchange: call builder directly, rather than forking redo.
Now we no longer rebuild the same stuff over and over!
2010-11-19 07:32:16 -08:00
Avery Pennarun
132ff02840 Only mkdirp() the .redo directory in one place right at the beginning.
This doesn't really seem to change anything, but it's more correct and
should reveal weirdness (especially an incorrect .redo directory in a
sub-redo) sooner.
2010-11-19 03:16:39 -08:00
Avery Pennarun
dc3efb69cc Extract .redo dir state management stuff into its own file.
In preparation for changing the on-disk format eventually, as well as making
the main code more readable.
2010-11-19 03:16:29 -08:00
Avery Pennarun
a5ff60ccf3 Fix a race condition generating stampfiles.
This makes 'redo -j1000' now run successfully in t/curse, except that we
foolishly generate the same files more than once.  But at least not more
than once *in parallel*.
2010-11-19 00:57:27 -08:00
Avery Pennarun
84046bcab2 Some very suspicious changes to relpath() and sname() calls.
The problem is that redo-ifchange has a different $PWD than its
sub-dependencies, so as it's chasing them down, fixing up the relative paths
totally doesn't work at all.

There's probably a much smarter fix than this, but it's too late at night to
think of it right now.
2010-11-16 05:47:33 -08:00
Avery Pennarun
3de384497d Handle KeyboardInterrupt with less annoying spew to stderr. 2010-11-13 02:09:42 -08:00
Avery Pennarun
7505048093 redo-if*.py: import fewer things from helpers.
Just to keep track of how many helper functions we actually are using.  In
case I get brave and try to convert to C sometime.
2010-11-13 01:40:01 -08:00
Avery Pennarun
0bd6d07155 Prettier printing of errors. 2010-11-13 01:21:59 -08:00
Avery Pennarun
fc27b19108 Merge libdo.py and log.py into helpers.py. 2010-11-13 00:53:55 -08:00
Avery Pennarun
c57de820fb Move 'redo --ifchange' into 'redo-ifchange' to match djb's style.
It does simplify the logic of both redo.py and redo-ifchange.py, I suppose.
2010-11-13 00:47:49 -08:00