Commit graph

527 commits

Author SHA1 Message Date
Avery Pennarun
7f00abc36b jobserver: fix rare race condition in previous timer-exception workaround.
We have to clear the setitimer *before* leaving the try/except clause,
or the timer might fire between the try/except and the try/finally,
leaking a TimeoutError.

Reported-by: Denton Gentry
2021-07-27 20:48:36 -07:00
Ankur Kothari
8b2a4e9c37 Fix typo in docs: "an C" should be "in C" 2020-06-15 15:48:00 -04:00
Raphael Das Gupta
f75b69f063 fix typo / grammar in docs landing page 2020-06-15 15:47:36 -04:00
Aidan Holm
3f6e5f5e70 Fix typo. 2020-06-15 15:46:57 -04:00
Avery Pennarun
670abbe305 jobserver.py: _try_read()'s alarm timeout needs to throw an exception.
In python3, os.read() automatically retries after EINTR, which breaks
our ability to interrupt on SIGALRM.

Instead, throw an exception from the SIGALRM handler, which should work
on both python2 and python3.

This fixes a rare deadlock during parallel builds on python3.

For background:
https://www.python.org/dev/peps/pep-0475/#backward-compatibility

"Applications relying on the fact that system calls are interrupted
with InterruptedError will hang. The authors of this PEP don't think
that such applications exist [...]"

Well, apparently they were mistaken :)
2020-06-15 02:20:02 -04:00
Avery Pennarun
aa920f12ed jobserver.py: fix very rare python3 failure reported by a user.
Traceback (most recent call last):
  File "/nix/store/i0835myyhrfr13lh4y26r58406kk90xj-redo-apenwarr-0.42a/bin/../lib/redo/cmd_ifchange.py", line 54, in main
    jobserver.force_return_tokens()
  File "/nix/store/i0835myyhrfr13lh4y26r58406kk90xj-redo-apenwarr-0.42a/bin/../lib/redo/jobserver.py", line 482, in force_return_tokens
    os.write(_cheatfds[1], 't' * _cheats)
TypeError: a bytes-like object is required, not 'str'

Unfortunately I wasn't able to replicate it, but this is obviously the right fix.
2020-06-15 00:39:10 -04:00
Avery Pennarun
c1054a5902 t/110-compile: remove hard dependency on /usr/include/stdio.h.
This was testing source files outside the current build tree, but if
you don't have the file at all, that's not a good reason to fail the
test.
2020-06-15 00:33:41 -04:00
Avery Pennarun
a60949135d Merge branch 'doc_install_sudo' of git://github.com/BlameJohnny/redo
* 'doc_install_sudo' of git://github.com/BlameJohnny/redo:
  GettingStarted.md: Add -E option to sudo to preserve environment
2020-03-04 15:00:34 -05:00
Avery Pennarun
68d355178e Merge: Add compatibility to Python 3 (and retain Python 2)
Merge branch 'py6' of https://github.com/mlell/redo

* 'py6' of https://github.com/mlell/redo:
  Remove python<3.0 restriction in setup.py
  Make compatible to BeautifulSoup4
  Accept octal representations of Python 2 (0nnn) and Python 3 (0onnn)
  Prevent iterator being changed while iterating
  Python 2/3 compatible treatment of max(n, None)
  Prevent "Exception ... ignored" in `redo-log ... | head`
  Distinguish byte (python2 str type) and unicode strings (python 3 str type)
  Set file descriptor as inheritable for all pythons >=3.4
  Unify print function usage for Python 2 and 3 via __future__ import
  Run 2to3 utility
  Remove python interpreter selection
2020-03-04 14:54:24 -05:00
Avery Pennarun
92f86fc022 docs/cookbook/c: missing quote char. 2020-01-05 02:52:26 -05:00
Johnny Lind
94e9ee60d2 GettingStarted.md: Add -E option to sudo to preserve environment 2019-12-08 01:00:28 +01:00
Moritz Lell
be3bda885d Remove python<3.0 restriction in setup.py 2019-10-30 22:14:00 +01:00
Moritz Lell
a8fd6a123c Make compatible to BeautifulSoup4 2019-10-30 21:59:01 +01:00
Moritz Lell
5953729a44 Accept octal representations of Python 2 (0nnn) and Python 3 (0onnn)
The number format '0onnn' is accepted by both pythons
2019-10-30 21:59:01 +01:00
Moritz Lell
7f2d04d5ff Prevent iterator being changed while iterating
In Python 3, `zip()` returns an iterator that in turn contains references to
`tparts` and `bparts`. Because those two variables are modified within the
loop, the iterator does not advance properly.

Fix this by explicitly obtaining a list.
2019-10-30 21:59:01 +01:00
Moritz Lell
efab08fc9f Python 2/3 compatible treatment of max(n, None)
Python 3 does no longer allow comparisons of different types. Therefore,
explicitly convert f.checked_runid to a number that's always smaller than
`f.changed_runid`
2019-10-30 21:59:01 +01:00
Moritz Lell
52a8ca25b2 Prevent "Exception ... ignored" in redo-log ... | head
When STDOUT is piped to another program and that program closes the pipe,
this program is supposed to terminate. However, Python 3 prints an error
message because prior to exiting, STDOUT is automatically flushed which
does not work due to it being closed by the other side.

This commit includes code taken from the Python documentation for this case.
The output stream is redirected to /dev/null
2019-10-30 21:28:49 +01:00
Moritz Lell
e239820afd Distinguish byte (python2 str type) and unicode strings (python 3 str type)
Python 3 strings are python 2 unicode strings. Therefore consistently mark
strings that are sent via pipes or written/read to file as byte strings.
2019-10-30 21:28:49 +01:00
Moritz Lell
0d8d19437e Set file descriptor as inheritable for all pythons >=3.4
This is mandated by PEP 446
2019-10-30 21:28:49 +01:00
Moritz Lell
62845688e5 Unify print function usage for Python 2 and 3 via __future__ import 2019-10-30 21:28:49 +01:00
Moritz Lell
491040ea72 Run 2to3 utility 2019-10-30 19:58:12 +01:00
Moritz Lell
e8d4809bc5 Remove python interpreter selection 2019-10-30 19:58:12 +01:00
Avery Pennarun
b08b5efcef t/shelltest.od: Add a new preliminary test for IFS= behaviour.
Apparently in zsh (when in sh compatibility mode), IFS=/ will split
"/a/b/c/" into 5 parts ("", "a", "b", "c", ""). Other shells all seem
to agree that it's 4 parts ("", "a", "b", "c"). zsh seems maybe more
correct to me, but the majority rules, so we'll warn on it.

Meanwhile, we'll also fix the one place in minimal/do that failed due
to this oddity, since it's relatively easy to avoid.

Reported-by: shamrin@gmail.com
2019-07-24 03:27:12 -04:00
Avery Pennarun
262d272f29 t/103-unicode: workaround unicode normalization on newer macOS.
As named, the file would be extracted by git on macOS, then
(un)helpfully normalized by the macOS filesystem. After that,
"git clean -fdx" would delete the file, since it no longer
had the expected name, so git thought it wasn't part of its repo.

I considered pre-normalizing the filename, but a) that would break
on any future OS that normalizes differently; and b) that means we
won't test denormalized filenames. Instead, we'll remove the directory
from git, and create it from sh instead, then figure out what name
it got really created as, and then pass the "real" name to redo.
2019-07-24 03:27:04 -04:00
Avery Pennarun
bc9cc75bc6 Disable docker container test from toplevel 'redo test'
It's not reliable on all versions of docker, and we haven't had time to
fix it yet, so just turn it off. It's not essential to redo.

Reported-by: fcsmith@gmail.com
2019-07-24 03:27:04 -04:00
Avery Pennarun
8924fa35fa Oops, redo/whichpython.do would fail if python2.7 didn't exist. 2019-06-21 00:27:40 +09:00
Avery Pennarun
12b0d59b9f Merge remote-tracking branch 'origin/experimental/dockrepo'
* origin/experimental/dockrepo:
  docs/cookbook/container: update docker image builder.
2019-05-15 18:55:52 -07:00
Avery Pennarun
fb0a5bd69c Fix more problems with "/usr/bin/env python" picking python3.
Open files in 'rb' (read binary) mode to prevent useless default utf8
encoding in python3, without breaking python2 compatibility.

Reported-by: Tharre <tharre3@gmail.com>
2019-05-15 16:54:21 -07:00
Avery Pennarun
2e4d3d518e cookbook/container/default.sha256.do: use explicit close_fds=False.
Some people have /usr/bin/python as a link to python3. The script is
designed to work in either python2 or python3, but python3's subprocess
model defaults to close_fds=True, which closes the jobserver fds and
causes an error.  Explicitly force close_fds=False to get identical
behaviour on python2 and python3.

Reported-by: Tharre <tharre3@gmail.com>
2019-05-15 15:19:06 -07:00
Avery Pennarun
1ff5262124 redoconf/configure.sh: use "cmp -s" to silence output.
Eliminates this warning:
    $ mkdir out
    $ ../configure
    $ ../configure --prefix=/usr
    cmp: EOF on _flags after byte 33

