@@ -6,9 +6,10 @@ use std::{
6
6
path:: { Path , PathBuf } ,
7
7
process:: { Command , Stdio } ,
8
8
sync:: OnceLock ,
9
+ time:: SystemTime ,
9
10
} ;
10
11
11
- use build_helper:: ci:: CiEnv ;
12
+ use build_helper:: { ci:: CiEnv , git , git :: GitConfig } ;
12
13
use xz2:: bufread:: XzDecoder ;
13
14
14
15
use crate :: core:: config:: RustfmtMetadata ;
@@ -194,7 +195,7 @@ impl Config {
194
195
let _ = try_run ( self , patchelf. arg ( fname) ) ;
195
196
}
196
197
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 ) {
198
199
self . verbose ( & format ! ( "download {url}" ) ) ;
199
200
// Use a temporary file in case we crash while downloading, to avoid a corrupt download in cache/.
200
201
let tempfile = self . tempdir ( ) . join ( dest_path. file_name ( ) . unwrap ( ) ) ;
@@ -203,7 +204,7 @@ impl Config {
203
204
// protocols without worrying about merge conflicts if we change the HTTP implementation.
204
205
match url. split_once ( "://" ) . map ( |( proto, _) | proto) {
205
206
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 )
207
208
}
208
209
Some ( other) => panic ! ( "unsupported protocol {other} in {url}" ) ,
209
210
None => panic ! ( "no protocol in {url}" ) ,
@@ -214,7 +215,13 @@ impl Config {
214
215
) ;
215
216
}
216
217
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
+ ) {
218
225
println ! ( "downloading {url}" ) ;
219
226
// Try curl. If that fails and we are on windows, fallback to PowerShell.
220
227
let mut curl = Command :: new ( "curl" ) ;
@@ -250,19 +257,114 @@ impl Config {
250
257
"(New-Object System.Net.WebClient).DownloadFile('{}', '{}')" ,
251
258
url, tempfile. to_str( ) . expect( "invalid UTF-8 not supported with powershell downloads" ) ,
252
259
) ,
253
- ] ) ) . is_err ( ) {
260
+ ] ) ) . is_ok ( ) {
254
261
return ;
255
262
}
256
263
eprintln ! ( "\n spurious failure, trying again" ) ;
257
264
}
258
265
}
259
266
if !help_on_error. is_empty ( ) {
260
267
eprintln ! ( "{help_on_error}" ) ;
268
+ Self :: check_outdated ( commit) ;
261
269
}
262
270
crate :: exit!( 1 ) ;
263
271
}
264
272
}
265
273
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 upstream = git:: get_rust_lang_rust_remote (
311
+ & GitConfig { git_repository : "rust-lang/rust.git" , nightly_branch : "" } ,
312
+ None ,
313
+ ) ;
314
+ match upstream {
315
+ Ok ( upstream) => {
316
+ let log: String = Command :: new ( "git" )
317
+ . arg ( "log" )
318
+ . arg ( "--pretty=short" )
319
+ . arg ( format ! ( "{}/master..HEAD" , upstream) )
320
+ . output ( )
321
+ . expect ( "Failed to get git log" )
322
+ . stdout
323
+ . into_iter ( )
324
+ . map ( |c| c as char )
325
+ . collect ( ) ;
326
+ for s in log. split ( "\n " ) {
327
+ if s. contains ( "Author:" ) {
328
+ if !s. contains ( & format ! ( "Author: {}" , user. replace( "\n " , "" ) ) ) {
329
+ check_outdated_msg ( ) ;
330
+ return ;
331
+ }
332
+ }
333
+ }
334
+ }
335
+ Err ( e) => eprintln ! ( "{}" , e) ,
336
+ }
337
+ let last_commit: String = Command :: new ( "git" )
338
+ . arg ( "show" )
339
+ . arg ( "-s" )
340
+ . arg ( "--date=short" )
341
+ . arg ( "--format=%ct" )
342
+ . arg ( "origin/master" )
343
+ . output ( )
344
+ . expect ( "Failed to get git log" )
345
+ . stdout
346
+ . into_iter ( )
347
+ . map ( |c| c as char )
348
+ . collect ( ) ;
349
+ match SystemTime :: now ( ) . duration_since ( SystemTime :: UNIX_EPOCH ) {
350
+ Ok ( n) => {
351
+ let replaced = last_commit. replace ( "\n " , "" ) ;
352
+ let diff = n. as_secs ( ) - replaced. parse :: < u64 > ( ) . unwrap ( ) ;
353
+ if diff >= 165 * 24 * 60 * 60 {
354
+ // origin/master is more than 165 days out of date, CI builds disappear in 168 days
355
+ eprintln ! (
356
+ "NOTE: origin/master is {} days out of date, CI builds disappear in 168 days." ,
357
+ diff / ( 24 * 60 * 60 )
358
+ ) ;
359
+ eprintln ! ( "HELP: Consider updating your fork of the rust sources" ) ;
360
+ return ;
361
+ }
362
+ }
363
+ Err ( _) => panic ! ( "SystemTime before UNIX EPOCH!" ) ,
364
+ }
365
+ return ;
366
+ }
367
+
266
368
fn unpack ( & self , tarball : & Path , dst : & Path , pattern : & str ) {
267
369
eprintln ! ( "extracting {} to {}" , tarball. display( ) , dst. display( ) ) ;
268
370
if !dst. exists ( ) {
@@ -492,7 +594,7 @@ impl Config {
492
594
let extra_components = [ "cargo" ] ;
493
595
494
596
let download_beta_component = |config : & Config , filename, prefix : & _ , date : & _ | {
495
- config. download_component ( DownloadSource :: Dist , filename, prefix, date, "stage0" )
597
+ config. download_component ( DownloadSource :: Dist , filename, prefix, date, "stage0" ) ;
496
598
} ;
497
599
498
600
self . download_toolchain (
@@ -648,7 +750,7 @@ HELP: if trying to compile an old commit of rustc, disable `download-rustc` in c
648
750
download-rustc = false
649
751
" ;
650
752
}
651
- self . download_file ( & format ! ( "{base_url}/{url}" ) , & tarball, help_on_error) ;
753
+ self . download_file ( & format ! ( "{base_url}/{url}" ) , & tarball, help_on_error, & key . to_string ( ) ) ;
652
754
if let Some ( sha256) = checksum {
653
755
if !self . verify ( & tarball, sha256) {
654
756
panic ! ( "failed to verify {}" , tarball. display( ) ) ;
@@ -726,7 +828,12 @@ download-rustc = false
726
828
[llvm]
727
829
download-ci-llvm = false
728
830
" ;
729
- self . download_file ( & format ! ( "{base}/{llvm_sha}/{filename}" ) , & tarball, help_on_error) ;
831
+ self . download_file (
832
+ & format ! ( "{base}/{llvm_sha}/{filename}" ) ,
833
+ & tarball,
834
+ help_on_error,
835
+ & llvm_sha. to_string ( ) ,
836
+ ) ;
730
837
}
731
838
let llvm_root = self . ci_llvm_root ( ) ;
732
839
self . unpack ( & tarball, & llvm_root, "rust-dev" ) ;
0 commit comments