jobserver: allow overriding the parent jobserver in a subprocess.

Previously, if you passed a -j option to a redo process in a redo or
make process hierarchy with MAKEFLAGS already set, it would ignore the
-j option and continue using the jobserver provided by the parent.

With this change, we instead initialize a new jobserver with the
desired number of tokens, which is what GNU make does in the same
situation.  A typical use case for this is to force serialization of
build steps in a subtree (by using -j1).  In make, this is often useful
for "fixing" makefiles that haven't been written correctly for parallel
builds.  In redo, that happens much less often, but it's useful at
least in unit tests.

Passing -j1 is relatively harmless (the redo you are starting inherits
a token anyway, so it doesn't create any new tokens).  Passing -j > 1
is more risky, because it creates new tokens, thus increasing the level
of parallelism in the system.  Because this may not be what you wanted,
we print a warning when you pass -j > 1 to a sub-redo.  GNU make gives
a similar warning in this situation.
This commit is contained in:
Avery Pennarun 2018-12-31 18:57:58 -05:00
commit 19049d52fc
3 changed files with 38 additions and 17 deletions

View file

@ -36,7 +36,7 @@ def main():
else:
f = me = None
debug2('redo-ifchange: not adding depends.\n')
jobserver.setup(1)
jobserver.setup(0)
try:
if f:
for t in targets: