Commit graph

42 commits

Author SHA1 Message Date
Avery Pennarun
df44dc54a2 jwack: _cheatfds error when run from toplevel make -j.
Also added a new unit test to confirm that 'make' behaviour works as
expected, with and without parallelism.
2018-12-04 02:43:58 -05:00
Avery Pennarun
2023d36676 minimal/do: didn't work correctly with multi-level auto dir creation.
If we tried to build target a/b/c/d and a/b/c didn't exist yet, we
would correctly name the temp file something like a__b/c__d.tmp.  But
if a/b didn't exist yet, we named the temp file a/b__c/d.tmp, which
didn't work.  Instead, name it a/b__c__d.tmp as expected.
2018-11-02 04:27:28 -04:00
Avery Pennarun
ec72beb343 minimal/do: don't create a .did file until after a file is actually built.
With the new "continue" feature on by default, it turned out that
ctrl-c during a build, or a .do file returning an error, would mark a
target as "built" even though it hadn't been.  This would prevent
retrying it when you started minimal/do again.  Use a temp file
instead.

It's a little tricky: to prevent accidental recursion, we want to
create a file *before* building, but clean up that file when starting
the next session.  And we rename that file to the actual .did file
*after* building successfully.
2018-11-02 04:25:35 -04:00
Avery Pennarun
25d24d117f minimal/do: less aggressive 'all' default; add fake redo-{sources,targets,ood}.
If redo-ifchange is a symlink to minimal/do, and we run it from
*outside* an existing session, it shouldn't default to 'all'.

redo-sources, redo-targets, and redo-ood aren't too useful with
minimal/do, but they should exist in case someone tries to use them, so
just symlink them to /bin/true, like we do with redo-ifcreate.
2018-11-02 03:48:09 -04:00
Avery Pennarun
a14aa4c86d minimal/do whichdo: should print ../default.do if ../$1.do exists.
It would be incorrect to print ../$1.do (we only use $1.do in the
*current* directly, not prefix dirs; we only use default*.do in
those).  However, when we found ../default.do, we forgot to print it,
because of a silly logic error.
2018-11-02 03:13:45 -04:00
Avery Pennarun
7b8fda5e18 minimal/do: add redo-whichdo support and internal unit tests.
Adding redo-whichdo wasn't so hard, except that it exposed a bunch of
mistakes in the way minimal/do was choosing .do files.  Most of the
wrong names it tried didn't matter (since they're very unlikely to
exist) except that they produce the wrong redo-whichdo output.

Debugging that took so much effort that I added unit tests for some
functions to make it easier to find problems in the future.

Note: this change apparently makes minimal/do about 50% slower than
before, because the _find_dofiles algorithm got less optimized (but
more readable).  It's still not very slow, and anyway, since it's
minimal/do, I figured readable/correct code probably outweighed a bit
of speed.  (Although if anyone can come up with an algorithm that's
clear *and* works better, I won't turn it down :)  I feel like I must
be doing it the hard way...)
2018-11-02 02:20:52 -04:00
Avery Pennarun
b0a6bd79f9 minimal/do: invert the sense of the -c option.
After playing with "continuable" mode for a while, it seems to me that
what most people want will be incremental builds by default (albeit
without any dependency checking to rebuild a target if sources change).
This lets you run minimal/do several times in a row to incrementally
build up your project while you're playing around.  If you want to
start over, use -c.

As a result, in test.do we now recommend using 'minimal/do -c test'
since minimal/do now strays even further from proper redo semantics
otherwise.

While we're here, update the usage message to describe what all the new
options mean.
2018-11-02 02:20:52 -04:00
Avery Pennarun
0fc2e46708 minimal/do: add support for -x -v -d -c options.
-x, -v, and -d are the same as redo.

-c means "continuable", which disables the feature that deletes (and
forgets) all targets at the start of each run.  This is a little risky,
since minimal/do still doesn't understand dependencies, but it allows
you to run minimal/do several times in succession, so that

    minimal/do -c a
    minimal/do -c b
