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.
This commit is contained in:
Avery Pennarun 2018-10-03 19:54:54 -04:00
commit 484ed925ad

View file

@ -77,8 +77,13 @@ def setup(maxjobs):
return # already set up return # already set up
_debug('setup(%d)\n' % maxjobs) _debug('setup(%d)\n' % maxjobs)
flags = ' ' + os.getenv('MAKEFLAGS', '') + ' ' flags = ' ' + os.getenv('MAKEFLAGS', '') + ' '
FIND = ' --jobserver-fds=' FIND1 = ' --jobserver-auth=' # renamed in GNU make 4.2
ofs = flags.find(FIND) FIND2 = ' --jobserver-fds=' # fallback syntax
FIND = FIND1
ofs = flags.find(FIND1)
if ofs < 0:
FIND = FIND2
ofs = flags.find(FIND2)
if ofs >= 0: if ofs >= 0:
s = flags[ofs+len(FIND):] s = flags[ofs+len(FIND):]
(arg,junk) = s.split(' ', 1) (arg,junk) = s.split(' ', 1)
@ -86,13 +91,13 @@ def setup(maxjobs):
a = atoi(a) a = atoi(a)
b = atoi(b) b = atoi(b)
if a <= 0 or b <= 0: if a <= 0 or b <= 0:
raise ValueError('invalid --jobserver-fds: %r' % arg) raise ValueError('invalid --jobserver-auth: %r' % arg)
try: try:
fcntl.fcntl(a, fcntl.F_GETFL) fcntl.fcntl(a, fcntl.F_GETFL)
fcntl.fcntl(b, fcntl.F_GETFL) fcntl.fcntl(b, fcntl.F_GETFL)
except IOError, e: except IOError, e:
if e.errno == errno.EBADF: if e.errno == errno.EBADF:
raise ValueError('broken --jobserver-fds from make; prefix your Makefile rule with a "+"') raise ValueError('broken --jobserver-auth from make; prefix your Makefile rule with a "+"')
else: else:
raise raise
_fds = (a,b) _fds = (a,b)
@ -102,8 +107,10 @@ def setup(maxjobs):
_fds = _make_pipe(100) _fds = _make_pipe(100)
_release(maxjobs-1) _release(maxjobs-1)
os.putenv('MAKEFLAGS', os.putenv('MAKEFLAGS',
'%s --jobserver-fds=%d,%d -j' % (os.getenv('MAKEFLAGS'), '%s -j --jobserver-auth=%d,%d --jobserver-fds=%d,%d' %
_fds[0], _fds[1])) (os.getenv('MAKEFLAGS', ''),
_fds[0], _fds[1],
_fds[0], _fds[1]))
def wait(want_token): def wait(want_token):