WSL (Windows Services for Linux) provides a Linux-kernel-compatible ABI
for userspace processes, but the current version doesn't not implement
fcntl() locks at all; it just always returns success. See
https://github.com/Microsoft/WSL/issues/1927.
This causes us three kinds of problem:
1. sqlite3 in WAL mode gives "OperationalError: locking protocol".
1b. Other sqlite3 journal modes also don't work when used by
multiple processes.
2. redo parallelism doesn't work, because we can't prevent the same
target from being build several times simultaneously.
3. "redo-log -f" doesn't work, since it can't tell whether the log
file it's tailing is "done" or not.
To fix #1, we switch the sqlite3 journal back to PERSIST instead of
WAL. We originally changed to WAL in commit 5156feae9d to reduce
deadlocks on MacOS. That was never adequately explained, but PERSIST
still acts weird on MacOS, so we'll only switch to PERSIST when we
detect that locking is definitely broken. Sigh.
To (mostly) fix #2, we disable any -j value > 1 when locking is broken.
This prevents basic forms of parallelism, but doesn't stop you from
re-entrantly starting other instances of redo. To fix that properly,
we need to switch to a different locking mechanism entirely, which is
tough in python. flock() locks probably work, for example, but
python's locks lie and just use fcntl locks for those.
To fix #3, we always force --no-log mode when we find that locking is
broken.
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
"""redo-unlocked: internal tool for building dependencies."""
|
|
import sys, os
|
|
from . import env, logs, state
|
|
|
|
|
|
def main():
|
|
if len(sys.argv[1:]) < 2:
|
|
sys.stderr.write('%s: at least 2 arguments expected.\n' % sys.argv[0])
|
|
sys.exit(1)
|
|
|
|
env.inherit()
|
|
logs.setup(
|
|
tty=sys.stderr, parent_logs=env.v.LOG,
|
|
pretty=env.v.PRETTY, color=env.v.COLOR)
|
|
|
|
target = sys.argv[1]
|
|
deps = sys.argv[2:]
|
|
|
|
for d in deps:
|
|
assert d != target
|
|
|
|
me = state.File(name=target)
|
|
|
|
# Build the known dependencies of our primary target. This *does* require
|
|
# grabbing locks.
|
|
os.environ['REDO_NO_OOB'] = '1'
|
|
argv = ['redo-ifchange'] + deps
|
|
rv = os.spawnvp(os.P_WAIT, argv[0], argv)
|
|
if rv:
|
|
sys.exit(rv)
|
|
|
|
# We know our caller already owns the lock on target, so we don't have to
|
|
# acquire another one; tell redo-ifchange about that. Also, REDO_NO_OOB
|
|
# persists from up above, because we don't want to do OOB now either.
|
|
# (Actually it's most important for the primary target, since it's the one
|
|
# who initiated the OOB in the first place.)
|
|
os.environ['REDO_UNLOCKED'] = '1'
|
|
argv = ['redo-ifchange', target]
|
|
rv = os.spawnvp(os.P_WAIT, argv[0], argv)
|
|
if rv:
|
|
sys.exit(rv)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|