is the same as
    minimal/do a b
2018-10-17 02:57:33 -04:00
Avery Pennarun
f345eae290 minimal/do: redo vs redo-ifchange, and fix empty target handling.
We previously assumed that redo and redo-ifchange are the same in
minimal/do's design, because it rebuilds all targets on every run, and
so there's no reason to ever build the same target more than once.

Unfortunately that's incorrect: if you run 'redo x' from two points in
a single run (or even twice in the same .do file), we expect x to be
built twice.  If you wanted redo to decide whether to build it the
second time, you should have used redo-ifchange.

t/102-empty/touchtest was trying to test for this.  However, a
second bug in minimal/do made the test pass anyway.  minimal/do would
*always* rebuild any target x that produced no output, not caring
whether it had tried to build before, whether you used redo or
redo-ifchange.  And while we tested that redo would redo a file that
had been deleted, we didn't ensure that it would redo a file that was
*not* deleted, nor that redo-ifchange would *not* redo that file.

Fix both bugs in minimal/do, and make t/102-empty/touchtest cover the
missing cases.
2018-10-17 01:54:29 -04:00
Avery Pennarun
a3077a4a4d minimal/do: fix failure with paths containing spaces.
We grew a test for these at some point, but minimal/do didn't actually
pass it.

sh syntax oddity: if you say
    x=$1 y=$2
then it works fine when $1 and $2 contain spaces.  But if you say
    export x=$1 y=$2
(or "local" instead of "export") then $1 and $2 will be split on IFS,
and it won't do what you think.  I guess this is because 'export' and
'local' are like commands, and command arguments are split if not
quoted.
2018-10-12 05:18:44 -04:00
Avery Pennarun
33dadbfe07 minimal/do: some shells return error in "read x <file" for empty files.
...or files that contain bytes but not a trailing newline.  It's okay if we
don't get any data, but we definitely have to *not* let "set -e" abort us.
Now that we fixed set -e in the previous patch, it revealed this problem.
2012-02-09 00:42:41 -05:00
Avery Pennarun
c28181e26f minimal/do: fix a really scary bugs in "set -e" behaviour.
If you run something like

  blah_function || return 1

then everything even *inside* blah_function is *not* subject to the "set -e"
that would otherwise be in effect.  That's true even for ". subfile" inside
blah_function - which is exactly how minimal/do runs .do files.

Instead, rewrite it as

  blah_function
  [ "$?" = "0" ] || return 1

And add a bit to the unit tests to ensure that "set -e" behaviour is enabled
in .do files as we expect, and crash loudly otherwise.

(This weird behaviour may only happen in some shells and not others.)

Also, we had a "helpful" alias of redo() defined at the bottom of the file.
Combined with the way we use '.' to source the .do files, this would make it
not start a new shell just to run a recursive 'redo' command.  It almost
works, but this stupid "set -e" bug could cause a nested .do file to not
honour "set -e" if someone ran "redo foo || exit 1" from inside a .do
script.  The performance optimization is clearly not worth it here, so
rename it to _redo(); that causes it to actually re-exec the redo program
(which is a symlink to minimal/do).
2012-02-09 00:42:41 -05:00
Avery Pennarun
21f88094d5 Change definitions of $1,$2,$3 to match djb's redo.
If you use "redo --old-args", it will switch back to the old
(apenwarr-style) arguments for now, to give you time to update your .do
scripts.  This option will go away eventually.

Note: minimal/do doesn't understand the --old-args option.  If you're using
minimal/do in your project, keep using the old one until you update your use
of $1/$2, and then update to the new one.

apenwarr-style default.o.do:
   $1      foo
   $2      .o
   $3      whatever.tmp

djb-style default.o.do:
   $1      foo.o
   $2      foo
   $3      whatever.tmp

apenwarr-style foo.o.do:
   $1      foo.o
   $2      ""
   $3      whatever.tmp

