|
11 | 11 | import tarfile
|
12 | 12 | import tempfile
|
13 | 13 |
|
14 |
| -from time import time |
| 14 | +from time import time, sleep |
15 | 15 | from multiprocessing import Pool, cpu_count
|
16 | 16 |
|
17 | 17 | try:
|
@@ -1262,6 +1262,17 @@ def parse_stage0_file(path):
|
1262 | 1262 | return result
|
1263 | 1263 |
|
1264 | 1264 |
|
| 1265 | +def aquire_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 | + |
1265 | 1276 | def bootstrap(args):
|
1266 | 1277 | """Configure, fetch, build and run the initial bootstrap"""
|
1267 | 1278 | rust_root = os.path.abspath(os.path.join(__file__, "../../.."))
|
@@ -1333,18 +1344,24 @@ def bootstrap(args):
|
1333 | 1344 | if not os.path.exists(build.build_dir):
|
1334 | 1345 | os.makedirs(os.path.realpath(build.build_dir))
|
1335 | 1346 |
|
1336 |
| - # Fetch/build the bootstrap |
1337 |
| - build.download_toolchain() |
1338 |
| - sys.stdout.flush() |
1339 |
| - build.build_bootstrap() |
1340 |
| - sys.stdout.flush() |
| 1347 | + lock_path = aquire_lockfile(build.build_dir) |
1341 | 1348 |
|
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) |
1348 | 1365 |
|
1349 | 1366 |
|
1350 | 1367 | def main():
|
|
0 commit comments