4
4
import datetime
5
5
import distutils .version
6
6
import hashlib
7
+ import json
7
8
import os
8
9
import re
9
10
import shutil
@@ -176,15 +177,6 @@ def require(cmd, exit=True):
176
177
sys .exit (1 )
177
178
178
179
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
-
188
180
def format_build_time (duration ):
189
181
"""Return a nicer format for build time
190
182
@@ -371,13 +363,21 @@ def output(filepath):
371
363
os .rename (tmp , filepath )
372
364
373
365
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
+
374
375
class RustBuild (object ):
375
376
"""Provide all the methods required to build Rust"""
376
377
def __init__ (self ):
377
- self .date = ''
378
+ self .stage0_compiler = None
379
+ self .stage0_rustfmt = None
378
380
self ._download_url = ''
379
- self .rustc_channel = ''
380
- self .rustfmt_channel = ''
381
381
self .build = ''
382
382
self .build_dir = ''
383
383
self .clean = False
@@ -401,11 +401,10 @@ def download_toolchain(self, stage0=True, rustc_channel=None):
401
401
will move all the content to the right place.
402
402
"""
403
403
if rustc_channel is None :
404
- rustc_channel = self .rustc_channel
405
- rustfmt_channel = self .rustfmt_channel
404
+ rustc_channel = self .stage0_compiler .version
406
405
bin_root = self .bin_root (stage0 )
407
406
408
- key = self .date
407
+ key = self .stage0_compiler . date
409
408
if not stage0 :
410
409
key += str (self .rustc_commit )
411
410
if self .rustc (stage0 ).startswith (bin_root ) and \
@@ -444,19 +443,23 @@ def download_toolchain(self, stage0=True, rustc_channel=None):
444
443
445
444
if self .rustfmt () and self .rustfmt ().startswith (bin_root ) and (
446
445
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
+ )
448
450
):
449
- if rustfmt_channel :
451
+ if self . stage0_rustfmt is not None :
450
452
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
+ )
453
456
self ._download_component_helper (
454
- filename , "rustfmt-preview" , tarball_suffix , key = date
457
+ filename , "rustfmt-preview" , tarball_suffix , key = self . stage0_rustfmt . date
455
458
)
456
459
self .fix_bin_or_dylib ("{}/bin/rustfmt" .format (bin_root ))
457
460
self .fix_bin_or_dylib ("{}/bin/cargo-fmt" .format (bin_root ))
458
461
with output (self .rustfmt_stamp ()) as rustfmt_stamp :
459
- rustfmt_stamp .write (self .rustfmt_channel )
462
+ rustfmt_stamp .write (self .stage0_rustfmt . channel () )
460
463
461
464
# Avoid downloading LLVM twice (once for stage0 and once for the master rustc)
462
465
if self .downloading_llvm () and stage0 :
@@ -517,7 +520,7 @@ def _download_component_helper(
517
520
):
518
521
if key is None :
519
522
if stage0 :
520
- key = self .date
523
+ key = self .stage0_compiler . date
521
524
else :
522
525
key = self .rustc_commit
523
526
cache_dst = os .path .join (self .build_dir , "cache" )
@@ -815,7 +818,7 @@ def rustc(self, stage0):
815
818
816
819
def rustfmt (self ):
817
820
"""Return config path for rustfmt"""
818
- if not self .rustfmt_channel :
821
+ if self .stage0_rustfmt is None :
819
822
return None
820
823
return self .program_config ('rustfmt' )
821
824
@@ -1039,19 +1042,12 @@ def update_submodules(self):
1039
1042
self .update_submodule (module [0 ], module [1 ], recorded_submodules )
1040
1043
print ("Submodules updated in %.2f seconds" % (time () - start_time ))
1041
1044
1042
- def set_normal_environment (self ):
1045
+ def set_dist_environment (self , url ):
1043
1046
"""Set download URL for normal environment"""
1044
1047
if 'RUSTUP_DIST_SERVER' in os .environ :
1045
1048
self ._download_url = os .environ ['RUSTUP_DIST_SERVER' ]
1046
1049
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
1055
1051
1056
1052
def check_vendored_status (self ):
1057
1053
"""Check that vendoring is configured properly"""
@@ -1160,17 +1156,13 @@ def bootstrap(help_triggered):
1160
1156
build_dir = build .get_toml ('build-dir' , 'build' ) or 'build'
1161
1157
build .build_dir = os .path .abspath (build_dir .replace ("$ROOT" , build .rust_root ))
1162
1158
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" ])
1166
1164
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" ])
1174
1166
1175
1167
build .build = args .build or build .build_triple ()
1176
1168
build .update_submodules ()
0 commit comments