djb-style foo.o.do:
   $1      foo.o
   $2      foo.o  (I think?)
   $3      whatever.tmp
2011-12-31 02:49:39 -05:00
Avery Pennarun
2efbbc26b9 Don't crash on targets in directories that don't exist yet.
The reason we'd crash is that we tried to pre-create a file called
$target.redo.tmp, which wouldn't work because the directory containing
$target didn't exist.

We now try to generate a smarter filename by using the innermost directory
of target that *does* exist.  It's a little messy, but the idea is to make
sure we won't have to rename() across a filesystem boundary if, for example,
there's a mounted filesystem in the middle of the hierarchy somewhere.
2011-03-22 23:00:34 -07:00
Avery Pennarun
989eb6804b minimal/do: fix a typo: DO_BUILD -> DO_BUILT
...and remove the "disable-if-minimal-do" from the test that would have
caught this bug.

Reported by Ulrik Sverdrup.
2011-03-06 21:38:34 -08:00
Avery Pennarun
0e037b8c45 minimal/do: leak fewer variables, especially PREFIX.
Since we use ". filename.do" to run the .do files instead of just
"filename.do", shell local variables end up being inherited by the
subprogram.  Change all the local variables to be all lowercase, to avoid
conflicting with any typical environment variables someone might use.

The particular variable that triggered this was PREFIX (reported by "ulrik"
on the mailing list) and that fixes this, at least.

Arguably we shouldn't be using ".", but using it avoids unnecessary forks,
which is kind of nice.
2011-03-05 19:03:34 -08:00
Avery Pennarun
c1a1f32445 MacOS: "-e filename/." returns true even for non-directories.
This has something to do with resource forks.  So use "-d filename/."
instead, which returns false if filename is not a directory.
2011-03-05 19:03:30 -08:00
Avery Pennarun
1ed168e79e minimal/do: work around a bug with empty .do files.
If you ". ./filename" and ./filename contains no commands, apparently
ash/dash will give the exit code of the command *before* the ., rather than
defaulting to zero as it supposedly should.  This should work around it in
our .do files at least.

Reported by Tim Allen.
2011-02-28 21:13:55 -08:00
Avery Pennarun
cfc3f44d64 minimal/do: 'redo-ifchange' with no parameters shouldn't try to build all.
It should just build nothing.  Because sometimes you want to do something
like:
	redo-ifchange $(find -name '*.c')

And the find doesn't return any results.  This is consistent with what real
redo does.

Added a test to confirm that it works.
2011-02-26 18:01:31 -08:00
Avery Pennarun
304e88022a minimal-do: deal with 'clean.do' operations better.
Sometimes clean.do implementations want to delete our .do_built file and
directory.  If that happens, deal with it quietly, as long as they don't
request any *additional* redo-type operations.
2011-01-28 21:10:04 -08:00
Avery Pennarun
c7f06448c5 minimal/do: support searching parent dirs for .do files.
Now all tests pass again with both redo and minimal/do.
2011-01-15 21:45:25 -08:00
Avery Pennarun
f6ea1fd76b log.py, minimal/do: don't use ansi colour codes if $TERM is blank or 'dumb'
Apparently emacs sets TERM=dumb in its tty simulator, so even though
isatty() returns true, we shouldn't use colour codes.  (emacs is therefore
lame. But we knew that.)
2011-01-04 14:11:29 -08:00
Tim Allen
cb1512b14b Use named constants for terminal control codes.
(apenwarr slightly changed the minimal/do tty detection.)
2011-01-04 14:10:20 -08:00
Avery Pennarun
f641e52e3b Handle .do files that start with "#!/" to specify an explicit interpreter.
Now you can have your .do files interpreted by whatever interpreter you
want.
2011-01-01 22:10:14 -08:00
Avery Pennarun
f24d4f142b minimal/do: don't print an error on exit if we don't build anything. 2011-01-01 22:05:05 -08:00
Avery Pennarun
7142c342ae minimal/do: faster deletion of stamp files.
"while/read/printf | xargs -0" is much faster than while/read/rm, because it
doesn't fork so many times.
2011-01-01 04:15:12 -08:00
Avery Pennarun
8aa27d050b minimal/do: delete .tmp files if a build fails. 2011-01-01 04:14:41 -08:00
Avery Pennarun
fb5275938d minimal/do: use ".did" stamp files instead of empty target files.
If all.do runs and creates no output, we shouldn't create a file called
'all', but we should remember that 'all' has been run successfully.  We do
this by creating 'all.did' during the build.

