Auto merge of #98373 - joshtriplett:bootstrap-locking, r=jyn514
Move locking from bootstrap.py to rust bootstrap, using fd-lock Helps with https://github.com/rust-lang/rust/issues/94829.
This commit is contained in:
commit
0e21a27075
6 changed files with 123 additions and 45 deletions
|
@ -15,44 +15,6 @@ import tempfile
|
|||
|
||||
from time import time, sleep
|
||||
|
||||
# Acquire a lock on the build directory to make sure that
|
||||
# we don't cause a race condition while building
|
||||
# Lock is created in `build_dir/lock.db`
|
||||
def acquire_lock(build_dir):
|
||||
try:
|
||||
import sqlite3
|
||||
|
||||
path = os.path.join(build_dir, "lock.db")
|
||||
try:
|
||||
con = sqlite3.Connection(path, timeout=0)
|
||||
curs = con.cursor()
|
||||
curs.execute("BEGIN EXCLUSIVE")
|
||||
# The lock is released when the cursor is dropped
|
||||
return curs
|
||||
# If the database is busy then lock has already been acquired
|
||||
# so we wait for the lock.
|
||||
# We retry every quarter second so that execution is passed back to python
|
||||
# so that it can handle signals
|
||||
except sqlite3.OperationalError:
|
||||
del con
|
||||
del curs
|
||||
print("Waiting for lock on build directory")
|
||||
con = sqlite3.Connection(path, timeout=0.25)
|
||||
curs = con.cursor()
|
||||
while True:
|
||||
try:
|
||||
curs.execute("BEGIN EXCLUSIVE")
|
||||
break
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
sleep(0.25)
|
||||
return curs
|
||||
except ImportError:
|
||||
print("warning: sqlite3 not available in python, skipping build directory lock")
|
||||
print("please file an issue on rust-lang/rust")
|
||||
print("this is not a problem for non-concurrent x.py invocations")
|
||||
return None
|
||||
|
||||
def support_xz():
|
||||
try:
|
||||
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
||||
|
@ -928,11 +890,8 @@ def bootstrap(help_triggered):
|
|||
|
||||
build.build = args.build or build.build_triple()
|
||||
|
||||
# Acquire the lock before doing any build actions
|
||||
# The lock is released when `lock` is dropped
|
||||
if not os.path.exists(build.build_dir):
|
||||
os.makedirs(build.build_dir)
|
||||
lock = acquire_lock(build.build_dir)
|
||||
|
||||
# Fetch/build the bootstrap
|
||||
build.download_toolchain()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue