Skip to content

Commit 1c6986f

Browse files
committed
bootstrap.py: add lockfile
the rust part of bootstrap already has a lockfile, but that's not good enough, the python side also shouldn't race with itself. fixes RUST-143756
1 parent bfc046a commit 1c6986f

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/bootstrap/bootstrap.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import tarfile
1212
import tempfile
1313

14-
from time import time
14+
from time import time, sleep
1515
from multiprocessing import Pool, cpu_count
1616

1717
try:
@@ -1262,6 +1262,17 @@ def parse_stage0_file(path):
12621262
return result
12631263

12641264

1265+
def acquire_lockfile(build_dir):
1266+
lock_path = os.path.join(build_dir, "py-lock")
1267+
while True:
1268+
try:
1269+
open(lock_path, "x")
1270+
return lock_path
1271+
except FileExistsError:
1272+
print("bootstrap.py: waiting for lockfile...")
1273+
sleep(2)
1274+
1275+
12651276
def bootstrap(args):
12661277
"""Configure, fetch, build and run the initial bootstrap"""
12671278
rust_root = os.path.abspath(os.path.join(__file__, "../../.."))
@@ -1333,18 +1344,24 @@ def bootstrap(args):
13331344
if not os.path.exists(build.build_dir):
13341345
os.makedirs(os.path.realpath(build.build_dir))
13351346

1336-
# Fetch/build the bootstrap
1337-
build.download_toolchain()
1338-
sys.stdout.flush()
1339-
build.build_bootstrap()
1340-
sys.stdout.flush()
1347+
lock_path = acquire_lockfile(build.build_dir)
13411348

1342-
# Run the bootstrap
1343-
args = [build.bootstrap_binary()]
1344-
args.extend(sys.argv[1:])
1345-
env = os.environ.copy()
1346-
env["BOOTSTRAP_PYTHON"] = sys.executable
1347-
run(args, env=env, verbose=build.verbose, is_bootstrap=True)
1349+
try:
1350+
# Fetch/build the bootstrap
1351+
build.download_toolchain()
1352+
sys.stdout.flush()
1353+
build.build_bootstrap()
1354+
sys.stdout.flush()
1355+
1356+
# Run the bootstrap
1357+
args = [build.bootstrap_binary()]
1358+
args.extend(sys.argv[1:])
1359+
env = os.environ.copy()
1360+
env["BOOTSTRAP_PYTHON"] = sys.executable
1361+
run(args, env=env, verbose=build.verbose, is_bootstrap=True)
1362+
finally:
1363+
# always remove the lockfile
1364+
os.remove(lock_path)
13481365

13491366

13501367
def main():

0 commit comments

Comments
 (0)