@@ -322,6 +322,7 @@ def __init__(self):
322
322
self .date = ''
323
323
self ._download_url = ''
324
324
self .rustc_channel = ''
325
+ self .rustfmt_channel = ''
325
326
self .build = ''
326
327
self .build_dir = os .path .join (os .getcwd (), "build" )
327
328
self .clean = False
@@ -344,6 +345,7 @@ def download_stage0(self):
344
345
"""
345
346
rustc_channel = self .rustc_channel
346
347
cargo_channel = self .cargo_channel
348
+ rustfmt_channel = self .rustfmt_channel
347
349
348
350
def support_xz ():
349
351
try :
@@ -393,13 +395,29 @@ def support_xz():
393
395
with output (self .cargo_stamp ()) as cargo_stamp :
394
396
cargo_stamp .write (self .date )
395
397
396
- def _download_stage0_helper (self , filename , pattern , tarball_suffix ):
398
+ if self .rustfmt () and self .rustfmt ().startswith (self .bin_root ()) and (
399
+ not os .path .exists (self .rustfmt ())
400
+ or self .program_out_of_date (self .rustfmt_stamp ())
401
+ ):
402
+ if rustfmt_channel :
403
+ tarball_suffix = '.tar.xz' if support_xz () else '.tar.gz'
404
+ [channel , date ] = rustfmt_channel .split ('-' , 1 )
405
+ filename = "rustfmt-{}-{}{}" .format (channel , self .build , tarball_suffix )
406
+ self ._download_stage0_helper (filename , "rustfmt-preview" , tarball_suffix , date )
407
+ self .fix_executable ("{}/bin/rustfmt" .format (self .bin_root ()))
408
+ self .fix_executable ("{}/bin/cargo-fmt" .format (self .bin_root ()))
409
+ with output (self .rustfmt_stamp ()) as rustfmt_stamp :
410
+ rustfmt_stamp .write (self .date )
411
+
412
+ def _download_stage0_helper (self , filename , pattern , tarball_suffix , date = None ):
413
+ if date is None :
414
+ date = self .date
397
415
cache_dst = os .path .join (self .build_dir , "cache" )
398
- rustc_cache = os .path .join (cache_dst , self . date )
416
+ rustc_cache = os .path .join (cache_dst , date )
399
417
if not os .path .exists (rustc_cache ):
400
418
os .makedirs (rustc_cache )
401
419
402
- url = "{}/dist/{}" .format (self ._download_url , self . date )
420
+ url = "{}/dist/{}" .format (self ._download_url , date )
403
421
tarball = os .path .join (rustc_cache , filename )
404
422
if not os .path .exists (tarball ):
405
423
get ("{}/{}" .format (url , filename ), tarball , verbose = self .verbose )
@@ -493,6 +511,16 @@ def cargo_stamp(self):
493
511
"""
494
512
return os .path .join (self .bin_root (), '.cargo-stamp' )
495
513
514
+ def rustfmt_stamp (self ):
515
+ """Return the path for .rustfmt-stamp
516
+
517
+ >>> rb = RustBuild()
518
+ >>> rb.build_dir = "build"
519
+ >>> rb.rustfmt_stamp() == os.path.join("build", "stage0", ".rustfmt-stamp")
520
+ True
521
+ """
522
+ return os .path .join (self .bin_root (), '.rustfmt-stamp' )
523
+
496
524
def program_out_of_date (self , stamp_path ):
497
525
"""Check if the given program stamp is out of date"""
498
526
if not os .path .exists (stamp_path ) or self .clean :
@@ -565,6 +593,12 @@ def rustc(self):
565
593
"""Return config path for rustc"""
566
594
return self .program_config ('rustc' )
567
595
596
+ def rustfmt (self ):
597
+ """Return config path for rustfmt"""
598
+ if not self .rustfmt_channel :
599
+ return None
600
+ return self .program_config ('rustfmt' )
601
+
568
602
def program_config (self , program ):
569
603
"""Return config path for the given program
570
604
@@ -868,6 +902,9 @@ def bootstrap(help_triggered):
868
902
build .rustc_channel = data ['rustc' ]
869
903
build .cargo_channel = data ['cargo' ]
870
904
905
+ if "rustfmt" in data :
906
+ build .rustfmt_channel = data ['rustfmt' ]
907
+
871
908
if 'dev' in data :
872
909
build .set_dev_environment ()
873
910
else :
@@ -895,6 +932,8 @@ def bootstrap(help_triggered):
895
932
env ["RUSTC_BOOTSTRAP" ] = '1'
896
933
env ["CARGO" ] = build .cargo ()
897
934
env ["RUSTC" ] = build .rustc ()
935
+ if build .rustfmt ():
936
+ env ["RUSTFMT" ] = build .rustfmt ()
898
937
run (args , env = env , verbose = build .verbose )
899
938
900
939
0 commit comments