Since minimal/do always just wipes everything out every time it runs, we can
safely remove the .did files after minimal/do terminates, so this doesn't
clutter things too much in normal use.

This fixes some edge cases, particularly that 'minimal/do clean' no longer
leaves stupid files named "clean" lying around, and the redo-sh directory
can now be rebuilt correctly since we rebuild it as long as redo-sh.did
doesn't exist.  (We don't want to "rm -rf redo-sh" because it makes me
nervous.)
2011-01-01 04:11:20 -08:00
Avery Pennarun
41ef15fde2 minimal/do: use posix shell features instead of dirname/basename.
This avoids a few forks, and is a good example of how to do some "modern" sh
programming.  Plus we now use fewer lines of code.
2011-01-01 04:10:47 -08:00
Avery Pennarun
c13eac953e Release minimal/do to the public domain.
This makes it more convenient if you really want to include it as the build
script for your own projects.
2010-12-14 17:58:16 -08:00
Avery Pennarun
3dd8d081be minimal/do: MacOS has /usr/bin/true, not /bin/true. 2010-12-14 02:47:51 -08:00
Avery Pennarun
80fedc84fe minimal/do: make redo-ifchange (etc) into subprograms in a temp dir.
Using aliases for them was cute, but it didn't work with things like:

	find -name '*.c' | xargs redo-ifchange

since xargs doesn't know about aliases.
2010-12-11 21:47:55 -08:00
Avery Pennarun
b9987433c9 Disable the tests that don't work with minimal/do.
...only when running under minimal/do, of course.

The tests in question mostly fail because they're testing particular
dependency-related behaviour, and minimal/do doesn't support dependencies,
so naturally it doesn't work.
2010-12-11 21:06:12 -08:00
Avery Pennarun
a75555e7a8 minimal/do: don't completely abort if a sub-redo fails.
Just allow that sub-redo to return an error code.  Also, parent redos should
return error code 1, not the same code as the child.  That makes it easier
to figure out which file generated the "special" error code.
2010-12-11 20:37:27 -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
81cbe49938 minimal/do: write my own replacements for dirname and basename.
This greatly reduces the number of fork+exec calls, so in particular,
t/curse/all.do now runs much faster:

   /bin/sh (bash): was 5.9s, now 2.2s
   /bin/dash: was 3.2s, now 1.1s

Obviously improving the speed of minimal/do doesn't really matter, except
that it makes a good benchmark to compare the "real" redo against.  So far
it's losing badly: 5.4s.
2010-11-21 00:19:31 -08:00
Avery Pennarun
b9853d3858 minimal/do: handle nonzero exit codes and set $1/$2 correctly.
Also add some tests to confirm this.
2010-11-17 19:07:27 -08:00
Avery Pennarun
c7585558ef If the .do script deletes $3, don't die. 2010-11-17 17:55:16 -08:00
Avery Pennarun
41afb96f25 minimal/do: pretty up the output.
We're up to 1315 bytes now, though.  Lame.
2010-11-16 03:28:44 -08:00
Avery Pennarun
4b8c929cdc minimal/do: add support for default.* targets.
Unit tests now pass again with 'minimal/do test'.
2010-11-16 03:20:52 -08:00
Avery Pennarun
ac36dcf136 minimal/do: given a directory name, build dirname/all
Like redo does.
2010-11-16 03:11:28 -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