Skip to content

Commit

Permalink
use stage0 file in bootstrap.py
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed May 9, 2024
1 parent efb153e commit b8da18c
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,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.")
Expand Down Expand Up @@ -421,9 +421,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
Expand All @@ -439,7 +439,7 @@ def __init__(
bin_root,
tarball_path,
tarball_suffix,
checksums_sha256,
stage0_data,
pattern,
verbose,
):
Expand All @@ -448,7 +448,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

Expand All @@ -458,7 +458,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,
)

Expand Down Expand Up @@ -510,11 +510,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"])

Check failure on line 514 in src/bootstrap/bootstrap.py

View workflow job for this annotation

GitHub Actions / PR - mingw-check-tidy

line longer than 100 chars
self.download_url = os.getenv("RUSTUP_DIST_SERVER") or self.stage0_data["dist_server"]

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

Expand Down Expand Up @@ -581,7 +579,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,
)
Expand Down Expand Up @@ -1071,6 +1069,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__, '../../..'))
Expand Down

0 comments on commit b8da18c

Please sign in to comment.