@@ -6,6 +6,7 @@ use std::{
66 path:: { Path , PathBuf } ,
77 process:: { Command , Stdio } ,
88 sync:: OnceLock ,
9+ time:: SystemTime ,
910} ;
1011
1112use build_helper:: ci:: CiEnv ;
@@ -194,7 +195,7 @@ impl Config {
194195 let _ = try_run ( self , patchelf. arg ( fname) ) ;
195196 }
196197
197- fn download_file ( & self , url : & str , dest_path : & Path , help_on_error : & str ) {
198+ fn download_file ( & self , url : & str , dest_path : & Path , help_on_error : & str , commit : & String ) {
198199 self . verbose ( & format ! ( "download {url}" ) ) ;
199200 // Use a temporary file in case we crash while downloading, to avoid a corrupt download in cache/.
200201 let tempfile = self . tempdir ( ) . join ( dest_path. file_name ( ) . unwrap ( ) ) ;
@@ -203,7 +204,7 @@ impl Config {
203204 // protocols without worrying about merge conflicts if we change the HTTP implementation.
204205 match url. split_once ( "://" ) . map ( |( proto, _) | proto) {
205206 Some ( "http" ) | Some ( "https" ) => {
206- self . download_http_with_retries ( & tempfile, url, help_on_error)
207+ self . download_http_with_retries ( & tempfile, url, help_on_error, commit )
207208 }
208209 Some ( other) => panic ! ( "unsupported protocol {other} in {url}" ) ,
209210 None => panic ! ( "no protocol in {url}" ) ,
@@ -214,7 +215,13 @@ impl Config {
214215 ) ;
215216 }
216217
217- fn download_http_with_retries ( & self , tempfile : & Path , url : & str , help_on_error : & str ) {
218+ fn download_http_with_retries (
219+ & self ,
220+ tempfile : & Path ,
221+ url : & str ,
222+ help_on_error : & str ,
223+ commit : & String ,
224+ ) {
218225 println ! ( "downloading {url}" ) ;
219226 // Try curl. If that fails and we are on windows, fallback to PowerShell.
220227 let mut curl = Command :: new ( "curl" ) ;
@@ -250,19 +257,100 @@ impl Config {
250257 "(New-Object System.Net.WebClient).DownloadFile('{}', '{}')" ,
251258 url, tempfile. to_str( ) . expect( "invalid UTF-8 not supported with powershell downloads" ) ,
252259 ) ,
253- ] ) ) . is_err ( ) {
260+ ] ) ) . is_ok ( ) {
254261 return ;
255262 }
256263 eprintln ! ( "\n spurious failure, trying again" ) ;
257264 }
258265 }
259266 if !help_on_error. is_empty ( ) {
260267 eprintln ! ( "{help_on_error}" ) ;
268+ Self :: check_outdated ( commit) ;
261269 }
262270 crate :: exit!( 1 ) ;
263271 }
264272 }
265273
274+ fn check_outdated ( commit : & String ) {
275+ let check_outdated_msg = || {
276+ if !commit. is_empty ( ) {
277+ let build_date: String = Command :: new ( "git" )
278+ . arg ( "show" )
279+ . arg ( "-s" )
280+ . arg ( "--format=%ar" )
281+ . arg ( commit)
282+ . output ( )
283+ . unwrap ( )
284+ . stdout
285+ . into_iter ( )
286+ . map ( |c| c as char )
287+ . collect ( ) ;
288+ if build_date. is_empty ( ) {
289+ eprintln ! ( "NOTE: trying to download builds for {}" , commit) ;
290+ } else {
291+ eprintln ! (
292+ "NOTE: trying to download builds for {}, but it is from {}" ,
293+ commit, build_date
294+ ) ;
295+ }
296+ } else {
297+ eprintln ! ( "NOTE: you seem to have an outdated version of rust source" ) ;
298+ }
299+ } ;
300+
301+ let user: String = Command :: new ( "git" )
302+ . arg ( "config" )
303+ . arg ( "user.name" )
304+ . output ( )
305+ . expect ( "Failed to get git user.name" )
306+ . stdout
307+ . into_iter ( )
308+ . map ( |c| c as char )
309+ . collect ( ) ;
310+ let log: String = Command :: new ( "git" )
311+ . arg ( "log" )
312+ . arg ( "--pretty=short" )
313+ . arg ( "origin/master..HEAD" )
314+ . output ( )
315+ . expect ( "Failed to get git log" )
316+ . stdout
317+ . into_iter ( )
318+ . map ( |c| c as char )
319+ . collect ( ) ;
320+ for s in log. split ( "\n " ) {
321+ if s. contains ( "Author:" ) {
322+ if !s. contains ( & format ! ( "Author: {}" , user. replace( "\n " , "" ) ) ) {
323+ check_outdated_msg ( ) ;
324+ return ;
325+ }
326+ }
327+ }
328+ let last_commit: String = Command :: new ( "git" )
329+ . arg ( "show" )
330+ . arg ( "-s" )
331+ . arg ( "--date=short" )
332+ . arg ( "--format=%ct" )
333+ . arg ( "origin/master" )
334+ . output ( )
335+ . expect ( "Failed to get git log" )
336+ . stdout
337+ . into_iter ( )
338+ . map ( |c| c as char )
339+ . collect ( ) ;
340+ match SystemTime :: now ( ) . duration_since ( SystemTime :: UNIX_EPOCH ) {
341+ Ok ( n) => {
342+ let replaced = last_commit. replace ( "\n " , "" ) ;
343+ if n. as_secs ( ) - replaced. parse :: < u64 > ( ) . unwrap ( ) >= 165 * 24 * 60 * 60 {
344+ // origin/master is more than 10 days out of date
345+ check_outdated_msg ( ) ;
346+ return ;
347+ }
348+ }
349+ Err ( _) => panic ! ( "SystemTime before UNIX EPOCH!" ) ,
350+ }
351+ return ;
352+ }
353+
266354 fn unpack ( & self , tarball : & Path , dst : & Path , pattern : & str ) {
267355 eprintln ! ( "extracting {} to {}" , tarball. display( ) , dst. display( ) ) ;
268356 if !dst. exists ( ) {
@@ -492,7 +580,7 @@ impl Config {
492580 let extra_components = [ "cargo" ] ;
493581
494582 let download_beta_component = |config : & Config , filename, prefix : & _ , date : & _ | {
495- config. download_component ( DownloadSource :: Dist , filename, prefix, date, "stage0" )
583+ config. download_component ( DownloadSource :: Dist , filename, prefix, date, "stage0" ) ;
496584 } ;
497585
498586 self . download_toolchain (
@@ -648,7 +736,7 @@ HELP: if trying to compile an old commit of rustc, disable `download-rustc` in c
648736download-rustc = false
649737" ;
650738 }
651- self . download_file ( & format ! ( "{base_url}/{url}" ) , & tarball, help_on_error) ;
739+ self . download_file ( & format ! ( "{base_url}/{url}" ) , & tarball, help_on_error, & key . to_string ( ) ) ;
652740 if let Some ( sha256) = checksum {
653741 if !self . verify ( & tarball, sha256) {
654742 panic ! ( "failed to verify {}" , tarball. display( ) ) ;
@@ -726,7 +814,12 @@ download-rustc = false
726814 [llvm]
727815 download-ci-llvm = false
728816 " ;
729- self . download_file ( & format ! ( "{base}/{llvm_sha}/{filename}" ) , & tarball, help_on_error) ;
817+ self . download_file (
818+ & format ! ( "{base}/{llvm_sha}/{filename}" ) ,
819+ & tarball,
820+ help_on_error,
821+ & llvm_sha. to_string ( ) ,
822+ ) ;
730823 }
731824 let llvm_root = self . ci_llvm_root ( ) ;
732825 self . unpack ( & tarball, & llvm_root, "rust-dev" ) ;
0 commit comments