Skip to content

Commit 9d46820

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 9d46820

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

src/bootstrap/bootstrap.py

Lines changed: 27 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:
@@ -1261,6 +1261,15 @@ def parse_stage0_file(path):
12611261
result[key.strip()] = value.strip()
12621262
return result
12631263

1264+
def aquire_lockfile(build_dir):
1265+
lock_path = os.path.join(build_dir, "py-lock")
1266+
while True:
1267+
try:
1268+
open(lock_path, "x")
1269+
return lock_path
1270+
except FileExistsError:
1271+
print("bootstrap.py: waiting for lockfile...")
1272+
sleep(2)
12641273

12651274
def bootstrap(args):
12661275
"""Configure, fetch, build and run the initial bootstrap"""
@@ -1333,18 +1342,24 @@ def bootstrap(args):
13331342
if not os.path.exists(build.build_dir):
13341343
os.makedirs(os.path.realpath(build.build_dir))
13351344

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

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)
1347+
try:
1348+
# Fetch/build the bootstrap
1349+
build.download_toolchain()
1350+
sys.stdout.flush()
1351+
build.build_bootstrap()
1352+
sys.stdout.flush()
1353+
1354+
# Run the bootstrap
1355+
args = [build.bootstrap_binary()]
1356+
args.extend(sys.argv[1:])
1357+
env = os.environ.copy()
1358+
env["BOOTSTRAP_PYTHON"] = sys.executable
1359+
run(args, env=env, verbose=build.verbose, is_bootstrap=True)
1360+
finally:
1361+
# always remove the lockfile
1362+
os.remove(lock_path)
13481363

13491364

13501365
def main():

0 commit comments

Comments
 (0)