|
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:
|
@@ -1261,6 +1261,15 @@ def parse_stage0_file(path):
|
1261 | 1261 | result[key.strip()] = value.strip()
|
1262 | 1262 | return result
|
1263 | 1263 |
|
| 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) |
1264 | 1273 |
|
1265 | 1274 | def bootstrap(args):
|
1266 | 1275 | """Configure, fetch, build and run the initial bootstrap"""
|
@@ -1333,18 +1342,24 @@ def bootstrap(args):
|
1333 | 1342 | if not os.path.exists(build.build_dir):
|
1334 | 1343 | os.makedirs(os.path.realpath(build.build_dir))
|
1335 | 1344 |
|
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) |
1341 | 1346 |
|
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) |
1348 | 1363 |
|
1349 | 1364 |
|
1350 | 1365 | def main():
|
|
0 commit comments