Commit graph

435 commits

Author SHA1 Message Date
Avery Pennarun
cf274842f4 shelltest: wrap some tests in 'eval' so they don't abort in posh.
posh will abort the entire script if it detects a syntax error.  I
don't know if that's good or not, but you shouldn't be writing scripts
with syntax errors, so that by itself isn't a good reason for posh to
fail.

It still fails some actual tests, but at least now we don't consider it
a 'crash' outcome.
2018-12-20 08:55:14 +00:00
Avery Pennarun
d7a057ed29 shelltest: add reference URLs for some "set -e" behaviour. 2018-12-20 04:46:10 +00:00
Avery Pennarun
174a093dc5 Don't set_checked() on is_override files.
If a file is overridden and then overridden again, this caused us to
rebuild only the first thing that depends on it, but not any subsequent
things, which is a pretty serious bug.

It turned out that t/350-deps-forget is already supposed to test this,
but I had cleverly encoded the wrong behaviour into the expected
results in the table-driven test.  I blame lack of sleep.  Anyway, I
fixed the test, which made it fail, and then fixed the code, which made
it pass.
2018-12-18 13:01:40 +00:00
Avery Pennarun
686c381109 Fix more inconsistent behaviour with symlinks in paths.
Both redo and minimal/do were doing slightly weird things with
symlinked directories, especially when combined with "..".  For
example, if x is a link to ., then x/x/x/x/../y should resolve to
"../y", which is quite non-obvious.

Added some tests to make sure this stays fixed.
2018-12-17 16:17:37 +00:00
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
761b77333e redo/sh.do: include the 'lksh' variant of mksh.
This one attempts to be a much closer match to POSIX, and seems to
succeed, giving only warning W118.
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
9aa8061e83 minimal/do: fix a bug when $PWD != $(/bin/pwd).
This can happen when $PWD contains a symlink somewhere in the path.  In
that case, "cd ..; cat x" could mean something different from "cat ../x".

Notably, this error occurs when running "./do test" if your build
directory is through a symlink.  For example, on freebsd your home
directory is /home/$USER, but /home is a symlink to /usr/home, which
triggers this problem.

Not adding tests in this commit, because when I added some tests, I
found even more symlink-related bugs, but those ones are much more
unlikely to occur.  The additional fixes+tests are in a later commit.
2018-12-17 16:14:08 +00:00
Avery Pennarun
54d8399718 minimal/do: fix t/000-set-minus-e on some shells.
Running commands in "||" context (like "x || return") disables "set -e"
behaviour in that context, even several levels deep in the call
hierarchy.  The exact behaviour varies between shells, but this caused
a test failure with at least zsh 5.3.1 on debian.
2018-12-17 16:13:39 +00:00
Avery Pennarun
29f939013e Add a bunch of missing python docstrings.
This appeases pylint, so un-disable its docstring warning.
2018-12-14 09:03:53 +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
2b4fe812e2 Some renaming and comments to try to clarify builder and jobserver.
The code is still a bit spaghetti-like, especialy when it comes to
redo-unlocked, but at least the new names are slightly more
comprehensible.
2018-12-11 04:17:27 +00:00
Avery Pennarun
4d2b4cfccb Make calls to logs.setup() explicit in each cmd.
Further reducing magic implicit behaviour to make code easier to
follow.
2018-12-11 02:35:11 +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
539a26d264 Minor copyediting of index.md. 2018-12-10 05:03:20 +00:00
Avery Pennarun
2b7da63c66 Fix a few lagging doc references to old-style build+test layout. 2018-12-10 04:33:57 +00:00
Avery Pennarun
bd8dbfb487 Switch to module-relative import syntax.
Now that the python scripts are all in a "redo" python module, we can
use the "new style" (ahem) package-relative imports.  This appeases
pylint, plus avoids confusion in case more than one package has
similarly-named modules.
2018-12-05 02:34:36 -05:00
Avery Pennarun
0b648521fd Move setproctitle() stuff into title.py.
This removes another instance of magical code running at module import
time.  And the process title wasn't really part of the state database
anyway.

Unfortunately this uncovered a bug: the recent change to use
'python -S' makes it not find the setproctitle module if installed.

My goodness, I hate the horrible python easy_install module gunk that
makes startup linearly slower the more modules you have installed,
whether you import them or not, if you don't use -S.  But oh well,
we're stuck with it for now.
2018-12-05 02:28:34 -05:00
Avery Pennarun
9b6d1eeb6e env and env_init: Eliminate weird auto-initialization of globals.
Merge the two files into env, and make each command explicitly call the
function that sets it up in the way that's needed for that command.

This means we can finally just import all the modules at the top of
each file, without worrying about import order.  Phew.

