Commit graph

375 commits

Author SHA1 Message Date
Alan Falloon
f4b4c400b2 Handle errors on rename of target file.
[apenwarr: this is the remaining part after part of the original was
included in someone else's separate patch.]
2018-10-11 23:12:07 -04:00
Avery Pennarun
c724523473 Docs: Add missing commands to redo.md, and add redo-whichdo.md. 2018-10-11 05:56:21 -04:00
Avery Pennarun
84fb972fb7 Documentation: Fix some markdown formatting bugs. 2018-10-11 05:56:21 -04:00
Daniele Varrazzo
adbaaf38ce Use py-setproctitle to clean up ps output in redo scripts
* Change the process title with a cleaned-up version of the script
* Document the use of setproctitle in the README
2018-10-11 03:52:20 -04:00
Avery Pennarun
2affe20fb2 redo.me: missing .do in do search path description.
[Noticed by mait on github.]
2018-10-11 03:34:25 -04:00
Daniel Benamy
4c09289fb4 Fix missing blank line that breaks README.md formatting. 2018-10-11 03:30:31 -04:00
Rob Donnelly
587ad39b03 Add installation instructions 2018-10-11 03:28:54 -04:00
Avery Pennarun
0d60e4e2ec Missing state flush after checking initial file existence.
This caused an assertion in some error conditions.
2018-10-11 03:28:05 -04:00
Avery Pennarun
93d2515bc5 Missing a couple of rules in t/clean.do files. 2018-10-11 03:28:05 -04:00
Robert L. Bocchino Jr
7dd63efb37 Add cyclic dependence detection.
If a depends on b which depends on a, redo would just freeze.  Now it
aborts with a somewhat helpful error message.

[Updated by apenwarr for coding style and to add a test.]
2018-10-11 03:28:05 -04:00
Robert L. Bocchino Jr
63f9dcb640 Remove deprecated old-args feature. 2018-10-11 03:28:05 -04:00
Robert L. Bocchino Jr
99873775ba Revise file stamp in state.py
Removed information (ctime) that was causing spurious
"you modified it" warnings.

[apenwarr: This was not quite right.  ctime includes some things we
don't want to care about, such as link count, so we have to remove it.
But it also notices changes to st_uid, st_gid, and st_mode, which we do
care about, so now we have to include those explicitly.]
2018-10-11 03:28:05 -04:00
Robert L. Bocchino Jr
f739a0fc6e Fix mtime/ctime bug
[apenwarr's note: ctime includes extra inode attributes like link
count, which are not important for this check, but which could cause
spurious warnings.]
2018-10-11 03:28:05 -04:00
Mildred Ki'Lya
1f32d06c4e Fix t/130-mode: "ls -l" output is not always as expected
[tweaked by apenwarr to remove dependency on non-portable /usr/bin/stat]
2018-10-11 03:28:05 -04:00
Alan Falloon
67c1d4f7d8 We sometimes missed deps when more than one dep required a stamp check.
If must_build was nonempty when recursively calling isdirty() that
returned a list, we'd lose the original value of must_build.
2018-10-11 03:28:05 -04:00
Travis Cross
cb713bdace Restore SIGPIPE default action before exec(3)
Python chooses to ignore SIGPIPE, however most unix processes expect
to terminate on the signal.  Therefore failing to restore the default
action results in surprising behavior.  For example, we expect
`dd if=/dev/zero | head -c1` to return immediately.  However, prior to
this commit, that pipeline would hang forever.  Insidious forms of
data corruption or loss were also possible.

See:

  http://www.chiark.greenend.org.uk/ucgi/~cjwatson/blosxom/2009-07-02-python-sigpipe.html
  http://blog.nelhage.com/2010/02/a-very-subtle-bug/
2018-10-11 03:28:05 -04:00
Tommi Virtanen
c2c013970e Avoid bashism >&file
The >& form is only for file descriptors, passing a file name there is
a bash extension.

    $ /bin/dash -c 'echo foo >&/dev/null'
    /bin/dash: 1: Syntax error: Bad fd number
2018-10-11 03:28:05 -04:00
Avery Pennarun
5156feae9d Switch sqlite3 journal mode to WAL.
WAL mode does make the deadlocking on MacOS go away.  This suggests
that pysqlite3 was leaving *read* transactions open for a long time; in
old-style sqlite journals, this prevents anyone from obtaining a write
lock, although it doesn't prevent other concurrent reads.

With WAL journals, writes can happen even while readers are holding a
lock, but the journal doesn't flush until the readers have released it.
This is not a "real" fix but it's fairly harmless, since all redo
instances will exit eventually, and when they do, the WAL journal can
be flushed.
2018-10-06 05:06:42 -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
Avery Pennarun
74f968d6ca Correctly report error when target dir does not exist.
If ./default.do knows how to build x/y/z, then we will run
	./default.do x/y/z x/y/z x__y__z.redo2.tmp
which can correctly generate $3, but then we can fail to rename it to
x/y/z because x/y doesn't exist.  This would previously through an
exception.  Now it prints a helpful error message.

default.do may create x/y, in which case renaming will succeed.
2018-10-06 02:38:32 -04:00
Avery Pennarun
34669fba65 Use os.lstat() instead of os.stat().
I think this aligns better with how redo works.  Otherwise, if a.do
creates a as a symlink, then changes to the symlink's *target* will
change a's stat/stamp information without re-running a.do, which looks
to redo like you modified a by hand, which causes it to stop running
a.do altogether.

With this change, modifications to a's target are okay, but they don't
trigger any redo dependency changes.  If you want that, then a.do
should redo-ifchange on its symlink target explicitly.
2018-10-06 00:14:02 -04:00
Avery Pennarun
61d35d3972 redo-whichdo: a command that explains the .do search path for a target.
For example:

$ redo-whichdo a/b/c/.x.y

- a/b/c.x.y.do
- a/b/default.x.y.do
- a/b/default.y.do
- a/b/default.do
- a/default.x.y.do
- a/default.y.do
- a/default.do
- default.x.y.do
- default.y.do
+ default.do
1 a/b/c.x.y
2 a/b/c.x.y

Lines starting with '-' mean a potential .do file that did not exist,
so we moved onto the next choice (but consider using redo-ifcreate in
case it gets created).  '+' means the .do file we actually chose.  '1'
and '2' are the $1 and $2 to pass along to the given .do file if you want to
call it for the given target.

(The output format is a little weird to make sure it's parseable with
sh 'read x y' calls, even when filenames contain spaces or special
characters.)
2018-10-04 20:20:53 -04:00
Avery Pennarun
484ed925ad Fix bug setting MAKEFLAGS, and support --jobserver-auth
GNU make post-4.2 renamed the --jobserver-fds option to
--jobserver-auth.  For compatibility with both older and newer
versions, when we set MAKEFLAGS we set both, and when we read MAKEFLAGS
we will accept either one.

Also, when MAKEFLAGS was not already set, redo would set a MAKEFLAGS with a
leading 'None' string, which was incorrect.  It should be the empty
string instead.
2018-10-03 19:54:54 -04:00
Avery Pennarun
cb05a7bd98 Nowadays there is a "non-recursive make considered harmful" paper.
Of course there is!  Let's complete the circle by linking to it,
because it links to this project (among many others).
2018-09-18 13:23:57 -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
ede182cb84 Add a test for install.do. 2012-02-09 00:42:41 -05:00
Avery Pennarun
a9ebabd6b7 Add a test for --keep-going option. 2012-02-09 00:42:41 -05:00
Avery Pennarun
9f6447e2cb Add a test for --shuffle option. 2012-02-09 00:42:41 -05:00
Avery Pennarun
34ce233f5e Rename 111-compile to 111-compile2.
Not a great name, but make it obvious that this is a slightly different test
from 110-compile.
2012-02-09 00:42:40 -05:00
Avery Pennarun
1f304f4d1d t/100-args: add a test for --old-args feature. 2012-02-09 00:42:40 -05:00
Avery Pennarun
a8bec74449 t/350-deps: 'redo clean' was crashing. 2012-02-08 22:56:04 -05:00
Avery Pennarun
c38e2bee92 t/201-fail: add a simple test for non-existent source files.
(This actually went uncaught in my redo rewrite.  Oops.)
2012-02-08 22:51:04 -05:00
Avery Pennarun
7822f5a5bb t/*: rearrange tests into numbered directories.
It was getting way too ad-hoc in there.  Let's reorganize the tests so that
there's a good, obvious, suggested sequence to run them in.
2012-02-08 01:56:50 -05:00
Avery Pennarun
116c279e96 t/*: update some tests from my rewrite branch.
Just some minor test fixes so that tests pass on both current redo and the
upcoming rewritten one.
2012-02-08 01:56:43 -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
0670f78b96 md-to-man.do: suggest how to install markdown/BeautifulSoup
...since they aren't included by default on MacOS X, but easy_install can
easily get them for you.
2011-12-31 02:49:39 -05:00
Avery Pennarun
75c3a0a46b Import latest options.py from bup. 2011-12-31 02:49:39 -05:00
Avery Pennarun
20951f9e6e t/pytest.do: don't run in minimal/do.
And add a reminder to test.do to run 'minimal/do test'.
2011-12-31 02:49:39 -05:00
Avery Pennarun
656c3c583c Docs: recommend adding redo-ifchange with a lot of targets at a time.
Some people don't know to do this, and their scripts are unnecessarily slow
because of it.
2011-05-08 04:25:51 -04:00
Avery Pennarun
2fa8aab191 redo-sh: reverse a case that caused 'set -e' to abort on zsh.
Correctly, I might add.  It's too bad none of my other shells did it.  Sigh.
2011-05-08 01:25:26 -04:00
Avery Pennarun
c6020cf1cd t/shelltest.od: quiet some error messages that get printed during testing.
If the error message only triggered a shelltest warning instead of a
failure, then they're harmless, so we might as well silence them when
running 'redo test' (which runs t/shelltest.do, which enables
SHELLTEST_QUIET).  We still want to print them when actually testing out
shelltest.od, though, to help with debugging the script.
2011-05-08 01:25:20 -04:00
Avery Pennarun
4e285607f0 Don't use "insert ... default values" in sqlite3.
It isn't supported in older sqlite3 versions.  Let's just do something
equivalent instead.
2011-05-07 23:47:03 -04:00
Avery Pennarun
b993e449f8 shelltest: use a more magical magic number for success.
There may be some odd situation where a shell returns 0 despite not executing
the script correctly; now 0 is an error condition.
2011-04-17 23:39:53 -04:00
Avery Pennarun
e9e24bb450 t/shelltest.od: another test for ${x#y} behaviour.
If y contains a * character, it's a case-esac style wildcard unless it's in
"" or '', which tells it to match a literal *.  But in dash/busybox, the ''
quoting doesn't actually work, only "" does.

Since there's a workaround - just always use "" quoting - it's not that
fatal.  If the "" quoting doesn't work, then we'll make it fail.
2011-04-02 16:30:14 -07:00
Avery Pennarun
03763177ff shelltest.od: a few more/better tests and clarification comments. 2011-04-02 15:41:52 -07:00
Avery Pennarun
3b940696c1 redo-sh.do: prettier log messages.
Make it easier to see which shells fail/warn about what.
2011-04-02 15:33:13 -07:00
Avery Pennarun
92c3e7c5af Test for previous override fix. 2011-03-30 23:35:20 -04:00
Avery Pennarun
0a5f424ef8 User-overridden targets stay overridden even if the last build failed.
Previously, if 'redo-ifchange foo' failed last time, then creating foo
manually wouldn't help; 'redo-ifchange foo' would still try to rebuild it.
But if the first run *did* create it, then manually overriding it *did*
work.

That inconsistency is pointless.  If the user creates it by hand, it doesn't
matter if it failed to build last time or not; the user wants it overridden.
So this way, something that can't build can at least be manually created as
a hack.
2011-03-30 23:35:20 -04:00
Avery Pennarun
fb20652d04 Test for precenting state.relpath fix. 2011-03-27 15:25:11 -04:00