44import datetime
55import distutils .version
66import hashlib
7+ import json
78import os
89import re
910import shutil
@@ -176,15 +177,6 @@ def require(cmd, exit=True):
176177 sys .exit (1 )
177178
178179
179- def stage0_data (rust_root ):
180- """Build a dictionary from stage0.txt"""
181- nightlies = os .path .join (rust_root , "src/stage0.txt" )
182- with open (nightlies , 'r' ) as nightlies :
183- lines = [line .rstrip () for line in nightlies
184- if not line .startswith ("#" )]
185- return dict ([line .split (": " , 1 ) for line in lines if line ])
186-
187-
188180def format_build_time (duration ):
189181 """Return a nicer format for build time
190182
@@ -371,13 +363,21 @@ def output(filepath):
371363 os .rename (tmp , filepath )
372364
373365
366+ class Stage0Toolchain :
367+ def __init__ (self , stage0_payload ):
368+ self .date = stage0_payload ["date" ]
369+ self .version = stage0_payload ["version" ]
370+
371+ def channel (self ):
372+ return self .version + "-" + self .date
373+
374+
374375class RustBuild (object ):
375376 """Provide all the methods required to build Rust"""
376377 def __init__ (self ):
377- self .date = ''
378+ self .stage0_compiler = None
379+ self .stage0_rustfmt = None
378380 self ._download_url = ''
379- self .rustc_channel = ''
380- self .rustfmt_channel = ''
381381 self .build = ''
382382 self .build_dir = ''
383383 self .clean = False
@@ -401,11 +401,10 @@ def download_toolchain(self, stage0=True, rustc_channel=None):
401401 will move all the content to the right place.
402402 """
403403 if rustc_channel is None :
404- rustc_channel = self .rustc_channel
405- rustfmt_channel = self .rustfmt_channel
404+ rustc_channel = self .stage0_compiler .version
406405 bin_root = self .bin_root (stage0 )
407406
408- key = self .date
407+ key = self .stage0_compiler . date
409408 if not stage0 :
410409 key += str (self .rustc_commit )
411410 if self .rustc (stage0 ).startswith (bin_root ) and \
@@ -444,19 +443,23 @@ def download_toolchain(self, stage0=True, rustc_channel=None):
444443
445444 if self .rustfmt () and self .rustfmt ().startswith (bin_root ) and (
446445 not os .path .exists (self .rustfmt ())
447- or self .program_out_of_date (self .rustfmt_stamp (), self .rustfmt_channel )
446+ or self .program_out_of_date (
447+ self .rustfmt_stamp (),
448+ "" if self .stage0_rustfmt is None else self .stage0_rustfmt .channel ()
449+ )
448450 ):
449- if rustfmt_channel :
451+ if self . stage0_rustfmt is not None :
450452 tarball_suffix = '.tar.xz' if support_xz () else '.tar.gz'
451- [channel , date ] = rustfmt_channel .split ('-' , 1 )
452- filename = "rustfmt-{}-{}{}" .format (channel , self .build , tarball_suffix )
453+ filename = "rustfmt-{}-{}{}" .format (
454+ self .stage0_rustfmt .version , self .build , tarball_suffix ,
455+ )
453456 self ._download_component_helper (
454- filename , "rustfmt-preview" , tarball_suffix , key = date
457+ filename , "rustfmt-preview" , tarball_suffix , key = self . stage0_rustfmt . date
455458 )
456459 self .fix_bin_or_dylib ("{}/bin/rustfmt" .format (bin_root ))
457460 self .fix_bin_or_dylib ("{}/bin/cargo-fmt" .format (bin_root ))
458461 with output (self .rustfmt_stamp ()) as rustfmt_stamp :
459- rustfmt_stamp .write (self .rustfmt_channel )
462+ rustfmt_stamp .write (self .stage0_rustfmt . channel () )
460463
461464 # Avoid downloading LLVM twice (once for stage0 and once for the master rustc)
462465 if self .downloading_llvm () and stage0 :
@@ -517,7 +520,7 @@ def _download_component_helper(
517520 ):
518521 if key is None :
519522 if stage0 :
520- key = self .date
523+ key = self .stage0_compiler . date
521524 else :
522525 key = self .rustc_commit
523526 cache_dst = os .path .join (self .build_dir , "cache" )
@@ -815,7 +818,7 @@ def rustc(self, stage0):
815818
816819 def rustfmt (self ):
817820 """Return config path for rustfmt"""
818- if not self .rustfmt_channel :
821+ if self .stage0_rustfmt is None :
819822 return None
820823 return self .program_config ('rustfmt' )
821824
@@ -1039,19 +1042,12 @@ def update_submodules(self):
10391042 self .update_submodule (module [0 ], module [1 ], recorded_submodules )
10401043 print ("Submodules updated in %.2f seconds" % (time () - start_time ))
10411044
1042- def set_normal_environment (self ):
1045+ def set_dist_environment (self , url ):
10431046 """Set download URL for normal environment"""
10441047 if 'RUSTUP_DIST_SERVER' in os .environ :
10451048 self ._download_url = os .environ ['RUSTUP_DIST_SERVER' ]
10461049 else :
1047- self ._download_url = 'https://static.rust-lang.org'
1048-
1049- def set_dev_environment (self ):
1050- """Set download URL for development environment"""
1051- if 'RUSTUP_DEV_DIST_SERVER' in os .environ :
1052- self ._download_url = os .environ ['RUSTUP_DEV_DIST_SERVER' ]
1053- else :
1054- self ._download_url = 'https://dev-static.rust-lang.org'
1050+ self ._download_url = url
10551051
10561052 def check_vendored_status (self ):
10571053 """Check that vendoring is configured properly"""
@@ -1160,17 +1156,13 @@ def bootstrap(help_triggered):
11601156 build_dir = build .get_toml ('build-dir' , 'build' ) or 'build'
11611157 build .build_dir = os .path .abspath (build_dir .replace ("$ROOT" , build .rust_root ))
11621158
1163- data = stage0_data (build .rust_root )
1164- build .date = data ['date' ]
1165- build .rustc_channel = data ['rustc' ]
1159+ with open (os .path .join (build .rust_root , "src" , "stage0.json" )) as f :
1160+ data = json .load (f )
1161+ build .stage0_compiler = Stage0Toolchain (data ["compiler" ])
1162+ if data .get ("rustfmt" ) is not None :
1163+ build .stage0_rustfmt = Stage0Toolchain (data ["rustfmt" ])
11661164
1167- if "rustfmt" in data :
1168- build .rustfmt_channel = data ['rustfmt' ]
1169-
1170- if 'dev' in data :
1171- build .set_dev_environment ()
1172- else :
1173- build .set_normal_environment ()
1165+ build .set_dist_environment (data ["dist_server" ])
11741166
11751167 build .build = args .build or build .build_triple ()
11761168 build .update_submodules ()
0 commit comments