Commit graph

143 commits

Author SHA1 Message Date
Avery Pennarun
1f64cc4525 shelltest.od: add more "set -e" tests and add a 'skip' return code.
Based on the earlier t/000-set-minus-e bug in minimal/do on some
shells, let's add some extra tests that reveal the weirdness on those
shells.  Unfortunately because they are so popular (including bash and
zsh), we can't reject them outright for failing this one.

While we're here, add a new return code, "skip", which notes that a
test has failed but is not important enough to be considered a warning
or failure.  Previously we just had these commented out, which is not
quite obvious enough.

...and I updated a few comments while reviewing some of the older
tests.
2018-12-17 16:17:37 +00:00
Avery Pennarun
6cf06f707a shelltest.od: we accidentally treated some fails as mere warnings.
We were setting a global variable FAIL on failure, but if we failed
inside a subshell (which a very small number of tests might do), this
setting would be lost.  The script output (a series of failed/warning
lines) was still valid, but not the return code, so the shell might be
selected even if one of these tests failed.

To avoid the problem, put the fail/warning state in the filesystem
instead, which is shared across subshells.
2018-12-17 16:17:37 +00:00
Avery Pennarun
39e017869d Ensure correct operation with read-only target dirs and .do file dirs.
Although I expect this is rather rare, some people may want to build in
a read-write subdir of a read-only tree.  Other than some confusing
error reporting, this works fine in redo after the recent changes to
temp file handling, but let's add a test to make sure it stays that
way.  The test found a bug in minimal/do, so let's fix that.

Reported-by: Jeff Stearns <jeff.stearns@gmail.com>
2018-12-13 13:28:44 +00:00
Avery Pennarun
d95277d121 Use mkstemp() to create the stdout temp file, and simplify $3 path.
Previously, we'd try to put the stdout temp file in the same dir as the
target, if that dir exists.  Otherwise we'd walk up the directory tree
looking for a good place.  But this would go wrong if the directory we
chose got *deleted* during the run of the .do file.

Instead, we switch to an entirely new design: we use mkstemp() to
generate a temp file in the standard temp file location (probably
/tmp), then open it and immediately delete it, so the .do file can't
cause any unexpected behaviour.  After the .do file exits, we use our
still-open fd to the stdout file to read the content back out.

In the old implementation, we also put the $3 in the "adjusted"
location that depended whether the target dir already existed, just for
consistency.  But that was never necessary: we didn't create the $3
file, and if the .do script wants to write to $3, it should create the
target dir first anyway.  So change it to *always* use a $3 temp
filename in the target dir, which is much simpler and so has fewer edge
cases.

Add t/202-del/deltest4 with some tests for all these edge cases.

Reported-by: Jeff Stearns <jeff.stearns@gmail.com>
2018-12-13 13:28:44 +00:00
Avery Pennarun
1f79bf1174 Detect when a .do script deletes its stdout tmp file.
This can happen if we create the .tmp file in the same directory as the
target, and the .do file first does "rm -rf" on that directory, then
re-creates it.  The result is that the stdout file is lost.

We'll make this a warning if the .do script *didn't* write to stdout
(so the loss is harmless, just weird), and an error if they *did* write
to stdout, which we can detect because we still have an open fd on the
file, so we can fstat() it.
2018-12-12 03:45:33 +00:00
Avery Pennarun
474e12eed8 Fix minimal/do and tests when built in a path containing spaces.
Basically all just missing quotes around shell strings that use $PWD.
Most paths inside a project, since redo uses relative paths, only need
to worry when project-internal directories or filenames have spaces in
them.

Reported-by: Jeff Stearns <jeff.stearns@gmail.com>
2018-12-11 01:22:29 +00:00
Avery Pennarun
99188bef0d Rename redo/python -> redo/py.
This avoids a name overlap with the system-installed copy of python.
Since redo adds the redo/ dir to the $PATH before running .do files,
python.do might see its own previously-created target instead of the
"real" python when testing, and create an infinite loop by accident.
2018-12-05 02:27:04 -05:00
Avery Pennarun
f6fe00db5c Directory reorg: move code into redo/, generate binaries in bin/.
It's time to start preparing for a version of redo that doesn't work
unless we build it first (because it will rely on C modules, and
eventually be rewritten in C altogether).

To get rolling, remove the old-style symlinks to the main programs, and
rename those programs from redo-*.py to redo/cmd_*.py.  We'll also move
all library functions into the redo/ dir, which is a more python-style
naming convention.

Previously, install.do was generating wrappers for installing in
/usr/bin, which extend sys.path and then import+run the right file.
This made "installed" redo work quite differently from running redo
inside its source tree.  Instead, let's always generate the wrappers in
bin/, and not make anything executable except those wrappers.

Since we're generating wrappers anyway, let's actually auto-detect the
right version of python for the running system; distros can't seem to
agree on what to call their python2 binaries (sigh). We'll fill in the
right #! shebang lines.  Since we're doing that, we can stop using
/usr/bin/env, which will a) make things slightly faster, and b) let us
use "python -S", which tells python not to load a bunch of extra crap
we're not using, thus improving startup times.