Reported-by: compufreak@gmail.com
2019-05-15 14:12:26 -07:00
Avery Pennarun
4b01cdd9b5 Fix minor pylint warnings. 2019-05-13 23:08:51 +00:00
Avery Pennarun
5684142f11 redo-log: "(resumed)" lines didn't print as often as they should.
If we print a line indicating that we've started building a subprogram,
then that's an "interruption" of the detailed output of the current
program; we need to "resume" the current program's logs before printing
any new detailed information that comes through.
2019-05-13 22:58:42 +00:00
Avery Pennarun
642d6fa193 Unset CDPATH if it is set.
Apparently on some (probably buggy) platforms, when CDPATH is set, the
'cd' command will always print text to stdout.  This caused fail 122
and 123 in shelltest.od.

CDPATH is an interactive-mode option, so let's clear it when running
scripts.
2019-05-01 13:17:35 -04:00
Avery Pennarun
7238b370e4 builder.py: create temp log file in the same directory as the final one.
We're going to rename() it from the temp name to the final name, which
doesn't work across filesystems, so the safest option is to keep it in
the same directory.

Reported-by: spacefrogg@meterriblecrew.net
2019-03-12 00:03:34 -04:00
Avery Pennarun
e24e045a07 docs/cookbook/redoconf-simple: a simple redoconf C++ project.
This is a little simpler than the docs/cookbook/c project, which
doesn't actually have a doc yet because there was too much to explain.
I think I might make that a follow-on cookbook chapter, for people who
have read this simple one.

I think this doc is maybe a little too long; I intended it to be
"here's what you do to get started" but it turned into "here's what you
do to get started, and why it works, in excruciating detail." Not quite
sure how to fix.

(Also updated some other parts of the docs to refer to redoconf as a
real thing now instead of a "maybe someone should write this" thing.)
2019-03-06 03:05:04 -05:00
Avery Pennarun
7845f6ddde docs/cookbook/container: update docker image builder.
Apparently some newer docker versions crash if there is no "repository"
file in the resulting image.  Its syntax seems simple enough, described
in https://github.com/moby/moby/blob/master/image/spec/v1.md

Reported-by: Matthew Singletary <matt.singletary@gmail.com>
2019-03-05 21:49:36 -05:00
Avery Pennarun
2bea74df35 Work around ancient shells where >$3 does not implicitly quote $3.
Also add an entry in shelltest.od to reject any shell exhibiting that
bug.

Reported-by: Wayne Scott <wsc9tt@gmail.com>
2019-03-03 20:56:17 -05:00
Avery Pennarun
7895c947d5 shelltest.od: warning 84 (W84) triggered on *all* shells, not just posh.
I must have changed this at the last minute when adding it, but I don't
know why.  We were redefining f4() inside a subshell, so it never
applied to the parent shell, so it was always considered a failure.
But that's not what we were supposed to be testing.

This is just supposed to be a test of the really rare syntax of
defining a function without enclosing braces, which only fails on posh,
as far as I've seen.
2019-03-03 20:55:48 -05:00
Avery Pennarun
0dcc685739 Minor clarifications to redo install instructions.
Reported-by: @DRMacIver on twitter
2019-03-03 19:35:32 -05:00
Avery Pennarun
cead02bd21 redo-log: sometimes print a (resumed) line after ending a level of recursion.
If A calls B, and B produces stderr output, and then A wants to produce
output, the resulting log would be confusing: we'd see 'redo A' and
then 'redo B' and then B's output, but no indicator that B has ended
and we're back in A.  Now we show 'redo A (resumed)' before A's output.

If B didn't produce any output, or A doesn't produce any output, we
don't bother with the (resumed) line.  This seems nice, as it doesn't
clutter the log when there is no ambiguity anyway.
2019-03-02 19:08:47 -05:00
Avery Pennarun
b196315222 Change -x/-v to only affect top-level targets by default, not recursively.
Because redo targets are nicely isolated (unlike make targets), you
usually only want to debug one of them at a time.  Using -x could be
confusing, because you might end up with a dump of output from a
dependency you're not interested in.

Now, by default we'll disable -x when recursing into sub-targets, so
you only see the trace from the targets you are actually trying to
debug.  To get recursive behaviour, specify -x twice, eg. -xx.

Same idea with -v.
2019-03-02 18:46:00 -05:00
Avery Pennarun
7b4e3326bd logs.py: don't print (unchanged) lines with --no-log unless DEBUG.
This accidentally made output look different with --no-log vs with
normal redo-log output, because redo-log has a -u option while plain
redo does not.

