@@ -11,8 +11,8 @@ use once_cell::sync::OnceCell;
1111use  xz2:: bufread:: XzDecoder ; 
1212
1313use  crate :: { 
14-     min_config:: RustfmtMetadata , 
1514    llvm:: detect_llvm_sha, 
15+     min_config:: RustfmtMetadata , 
1616    t, 
1717    util:: { check_run,  exe,  output,  program_out_of_date,  try_run} , 
1818    Config ,  MinimalConfig , 
@@ -343,6 +343,99 @@ enum DownloadSource {
343343    Dist , 
344344} 
345345
346+ impl  MinimalConfig  { 
347+     pub  fn  download_bootstrap ( & self ,  commit :  & str )  -> PathBuf  { 
348+         self . verbose ( & format ! ( "downloading bootstrap from CI (commit {commit})" ) ) ; 
349+         let  host = self . build . triple ; 
350+         let  bin_root = self . out . join ( host) . join ( "bootstrap" ) ; 
351+         let  stamp = bin_root. join ( ".bootstrap-stamp" ) ; 
352+         let  bootstrap_bin = bin_root. join ( "bin" ) . join ( "bootstrap" ) ; 
353+ 
354+         if  !bootstrap_bin. exists ( )  || program_out_of_date ( & stamp,  commit)  { 
355+             let  version = self . git_artifact_version_part ( commit) ; 
356+             let  filename = format ! ( "bootstrap-{version}-{host}.tar.xz" ) ; 
357+             self . download_component ( DownloadSource :: CI ,  filename,  "bootstrap" ,  commit,  "" ) ; 
358+             if  self . should_fix_bins_and_dylibs ( )  { 
359+                 self . fix_bin_or_dylib ( & bootstrap_bin) ; 
360+             } 
361+             t ! ( fs:: write( stamp,  commit) ) ; 
362+         } 
363+ 
364+         bootstrap_bin
365+     } 
366+ 
367+     fn  download_component ( 
368+         & self , 
369+         mode :  DownloadSource , 
370+         filename :  String , 
371+         prefix :  & str , 
372+         key :  & str , 
373+         destination :  & str , 
374+     )  { 
375+         let  cache_dst = self . out . join ( "cache" ) ; 
376+         let  cache_dir = cache_dst. join ( key) ; 
377+         if  !cache_dir. exists ( )  { 
378+             t ! ( fs:: create_dir_all( & cache_dir) ) ; 
379+         } 
380+ 
381+         let  bin_root = self . out . join ( self . build . triple ) . join ( destination) ; 
382+         let  tarball = cache_dir. join ( & filename) ; 
383+         let  ( base_url,  url,  should_verify)  = match  mode { 
384+             DownloadSource :: CI  => ( 
385+                 self . stage0_metadata . config . artifacts_server . clone ( ) , 
386+                 format ! ( "{key}/{filename}" ) , 
387+                 false , 
388+             ) , 
389+             DownloadSource :: Dist  => { 
390+                 let  dist_server = env:: var ( "RUSTUP_DIST_SERVER" ) 
391+                     . unwrap_or ( self . stage0_metadata . config . dist_server . to_string ( ) ) ; 
392+                 // NOTE: make `dist` part of the URL because that's how it's stored in src/stage0.json 
393+                 ( dist_server,  format ! ( "dist/{key}/{filename}" ) ,  true ) 
394+             } 
395+         } ; 
396+ 
397+         // For the beta compiler, put special effort into ensuring the checksums are valid. 
398+         // FIXME: maybe we should do this for download-rustc as well? but it would be a pain to update 
399+         // this on each and every nightly ... 
400+         let  checksum = if  should_verify { 
401+             let  error = format ! ( 
402+                 "src/stage0.json doesn't contain a checksum for {url}. \  
403+ \ 
404+ \ 
405+ 
406+             ) ; 
407+             let  sha256 = self . stage0_metadata . checksums_sha256 . get ( & url) . expect ( & error) ; 
408+             if  tarball. exists ( )  { 
409+                 if  self . verify ( & tarball,  sha256)  { 
410+                     self . unpack ( & tarball,  & bin_root,  prefix) ; 
411+                     return ; 
412+                 }  else  { 
413+                     self . verbose ( & format ! ( 
414+                         "ignoring cached file {} due to failed verification" , 
415+                         tarball. display( ) 
416+                     ) ) ; 
417+                     self . remove ( & tarball) ; 
418+                 } 
419+             } 
420+             Some ( sha256) 
421+         }  else  if  tarball. exists ( )  { 
422+             self . unpack ( & tarball,  & bin_root,  prefix) ; 
423+             return ; 
424+         }  else  { 
425+             None 
426+         } ; 
427+ 
428+         self . download_file ( & format ! ( "{base_url}/{url}" ) ,  & tarball,  "" ) ; 
429+         if  let  Some ( sha256)  = checksum { 
430+             if  !self . verify ( & tarball,  sha256)  { 
431+                 panic ! ( "failed to verify {}" ,  tarball. display( ) ) ; 
432+             } 
433+         } 
434+ 
435+         self . unpack ( & tarball,  & bin_root,  prefix) ; 
436+     } 
437+ } 
438+ 
346439/// Functions that are only ever called once, but named for clarify and to avoid thousand-line functions. 
347440impl  Config  { 
348441    pub ( crate )  fn  maybe_download_rustfmt ( & self )  -> Option < PathBuf >  { 
@@ -553,96 +646,3 @@ impl Config {
553646        self . unpack ( & tarball,  & llvm_root,  "rust-dev" ) ; 
554647    } 
555648} 
556- 
557- impl  MinimalConfig  { 
558-     pub  fn  download_bootstrap ( & self ,  commit :  & str )  -> PathBuf  { 
559-         self . verbose ( & format ! ( "downloading bootstrap from CI (commit {commit})" ) ) ; 
560-         let  host = self . build . triple ; 
561-         let  bin_root = self . out . join ( host) . join ( "bootstrap" ) ; 
562-         let  stamp = bin_root. join ( ".bootstrap-stamp" ) ; 
563-         let  bootstrap_bin = bin_root. join ( "bin" ) . join ( "bootstrap" ) ; 
564- 
565-         if  !bootstrap_bin. exists ( )  || program_out_of_date ( & stamp,  commit)  { 
566-             let  version = self . git_artifact_version_part ( commit) ; 
567-             let  filename = format ! ( "bootstrap-{version}-{host}.tar.xz" ) ; 
568-             self . download_component ( DownloadSource :: CI ,  filename,  "bootstrap" ,  commit,  "" ) ; 
569-             if  self . should_fix_bins_and_dylibs ( )  { 
570-                 self . fix_bin_or_dylib ( & bootstrap_bin) ; 
571-             } 
572-             t ! ( fs:: write( stamp,  commit) ) ; 
573-         } 
574- 
575-         bootstrap_bin
576-     } 
577- 
578-     fn  download_component ( 
579-         & self , 
580-         mode :  DownloadSource , 
581-         filename :  String , 
582-         prefix :  & str , 
583-         key :  & str , 
584-         destination :  & str , 
585-     )  { 
586-         let  cache_dst = self . out . join ( "cache" ) ; 
587-         let  cache_dir = cache_dst. join ( key) ; 
588-         if  !cache_dir. exists ( )  { 
589-             t ! ( fs:: create_dir_all( & cache_dir) ) ; 
590-         } 
591- 
592-         let  bin_root = self . out . join ( self . build . triple ) . join ( destination) ; 
593-         let  tarball = cache_dir. join ( & filename) ; 
594-         let  ( base_url,  url,  should_verify)  = match  mode { 
595-             DownloadSource :: CI  => ( 
596-                 self . stage0_metadata . config . artifacts_server . clone ( ) , 
597-                 format ! ( "{key}/{filename}" ) , 
598-                 false , 
599-             ) , 
600-             DownloadSource :: Dist  => { 
601-                 let  dist_server = env:: var ( "RUSTUP_DIST_SERVER" ) 
602-                     . unwrap_or ( self . stage0_metadata . config . dist_server . to_string ( ) ) ; 
603-                 // NOTE: make `dist` part of the URL because that's how it's stored in src/stage0.json 
604-                 ( dist_server,  format ! ( "dist/{key}/{filename}" ) ,  true ) 
605-             } 
606-         } ; 
607- 
608-         // For the beta compiler, put special effort into ensuring the checksums are valid. 
609-         // FIXME: maybe we should do this for download-rustc as well? but it would be a pain to update 
610-         // this on each and every nightly ... 
611-         let  checksum = if  should_verify { 
612-             let  error = format ! ( 
613-                 "src/stage0.json doesn't contain a checksum for {url}. \  
614- \ 
615- \ 
616- 
617-             ) ; 
618-             let  sha256 = self . stage0_metadata . checksums_sha256 . get ( & url) . expect ( & error) ; 
619-             if  tarball. exists ( )  { 
620-                 if  self . verify ( & tarball,  sha256)  { 
621-                     self . unpack ( & tarball,  & bin_root,  prefix) ; 
622-                     return ; 
623-                 }  else  { 
624-                     self . verbose ( & format ! ( 
625-                         "ignoring cached file {} due to failed verification" , 
626-                         tarball. display( ) 
627-                     ) ) ; 
628-                     self . remove ( & tarball) ; 
629-                 } 
630-             } 
631-             Some ( sha256) 
632-         }  else  if  tarball. exists ( )  { 
633-             self . unpack ( & tarball,  & bin_root,  prefix) ; 
634-             return ; 
635-         }  else  { 
636-             None 
637-         } ; 
638- 
639-         self . download_file ( & format ! ( "{base_url}/{url}" ) ,  & tarball,  "" ) ; 
640-         if  let  Some ( sha256)  = checksum { 
641-             if  !self . verify ( & tarball,  sha256)  { 
642-                 panic ! ( "failed to verify {}" ,  tarball. display( ) ) ; 
643-             } 
644-         } 
645- 
646-         self . unpack ( & tarball,  & bin_root,  prefix) ; 
647-     } 
648- } 
0 commit comments