From f78b91c3eba3a58b2cecd590967edea52b8d794b Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Thu, 9 May 2024 17:26:35 +0300 Subject: [PATCH] use stage0 file in `bootstrap.py` Signed-off-by: onur-ozkan --- src/bootstrap/bootstrap.py | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index e464e444fea20..54a76ce57d0fb 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -3,7 +3,6 @@ import contextlib import datetime import hashlib -import json import os import re import shutil @@ -52,7 +51,7 @@ def get(base, url, path, checksums, verbose=False): try: if url not in checksums: - raise RuntimeError(("src/stage0.json doesn't contain a checksum for {}. " + raise RuntimeError(("src/stage0 doesn't contain a checksum for {}. " "Pre-built artifacts might not be available for this " "target at this time, see https://doc.rust-lang.org/nightly" "/rustc/platform-support.html for more information.") @@ -421,9 +420,9 @@ def output(filepath): class Stage0Toolchain: - def __init__(self, stage0_payload): - self.date = stage0_payload["date"] - self.version = stage0_payload["version"] + def __init__(self, date, version): + self.date = date + self.version = version def channel(self): return self.version + "-" + self.date @@ -439,7 +438,7 @@ def __init__( bin_root, tarball_path, tarball_suffix, - checksums_sha256, + stage0_data, pattern, verbose, ): @@ -448,7 +447,7 @@ def __init__( self.bin_root = bin_root self.tarball_path = tarball_path self.tarball_suffix = tarball_suffix - self.checksums_sha256 = checksums_sha256 + self.stage0_data = stage0_data self.pattern = pattern self.verbose = verbose @@ -458,7 +457,7 @@ def download_component(download_info): download_info.base_download_url, download_info.download_path, download_info.tarball_path, - download_info.checksums_sha256, + download_info.stage0_data, verbose=download_info.verbose, ) @@ -510,11 +509,9 @@ def __init__(self, config_toml="", args=None): build_dir = args.build_dir or self.get_toml('build-dir', 'build') or 'build' self.build_dir = os.path.abspath(build_dir) - with open(os.path.join(self.rust_root, "src", "stage0.json")) as f: - data = json.load(f) - self.checksums_sha256 = data["checksums_sha256"] - self.stage0_compiler = Stage0Toolchain(data["compiler"]) - self.download_url = os.getenv("RUSTUP_DIST_SERVER") or data["config"]["dist_server"] + self.stage0_data = parse_stage0_file(os.path.join(self.rust_root, "src", "stage0")) + self.stage0_compiler = Stage0Toolchain(self.stage0_data["compiler_date"], self.stage0_data["compiler_version"]) + self.download_url = os.getenv("RUSTUP_DIST_SERVER") or self.stage0_data["dist_server"] self.build = args.build or self.build_triple() @@ -581,7 +578,7 @@ def download_toolchain(self): bin_root=self.bin_root(), tarball_path=os.path.join(rustc_cache, filename), tarball_suffix=tarball_suffix, - checksums_sha256=self.checksums_sha256, + stage0_data=self.stage0_data, pattern=pattern, verbose=self.verbose, ) @@ -1071,6 +1068,16 @@ def parse_args(args): return parser.parse_known_args(args)[0] +def parse_stage0_file(path): + result = {} + with open(path, 'r') as file: + for line in file: + line = line.strip() + if line and not line.startswith('#'): + key, value = line.split('=', 1) + result[key.strip()] = value.strip() + return result + def bootstrap(args): """Configure, fetch, build and run the initial bootstrap""" rust_root = os.path.abspath(os.path.join(__file__, '../../..'))