@@ -6,13 +6,14 @@ use std::{
6
6
path:: { Path , PathBuf } ,
7
7
process:: { Command , Stdio } ,
8
8
sync:: OnceLock ,
9
+ time:: SystemTime ,
9
10
} ;
10
11
11
12
use build_helper:: ci:: CiEnv ;
12
13
use xz2:: bufread:: XzDecoder ;
13
14
14
15
use crate :: core:: config:: RustfmtMetadata ;
15
- use crate :: utils:: helpers:: { check_run, exe, program_out_of_date} ;
16
+ use crate :: utils:: helpers:: { check_run, exe, program_out_of_date, try_output } ;
16
17
use crate :: { core:: build_steps:: llvm:: detect_llvm_sha, utils:: helpers:: hex_encode} ;
17
18
use crate :: { t, Config } ;
18
19
@@ -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 : & str ) {
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 : & str ,
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,59 @@ 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 : & str ) {
275
+ let build_date: String = try_output (
276
+ Command :: new ( "git" )
277
+ . arg ( "show" )
278
+ . arg ( "-s" )
279
+ . arg ( "--format=%ct" ) // Commit date in unix timestamp
280
+ . arg ( commit) ,
281
+ ) ;
282
+ match SystemTime :: now ( ) . duration_since ( SystemTime :: UNIX_EPOCH ) {
283
+ Ok ( n) => {
284
+ let replaced = build_date. trim ( ) ;
285
+ let diff = n. as_secs ( ) - replaced. parse :: < u64 > ( ) . unwrap ( ) ;
286
+ if diff >= 165 * 24 * 60 * 60 {
287
+ let build_date: String = try_output (
288
+ Command :: new ( "git" )
289
+ . arg ( "show" )
290
+ . arg ( "-s" )
291
+ . arg ( "--format=%cr" ) // Commit date in `x days ago` format
292
+ . arg ( commit) ,
293
+ ) ;
294
+ if build_date. is_empty ( ) {
295
+ eprintln ! (
296
+ "NOTE: tried to download builds for {}, CI builds are only retained for 168 days" ,
297
+ commit
298
+ ) ;
299
+ } else {
300
+ eprintln ! (
301
+ "NOTE: tried to download builds for {} (from {}), CI builds are only retained for 168 days" ,
302
+ commit, build_date
303
+ ) ;
304
+ }
305
+ eprintln ! ( "HELP: Consider updating your copy of the rust sources" ) ;
306
+ return ;
307
+ }
308
+ }
309
+ Err ( _) => panic ! ( "SystemTime before UNIX EPOCH!" ) ,
310
+ }
311
+ }
312
+
266
313
fn unpack ( & self , tarball : & Path , dst : & Path , pattern : & str ) {
267
314
eprintln ! ( "extracting {} to {}" , tarball. display( ) , dst. display( ) ) ;
268
315
if !dst. exists ( ) {
@@ -492,7 +539,7 @@ impl Config {
492
539
let extra_components = [ "cargo" ] ;
493
540
494
541
let download_beta_component = |config : & Config , filename, prefix : & _ , date : & _ | {
495
- config. download_component ( DownloadSource :: Dist , filename, prefix, date, "stage0" )
542
+ config. download_component ( DownloadSource :: Dist , filename, prefix, date, "stage0" ) ;
496
543
} ;
497
544
498
545
self . download_toolchain (
@@ -648,7 +695,7 @@ HELP: if trying to compile an old commit of rustc, disable `download-rustc` in c
648
695
download-rustc = false
649
696
" ;
650
697
}
651
- self . download_file ( & format ! ( "{base_url}/{url}" ) , & tarball, help_on_error) ;
698
+ self . download_file ( & format ! ( "{base_url}/{url}" ) , & tarball, help_on_error, & key . to_string ( ) ) ;
652
699
if let Some ( sha256) = checksum {
653
700
if !self . verify ( & tarball, sha256) {
654
701
panic ! ( "failed to verify {}" , tarball. display( ) ) ;
@@ -726,7 +773,12 @@ download-rustc = false
726
773
[llvm]
727
774
download-ci-llvm = false
728
775
" ;
729
- self . download_file ( & format ! ( "{base}/{llvm_sha}/{filename}" ) , & tarball, help_on_error) ;
776
+ self . download_file (
777
+ & format ! ( "{base}/{llvm_sha}/{filename}" ) ,
778
+ & tarball,
779
+ help_on_error,
780
+ & llvm_sha. to_string ( ) ,
781
+ ) ;
730
782
}
731
783
let llvm_root = self . ci_llvm_root ( ) ;
732
784
self . unpack ( & tarball, & llvm_root, "rust-dev" ) ;
0 commit comments