Skip to content

Commit f2d50b6

Browse files
committed
use stage0 file in bootstrap.py
Signed-off-by: onur-ozkan <[email protected]>
1 parent efb153e commit f2d50b6

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

src/bootstrap/bootstrap.py

+24-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import contextlib
44
import datetime
55
import hashlib
6-
import json
76
import os
87
import re
98
import shutil
@@ -52,7 +51,7 @@ def get(base, url, path, checksums, verbose=False):
5251

5352
try:
5453
if url not in checksums:
55-
raise RuntimeError(("src/stage0.json doesn't contain a checksum for {}. "
54+
raise RuntimeError(("src/stage0 doesn't contain a checksum for {}. "
5655
"Pre-built artifacts might not be available for this "
5756
"target at this time, see https://doc.rust-lang.org/nightly"
5857
"/rustc/platform-support.html for more information.")
@@ -421,9 +420,9 @@ def output(filepath):
421420

422421

423422
class Stage0Toolchain:
424-
def __init__(self, stage0_payload):
425-
self.date = stage0_payload["date"]
426-
self.version = stage0_payload["version"]
423+
def __init__(self, date, version):
424+
self.date = date
425+
self.version = version
427426

428427
def channel(self):
429428
return self.version + "-" + self.date
@@ -439,7 +438,7 @@ def __init__(
439438
bin_root,
440439
tarball_path,
441440
tarball_suffix,
442-
checksums_sha256,
441+
stage0_data,
443442
pattern,
444443
verbose,
445444
):
@@ -448,7 +447,7 @@ def __init__(
448447
self.bin_root = bin_root
449448
self.tarball_path = tarball_path
450449
self.tarball_suffix = tarball_suffix
451-
self.checksums_sha256 = checksums_sha256
450+
self.stage0_data = stage0_data
452451
self.pattern = pattern
453452
self.verbose = verbose
454453

@@ -458,7 +457,7 @@ def download_component(download_info):
458457
download_info.base_download_url,
459458
download_info.download_path,
460459
download_info.tarball_path,
461-
download_info.checksums_sha256,
460+
download_info.stage0_data,
462461
verbose=download_info.verbose,
463462
)
464463

@@ -510,11 +509,12 @@ def __init__(self, config_toml="", args=None):
510509
build_dir = args.build_dir or self.get_toml('build-dir', 'build') or 'build'
511510
self.build_dir = os.path.abspath(build_dir)
512511

513-
with open(os.path.join(self.rust_root, "src", "stage0.json")) as f:
514-
data = json.load(f)
515-
self.checksums_sha256 = data["checksums_sha256"]
516-
self.stage0_compiler = Stage0Toolchain(data["compiler"])
517-
self.download_url = os.getenv("RUSTUP_DIST_SERVER") or data["config"]["dist_server"]
512+
self.stage0_data = parse_stage0_file(os.path.join(self.rust_root, "src", "stage0"))
513+
self.stage0_compiler = Stage0Toolchain(
514+
self.stage0_data["compiler_date"],
515+
self.stage0_data["compiler_version"]
516+
)
517+
self.download_url = os.getenv("RUSTUP_DIST_SERVER") or self.stage0_data["dist_server"]
518518

519519
self.build = args.build or self.build_triple()
520520

@@ -581,7 +581,7 @@ def download_toolchain(self):
581581
bin_root=self.bin_root(),
582582
tarball_path=os.path.join(rustc_cache, filename),
583583
tarball_suffix=tarball_suffix,
584-
checksums_sha256=self.checksums_sha256,
584+
stage0_data=self.stage0_data,
585585
pattern=pattern,
586586
verbose=self.verbose,
587587
)
@@ -1071,6 +1071,16 @@ def parse_args(args):
10711071

10721072
return parser.parse_known_args(args)[0]
10731073

1074+
def parse_stage0_file(path):
1075+
result = {}
1076+
with open(path, 'r') as file:
1077+
for line in file:
1078+
line = line.strip()
1079+
if line and not line.startswith('#'):
1080+
key, value = line.split('=', 1)
1081+
result[key.strip()] = value.strip()
1082+
return result
1083+
10741084
def bootstrap(args):
10751085
"""Configure, fetch, build and run the initial bootstrap"""
10761086
rust_root = os.path.abspath(os.path.join(__file__, '../../..'))

0 commit comments

Comments
 (0)