Annoyingly, we now have to build redo using minimal/do, then run the
tests using bin/redo.  To make this less annoying, we add a toplevel
./do script that knows the right steps, and a Makefile (whee!) for
people who are used to typing 'make' and 'make test' and 'make clean'.
2018-12-04 02:53:40 -05:00
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
5abf78059f t/351-deps-forget: forgot skip-if-minimal-do.
minimal/do doesn't really understand dependencies at all, to say
nothing of forgetting targets and converting them to sources.
2018-12-04 02:43:58 -05:00
Avery Pennarun
07163d81cf shelltest.od: detect some weird zsh problems.
This seems to only affect old zsh on MacOS.  But we want to catch it
anyway, because it caused t/351-deps-forget to fail in a weird way on
that version of zsh.

Shells really suck.
2018-12-04 02:43:58 -05:00
Avery Pennarun
2b0d34f0ed More fixes for converting missing targets -> sources.
I attempted to fix this in commit c06d1fba40, but it was apparently
incomplete and not all cases were covered by tests.

Let's add a much more thorough test by going through every possible
combination and making sure redo-{sources,targets,ood} all work as
expected, that the "you modified it" warning does or does not show up
when expected, and that dependencies are rebuilt the number of times we
expect.
2018-12-02 19:39:29 -05:00
Avery Pennarun
c06d1fba40 {ood,sources,targets}: fix relative paths; turn missing targets into sources.
When we check dependencies and a previously-is_generated dependency
existed before, but no longer does, forget that it was is_generated.
This slightly improves the situation where as a project evolves, a file
that used to be a target gets removed, and then later is re-added as a
static source file.  (It doesn't fix the other variant, where a file is
changed from target to source in a single atomic change, and is never
missing.  That one will be trickier to handle.)

While adding a test for this behaviour, I discovered that redo-sources,
redo-targets, and redo-ood were reporting their output relative to
STARTDIR instead of relative to $PWD, so fix that too.
2018-11-23 19:18:43 -05:00
Avery Pennarun
5596b9fae3 Better comment in t/flush-cache, and a avoid a (rare) unit test error.
flush-cache reduces the failed_runid by 1 each time, and it runs
multiple times per 'redo test'.  if failed_runid goes to zero, it would
be treated as success ("no failure") rather than a real failure at
runid 0.
2018-11-21 21:00:36 -05:00
Avery Pennarun
672b748394 Further improve handling of symlink targets/deps.
In commit redo-0.11-4-g34669fb, we changed os.stat into os.lstat to
avoid false positives in the "manual override" detector: a .do file
that generates $3 as a symlink would trigger manual override if the
*target* of that symlink ever changed, which is incorrect.

Unfortunately using os.lstat() leads to a different problem: if X
depends on Y and Y is a symlink to Z, then X would not be rebuilt when
Z changes, which is clearly wrong.

The fix is twofold:

1. read_stamp() should change on changes to both the link itself,
   *and* the target of the link.

2. We shouldn't mark a target as overridden under so many situations.
   We'll use *only* the primary mtime of the os.lstat(), not all the
   other bits in the stamp.

Step 2 fixes a few other false positives also.  For example, if you
'cp -a' a whole tree to another location, the st_ino of all the targets
will change, which would trigger a mass of "manual override" warnings.
Although a change in inode is sufficient to count an input as having
changed (just to be extra safe), it should *not* be considered a manual
override.  Now we can distinguish between the two.

Because the stamp format has changed, update the SCHEMA_VER field.  I
should have done this every other time I changed the stamp format, but
I forgot.  Sorry.  That leads to spurious "manually modified" warnings
after upgrading redo.
2018-11-21 16:28:14 -05:00
Avery Pennarun
4842996b5b Merge branch 'redo-log'
* redo-log:
  redo-log: add man page.
  redo-log: add automated tests, and fix some path bugs revealed by them.
  redo-log: fix stdout vs stderr; don't recapture if .do script redirects stderr.
  redo-log: don't show status line until >1.0 seconds after starting.
  Add --color and --no-color options.
  redo-log: --debug-pids works properly again.
  Split --raw-logs into --no-pretty and --no-log options.
  redo-log: prioritize the "foreground" process.
  redo-log: correctly indent first level of recursion.
  Raw logs contain @@REDO lines instead of formatted data.
  redo-log: status line should use actual terminal width.
  redo-log: capture and linearize the output of redo builds.
  Use signal.setitimer instead of signal.alarm.
2018-11-19 19:33:04 -05:00
Avery Pennarun
4edb6f78e0 redo-log: add automated tests, and fix some path bugs revealed by them.
When a log for X was saying it wanted to refer to Y, we used a relative
path, but it was sometimes relative to the wrong starting location, so
redo-log couldn't find it later.

