Commit graph

61 commits

Author SHA1 Message Date
Avery Pennarun
07af5d83f9 redo: only default to 'all' in the toplevel instance of redo.
We already did this in minimal/do, and redo-ifchange already did this, but
plain redo didn't.  This made constructs like:

	for d in *.x; do
		echo "${d%.x}"
	done | xargs redo

dangerous, because if there were no matching files, we'd try to 'redo all'.
2011-03-10 21:10:15 -08: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
Wayne Larsen
39cfdafd8a Add --version flag to redo.
Something to this effect would be useful, though I'm sure my
install.do changes are not how you'd do it.

(Slightly modified by apenwarr)
2011-01-25 23:14:18 -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
501b534308 Add a new --debug-pids option.
This makes the helpers.* log functions prepend getpid() to each line, so you
can see which pid did what.
2010-11-22 01:50:46 -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
b937e62d89 Add a new -k (--keep-going) option, like make has.
Previously, the default was to *always* keep going, which is actually not
usually what you want.  Now we actually exit correctly after an error.  Of
course you still might have multiple errors before existing if you were
building in parallel.
2010-11-21 07:15:48 -08:00
Avery Pennarun
6b0da1fda0 Add a -x option that just passes -x to the subshell.
This is often more useful than -v, since it prints the actual commands being
executed, not just the lines being input from the script.
2010-11-21 06:36:15 -08:00
Avery Pennarun
03a054ca79 Add a --debug-locks option.
Get rid of the "locked..." and "...unlocked!" messages by default, since
they're not usually interesting.  But add a new option to bring them back in
case we end up with trouble debugging the locking stuff.  (I don't really
100% trust it yet, although I haven't had a problem for a while now.)
2010-11-21 06:23:41 -08:00
Avery Pennarun
b19a918894 Test for the previous bugfix.
This fails if you make test *twice* without the preceding patch.
Unfortunately I couldn't find a good way to make it fail if you only make
test once.
2010-11-21 04:41:03 -08:00
Avery Pennarun
700873a90f Slightly clarify the initialization code in redo.py. 2010-11-21 02:26:18 -08:00
Avery Pennarun
12983bd88d Move initialization of .redo directory into state.init(). 2010-11-21 02:26:18 -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
f7734c3b8d Split build functions into builder.py. 2010-11-19 07:32:04 -08:00
Avery Pennarun
116e7e5f13 We now check the lock before releasing our jwack token.
That way, if everything is locked, we can determine that with a single
token, reducing context switches.

But mostly this is good because the code is simpler.
2010-11-19 07:20:55 -08:00
Avery Pennarun
c10875d7d7 Don't unlink(t) before building; always rebuild the target if it was locked.
The 'redo' command is supposed to *always* rebuild, not just if nobody else
rebuilt it.  (If you want "rebuild sometimes" behaviour, use redo-ifchange.)
Thus, we shouldn't be short circuiting it just because a file was previously
locked and then built okay.

However, there's still a race condition in parallel builds, because
redo-ifchange only checks the build stamp of each file once, then passes it
to redo.  Thus, we end up trying to build the same stuff over and over.
This change actually makes it build *more* times, which seems dumb, but is
one step closer to right.

Doing this broke 'make test', however, because we were unlinking the target
right before building it, rather than replacing it atomically as djb's
original design suggested we should do.  Thus, because of the combination of
the above two bugs, CC would appear and then disappear even as people were
trying to actually use it.  Now it gets replaced atomically so it should
at least work at all times... even though we're still building it more than
once, which is incorrect.
2010-11-19 06:43:18 -08:00
Avery Pennarun
362ca2997a A whole bunch of cleanups to state.Lock.
Now t/curse passes again when parallelized (except for the countall
mismatch, since we haven't fixed the source of that problem yet).  At least
it's consistent now.

There's a bunch of stuff rearranged in here, but the actual important
problem was that we were doing unlink() on the lock fifo even if ENXIO,
which meant a reader could connect in between ENXIO and unlink(), and thus
never get notified of the disconnection.  This would cause the build to
randomly freeze.
2010-11-19 06:07:41 -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
81356931a4 Oops, when searching up the tree, we'd use ../.redo/.redo as the redodir.
Obviously it should be ../.redo instead.  REDO_BASE is .., not ../.redo.
2010-11-19 03:15:45 -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
c4287b9d81 Improve 'redo -v' output whitespace.
It was too hard to tell when an ifchange ended and the commands from the
prior level started running again.  Now it's a little better.
2010-11-18 23:06:38 -08:00
Avery Pennarun
2b71e662cb Replace lockfile stuff with fifos instead.
Now people waiting for a lock can wait for the fifo to be ready, which means
it's instant instead of polled.  Very pretty.  Probably doesn't work on
Windows though.
2010-11-18 22:46:30 -08:00
Avery Pennarun
c7585558ef If the .do script deletes $3, don't die. 2010-11-17 17:55:16 -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
d9fe4806ac Oops, 'redo t/c.c' didn't work, because find_do_file() was slightly wrong.
We weren't searching for default.*.do in the subdir when needed.
2010-11-16 04:16:01 -08:00
Avery Pennarun
94b0e7166e Move atoi() into atoi.py and add a new debug2() debug level.
atoi() was getting redundant, and unfortunately we can't easily load
helpers.py in some places where we'd want to, because it depends on vars.py.
So move it to its own module.
2010-11-16 04:13:17 -08:00
Avery Pennarun
75063244b2 redo.py: we weren't removing the lock if there was a build error, oops.
try/finally doesn't work if there's an os._exit() in there.
2010-11-16 04:06:26 -08:00
Avery Pennarun
95d4e64a11 If foo and foo.do exist, then foo is always a target, not a source file.
The problem is if someone accidentally creates a file called "test" *before*
.redo/gen^test got created, then 'redo test' would do nothing, because redo
would assume it's a source file instead of a destination, according to djb's
rule.  But in this case, we know it's not, since test.do exists, so let's
build it anyway.  The problem is related to .PHONY rules in make.

This workaround is kind of cheating, because we can't safely apply that rule
if foo and default.do exist, even though default.do can be used to build
foo.

This probably won't happen very often... except with minimal/do, which
creates these empty files even when it shouldn't.  I'm not sure if I should
try to fix that or not, though.
2010-11-16 03:40:13 -08:00
Avery Pennarun
c1f09f564b Support for default.*.do rules.
I *think* this was the last missing part from djb's spec.  Certainly it's an
important one for any real project.
2010-11-16 03:04:11 -08:00
Avery Pennarun
b25e79f353 Add a --shuffle option to let you enable dependency randomization.
Previously, for testing, we were *always* randomizing the build order of
dependencies.  That's annoying since it'll make build logs differ randomly
from one run to the next, which could make comparisons harder.  However, the
feature is still useful for uncovering hidden dependencies between objects.
2010-11-16 00:28:01 -08:00
Avery Pennarun
8aea96cc90 Oops, don't use the SHELL environment variable after all.
Reading the docs for GNU make more closely, it seems they *don't* use the
one from the environment, because the user's interactive shell preferences
shouldn't affect how the Makefile runs.  Good point.

In a Makefile, you can define SHELL explicitly, and that works.  But let's
worry about that some other time.
2010-11-16 00:28:01 -08:00
Avery Pennarun
4243f31e1b Add minimal/do, a stripped-down redo implementation in 977 bytes of sh.
This could be good for distributing with your packages, so that people who
don't have redo installed can at least build it.  Also, we could use it for
building redo itself.

Will surely need to get slightly bigger as I inevitably discover I've
forgotten a critical feature.
2010-11-16 00:27:52 -08:00
Avery Pennarun
9d5afd67f0 redo.py: shuffle the list of targets.
This encourages greater randomness in builds, which both decreases lock
contention and should help with testing the consistency of parallel builds.
2010-11-13 04:42:13 -08:00
Avery Pennarun
bd5daf9754 Totally disgusting support for jobservers.
It needs some heavy rethinking and cleanup.  But it seems to work!  And it's
even compatible with GNU make, apparently!
2010-11-13 04:36:44 -08:00
Avery Pennarun
ae3b6ee363 Basic locking infrastructure.
So that more than one redo doesn't try to build the same thing at the same
time.  Kind of dumb, though, since it currently wipes out all the locks at
the toplevel, so running more than one at a time won't give accurate
results, but the -j option doesn't do anything yet.
2010-11-13 02:50:39 -08:00
Avery Pennarun
3de384497d Handle KeyboardInterrupt with less annoying spew to stderr. 2010-11-13 02:09:42 -08:00
Avery Pennarun
9c349cf652 Fix log() output so you can cut-and-paste it verbatim into a command line.
It used to say:
	redo:   t/all
	redo:     hello
and now it says:
	redo    t/all
	redo      t/hello

ie. there's no colon, and the path is intact.  That means if the build
fails, you can cut-and-paste 'redo   t/hello', add a -v, and try to debug
what went wrong.
2010-11-13 01:55:07 -08:00
Avery Pennarun
3c42645cdf Given a directory name as a target, try building dirname/all.
...if dirname/all.do exists.  This is a convenient command-line shortcut.
2010-11-13 01:45:16 -08:00
Avery Pennarun
edd8382a52 Change the default rule name from 'it' to 'all'.
This is a departure from how djb seems to have it set up, but I just like it
better.  It's more like the reasonably-common Makefile standard.  (Although
what make *actually* does is just use the first target declared in the
file.)
2010-11-13 01:40:37 -08:00
Avery Pennarun
7a8b7340a3 Use the SHELL variable instead of assuming 'sh'.
This is what GNU make does.  If SHELL isn't defined, we still fall back to
calling sh.

Rumour has it that Google has some kind of build system that can be
massively distributed if you just set SHELL to the right program; maybe
it'll work with redo now.  (Of course it won't do you any good until we
implement parallel builds...)
2010-11-13 01:30:31 -08:00
Avery Pennarun
0bd6d07155 Prettier printing of errors. 2010-11-13 01:21:59 -08:00
Avery Pennarun
89449b909c redo.py: don't add dependencies on files we rebuild.
redo-ifchange already does this, and then calls redo.py, so it's redundant.

The only weird case is if a .do file calls 'redo' instead of
'redo-ifchange'.  I'm not sure what exactly is supposed to happen here.
test.do does this, for example, and it works, but only because we always do
'redo test' and nobody depends on 'redo-ifchange test'; if they did, the
dependencies would be off, I guess.  But maybe it's meaningless to do that
anyway.
2010-11-13 01:10:29 -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
Avery Pennarun
63c596ac61 Move log stuff into a separate log.py. 2010-11-13 00:11:34 -08:00
Avery Pennarun
440af04821 Move creation of .redo directory.
This fixes "./redo clean test", since clean.do deletes .redo.
2010-11-12 23:58:39 -08:00
Avery Pennarun
903793ecd9 Colourize redo's output. 2010-11-12 23:58:32 -08:00