While we're here, remove the weird auto-appending-'all'-to-targets
feature in env.init().  Instead, do it explicitly, and only from redo and
redo-ifchange, only if is_toplevel and no other targets are given.
2018-12-05 02:27:04 -05:00
Avery Pennarun
75b5352511 test.do: allow docs to build in parallel with tests.
Previously, we'd try to build all the critical stuff first, and then
run the tests.  Nowadays, it takes a little longer to build the docs
(especially some of the docs/cookbook/ stuff), and this isn't needed to
run the tests, so let's allow them to parallelize.
2018-12-05 02:27:04 -05: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
f1305b49eb Move env.{add,get}_lock() into cycles.py, and rename.
They really aren't locks at all, they're a cycle detector.  Also rename
REDO_LOCKS to a more meaningful REDO_CYCLES.  And we'll move the
CyclicDependencyError exception in here as well, instead of state.py
where it doesn't really belong.
2018-12-05 02:26:58 -05:00
Avery Pennarun
ded14507b0 Rename vars{,_init}.py -> env{,_init}.py.
This fixes some pylint 'redefined builtins' warnings.  While I was
here, I fixed the others too by renaming a few local variables.
2018-12-05 02:26:49 -05:00
Avery Pennarun
65cf1c9854 Rename jwack.py -> jobserver.py.
I'm not really sure why I called it jwack.  I think it was kind of a
wack jobserver(tm).  But nowadays most of the wack-ness is gone.
2018-12-05 00:22:10 -05:00
Avery Pennarun
6e96395d48 redo/version: fix pylint warning. 2018-12-05 00:22:10 -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
5bc7c861b6 minimal/do: use "#!/usr/bin/env sh" instead of "#!/bin/sh"
This way you can force it to use redo-sh, so that it can pass
shelltest.od.
2018-12-04 02:52:23 -05:00
Avery Pennarun
8911a222bf minimal/do: reminder that nowadays incremental mode is default. 2018-12-04 02:43:58 -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
2d17be11ed sh.do: explicitly check /bin/sh instead of sh.
Because our experiment involves creating a file called redo/sh, and the
redo directory (or some other version of redo's dirctory) might be on
the path, just testing 'sh' is actually wrong: we might end up with
some earlier version of redo-sh.

Instead, specifically for sh, always demand that we test /bin/sh.
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
02f307578b Oops, broken 'install.do' target after pylint fixes. 2018-12-03 21:15:31 -05:00
Avery Pennarun
280cf6f3aa Add Roadmap.md. 2018-12-03 01:45:36 -05:00
Avery Pennarun
e1327540fb Move into the 21st century by fixing some pylint warnings. 2018-12-03 00:11:27 -05:00
Avery Pennarun
1966a0fac7 If using --log or -j > 1, disable stdin.
Parallelism and redo-log cause lots of confusion for any rules that try
to ask the user for questions, so disable it altogether.

Arguably, we should just disable stdin all the time, but maybe it's
still occasionally useful (even though you have to pass --no-log to get
it back).
2018-12-02 22:57:04 -05:00
Avery Pennarun
70f1557413 redo.py: split redo-log options into their own section.
This makes it a little more clear which things change the output format
vs changing redo functionality.
2018-12-02 22:36:13 -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
f25ebd6ccc Docs: format inline <code> blocks better.
It seems like we're using these differently than most readthedocs.org
users.  Remove the borders and padding so they work better inline, and
prevent confusing word wraps.
2018-11-29 14:59:38 -05:00
Avery Pennarun
2e84c1bc02 Docs/cookbook: add an R + latex example.
This shows how to dynamically generate a plot in R+ggplot2, then embed
it into a latex document, and compile it to pdf, all with proper
autodependencies.
2018-11-28 17:33:03 -05:00
Avery Pennarun
461ef57b26 Docs/cookbook: build from toplevel 'test' instead of toplevel 'all'.
The cookbook examples are interesting as redo tests, but don't need to
be built in order to build redo.
2018-11-28 12:55:49 -05:00
Avery Pennarun
caa86ac4bd Docs: results of more proofreading. 2018-11-26 18:09:36 -05:00
Avery Pennarun
d9d70c4c44 Even more doc cleanups. 2018-11-26 17:45:16 -05:00
Avery Pennarun
4008ce4a91 Change license to Apache 2.0.
Mailing list discussion was here:
https://groups.google.com/forum/#!topic/redo-list/wLMZMxtn4wo

Several more contributors replied to me personally to say that they
don't have a problem with the change (and several consider the change
to be an improvement).

The overwhelming majority of everything in the redo repo was written by
me, so I have the right to change the license unilaterally anyway,
subject to a few rules.  Since the new license actually removes
licensing/usage restrictions for everyone, this should be no problem.
2018-11-26 17:04:31 -05:00
Avery Pennarun
3b305edc7e Cookbook: add an example of using default.do for text processing. 2018-11-26 15:24:41 -05:00
Avery Pennarun
d663c9b67d First cookbook example for the docs: Hello World in C. 2018-11-24 14:36:02 -05:00
Avery Pennarun
d664099c9d Undo commit 95680ed: "Switch to using a separate lockfile per target."
This was required for old versions of MacOS X, but the bug has now been
fixed, so let's de-clutter the .redo directory by reducing to a single
lock file instead of one per fid.

This reverts commit 08b05fd72f92fa0061b3d082b391151b43cd7497.
2018-11-23 19:55:32 -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