Skip to content

bootstrap.py: add lockfile #143854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import tarfile
import tempfile

from time import time
from time import time, sleep
from multiprocessing import Pool, cpu_count

try:
Expand Down Expand Up @@ -1262,6 +1262,17 @@ def parse_stage0_file(path):
return result


def acquire_lockfile(build_dir):
lock_path = os.path.join(build_dir, "py-lock")
while True:
try:
open(lock_path, "x")
return lock_path
except FileExistsError:
print("bootstrap.py: waiting for lockfile...")
sleep(2)


def bootstrap(args):
"""Configure, fetch, build and run the initial bootstrap"""
rust_root = os.path.abspath(os.path.join(__file__, "../../.."))
Expand Down Expand Up @@ -1333,18 +1344,24 @@ def bootstrap(args):
if not os.path.exists(build.build_dir):
os.makedirs(os.path.realpath(build.build_dir))

# Fetch/build the bootstrap
build.download_toolchain()
sys.stdout.flush()
build.build_bootstrap()
sys.stdout.flush()
lock_path = acquire_lockfile(build.build_dir)

# Run the bootstrap
args = [build.bootstrap_binary()]
args.extend(sys.argv[1:])
env = os.environ.copy()
env["BOOTSTRAP_PYTHON"] = sys.executable
run(args, env=env, verbose=build.verbose, is_bootstrap=True)
try:
# Fetch/build the bootstrap
build.download_toolchain()
sys.stdout.flush()
build.build_bootstrap()
sys.stdout.flush()

# Run the bootstrap
args = [build.bootstrap_binary()]
args.extend(sys.argv[1:])
env = os.environ.copy()
env["BOOTSTRAP_PYTHON"] = sys.executable
run(args, env=env, verbose=build.verbose, is_bootstrap=True)
finally:
# always remove the lockfile
os.remove(lock_path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove the lockfile earlier? It feels a bit odd to remove it only after (IIUC) we run the Rust part -- then the Rust lockfile is never considered, right? And the Rust part has far more extensive code (e.g., we print the PID and such, IIRC)...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't feel like a good idea.

The files modified by the python side are often read by the rust side. If we remove the lockfile early, the second python command could start modifying files that are read by the rust command.

Sure, we could write bootstrap very particularly to work around this... but that seems like a waste of effort (that would need to be maintained continuously to prevent bugs) for a very niche upside.

More reasonable I think would be just porting these features to the python side.



def main():
Expand Down
Loading