Two examples:

 - if default.o.do is handling builds for a/b/x.o, and default.o.do
   does 'redo a/b/x.h', the log for x.o should refer to ./x.h, not
   a/b/x.h.

 - if foo.do is handling builds for foo, and it does
   "cd a/b && redo x", the log for foo should refer to a/b/x, not just
   x.
2018-11-19 18:58:36 -05:00
Avery Pennarun
02220d4318 t/110-compile and t/111-example: skip if no C compiler installed.
It's nice to validate "real" use with a C compiler, but silly to
completely fail validation just because a C compiler is missing.
2018-11-19 15:46:22 -05:00
Seamus Connor
190b4c34ff Replaced all instances of 'python' with 'python2'
On systems where 'python' refers to python3, redo
failed to launch. All invocations of python have been
made explicitly python2 invocations. All tests pass
on an Arch Linux system as of this commit.
2018-11-14 10:52:09 -08:00
Alexey Shamrin
59eb7e8f1e add link to projects using redo; fix t/example mention (#20)
also rename t/111-compile2 to t/111-example
2018-11-07 00:54:57 -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
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
e40dc5bad2 redo-whichdo: fix a bug where the last dir was checked twice, and add tests.
When we can't find a .do file, we walk all the way back to the root
directory.  When that happens, the root directory is actually searched
twice.  This is harmless (since a .do file doesn't exist there anyway)
but causes redo-whichdo to produce the wrong output.

Also, add a test, which I forgot to do when writing whichdo in the
first place.

To make the test work from the root directory, we need a way to
initialize redo without actually creating a .redo directory.  Add a
init_no_state() function for that purpose, and split the necessary path
functions into their own module so we can avoid importing builder.py.
2018-11-02 02:20:52 -04:00
Avery Pennarun
f4f9ed97ec t/clean.do: don't forget to run s??/clean. 2018-11-02 02:20:52 -04:00
Avery Pennarun
eb004d531e shelltest: downgrade #48 to a warning.
This is the test that
   x=y f
does *not* unset x after running f, if f is a shell function.  Apparently
that's the right thing to do, but freebsd dash 0.5.10.2 fails it.  This is
surprising because debian dash 0.5.8-2.4 passes, and it is presumably older.
Downgrade this to a warning because we want freebsd to have some cheap sh
variant that passes with redo, and nobody should be *relying* on this
insane behaviour anyway.

freebsd 11.2 sh (but not freebsd dash) fails test #24.  That one seems
rather serious, so I don't want to downgrade it to a warning.
2018-10-29 07:35:56 +00:00
Avery Pennarun
6c81b110be Tests: use cc instead of gcc.
This fixes problems where llvm is installed without a 'gcc' alias.
2018-10-29 07:20:33 +00: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
887df98ead builder.py: refresh the File object after obtaining the lock.
We need to create the File object to get its f.id, then lock that id.
During that gap, another instance of redo may have modified the file or
its state data, so we have to refresh it.

This fixes 'redo -j10 t/stress'.
2018-10-13 01:37:08 -04:00
Avery Pennarun
999ba4fb13 t/stress: add a test that usually triggers a bug using 950-curse.
It looks like we're updating the stamp for t/countall while another
task is replacing the file, which suggests a race condition in our
state management database.
2018-10-12 05:48:56 -04:00
Avery Pennarun
aa423a723f t/660-stamp: don't run at the same time as other tests in redo -j.
flush-cache can cause files affected by redo-stamp to get rebuilt
unnecessarily, which the test is specifically trying to validate.
Since other tests run flush-cache at random times when using -j, this
would cause random test failures.
2018-10-12 05:20:27 -04:00
Avery Pennarun
728a19cd52 t/*: some cleanups so switching between redo and minimal/do works.
Because the two programs use separate state databases, it helps if we
clean up some temp files between runs.  Otherwise they might think you
created some targets "by hand" and refuse to rebuild them.
2018-10-12 05:20:27 -04:00
Avery Pennarun
637521070b t/all.do: use redo instead of redo-ifchange.
I'm not quite sure what I was thinking, using redo-ifchange there, but
the result was that some tests wouldn't run if you run 'redo test'
repeatedly, even after modifying redo itself.

Also tweaked t/950-curse so that it always runs, not just the first
time.
2018-10-12 05:19:43 -04:00
Avery Pennarun
0d174f92c3 redo-sh: downgrade failures that affected dash; add a bash warning.
I feel a little dirty doing this, but the way the code was before, redo
almost always picked bash as the shell.  bash is way too overpowered
and this led to bashisms in do scripts unnecessarily.  The two failures
in dash are things that I would really like to have, but they haven't
materialized after 6 years, so I guess we should be realistic.

To appropriately penalize bash for asking for trouble, I added a
warning about [ 1 == 1 ] syntax being valid (as opposed to the POSIX
correct [ 1 = 1 ]).  This allows dash to be selected ahead of bash.

I also moved 'sh' to the end of the list, because although it's the
weakest shell on some systems, on other systems it's just bash.  And I
put zsh in front of bash, because fewer people have zsh and we want
them to test zsh.
2018-10-12 05:18:25 -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
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
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
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
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