(This is on purpose.  When running redo, you only want to see the things
that actually happened, so it never passes -u to the auto-launched
redo-log instance.  But when reviewing logs later, you might want to
look at the past logs from building a component that was unchanged in
the most recent run.)
2019-03-02 18:41:37 -05:00
Avery Pennarun
3071d13416 Merge branch 'redoconf'
* redoconf:
  redoconf: a stub rc_include() now sources ./redoconf.rc automatically.
  redoconf: assorted minor fixes.
  redoconf: move -Wl,-rpath flags to shlib.rc and add -Wl,-z,origin.
  mkdocs: don't bother to include cookbook/c/out.*/ dirs.
  docs/cookbook/c/allconfig.do: avoid need for '&' backgrounding.
  Precompiled headers: supply "-x c-header" or "-x c++-header" if available.
  minimal/do: remove dependency on 'seq' command.
  Fix some build problems on MacOS X.
  redoconf: posix.rc: fix abort when timespec is not available.
  redoconf: better handling of required vs optional detectors.
  redoconf: clock_gettime() detection needs to depend on -lrt.
  redoconf: avoid sed -E in _objlist().
  Experimental new redoconf C/C++ build/autoconfiguration system.
2019-03-02 04:32:07 -05:00
Avery Pennarun
1a3c11f220 redoconf: a stub rc_include() now sources ./redoconf.rc automatically.
This lets us remove the awkward ". ./redoconf.rc" line from zillions
of .od scripts, without paying the price of *always* including that
whole file every time default.do.sh is used.
2019-03-02 04:24:58 -05:00
Avery Pennarun
49f85f2156 redoconf: assorted minor fixes.
- libqt4.rc: add detection of the 'moc' command in $MOC.
- libssl.rc: add detection script for openssl.
- default.do.sh: provide a die() function to all .od files.  It's just
  too useful to not have it (I haven't converted everything to it yet).
- When building out/x/y.z, match against $S/default.z.od and
  $S/default.od if they exist.
- *.list files (lists of source/object files to include in a binary)
  can now contain *.o files in addition to *.c, *.cc, etc.
- rename compile() to _compile() to avoid polluting the namespace for
  scripts called from default.do.sh.
- When building a .so file in the top level directory, no need to
  make a symlink of it into the top level directory.
- link.od and link-shlib.od forgot to make use of the $xLIBS variable.
2019-03-02 04:12:25 -05:00
Avery Pennarun
1e2fc9be8a Merge branch 'master' into redoconf
* master:
  builder.py: atomically replace the log for a given target.
  redo-ifchange regression: if REDO_LOG is not set, assume it's 1.
  Explicitly reject target/source filenames with newlines in them.
  If redo searched all the way up to /default.do, it would run ./default.do instead.
  Overridden files were accidentally getting reclassified as static.
  Certain redo post-build failures would still mark a target as built.
  minimal/do: remove dependency on 'seq' command.
2019-03-02 04:09:17 -05:00
Avery Pennarun
63230a1ae3 builder.py: atomically replace the log for a given target.
Previously we were truncating the log if it existed.  This would cause
redo-log to produce invalid output if you had the following (admittedly
rare) sequence in a single session:
- start building X
- redo-log starts showing the log for X
- finish building X
- redo-log has not finished showing the log for X yet
- start building X again for some reason
- redo-log sees a truncated logfile.

Now, redo-log can finish reading the original file (which no longer has
a filename since it was overwritten) while the new file is being
created.
2019-03-02 04:05:36 -05:00
Avery Pennarun
8a97b0cb2c redo-ifchange regression: if REDO_LOG is not set, assume it's 1.
At some point this got broken during a refactoring.  The result was
that redo-ifchange, run from the command line (as opposed to inside a
.do script) would fail to start the log prettifier.
2019-03-02 04:05:36 -05:00
Avery Pennarun
83bc49512f Explicitly reject target/source filenames with newlines in them.
This avoids an ugly assertion failure when we try to log a message
containing an inner newline.
2019-03-02 04:05:36 -05:00
Avery Pennarun
e5a27f04e8 If redo searched all the way up to /default.do, it would run ./default.do instead.
This only happened if the containing project was buggy, ie. you tried
to build a target that has no .do file available anywhere. However, it
resulted in a confusing outcome for that case, where we'd run the wrong
default.do file with the wrong parameters.

Extended an existing test to catch this mistake.
2019-03-02 04:05:36 -05:00