@@ -107,13 +107,13 @@ static MINGW: &'static [&'static str] = &[
107
107
struct Manifest {
108
108
manifest_version : String ,
109
109
date : String ,
110
- git_commit_hash : String ,
111
110
pkg : BTreeMap < String , Package > ,
112
111
}
113
112
114
113
#[ derive( Serialize ) ]
115
114
struct Package {
116
115
version : String ,
116
+ git_commit_hash : Option < String > ,
117
117
target : BTreeMap < String , Target > ,
118
118
}
119
119
@@ -168,6 +168,9 @@ struct Builder {
168
168
rust_version : String ,
169
169
cargo_version : String ,
170
170
rls_version : String ,
171
+ rust_git_commit_hash : Option < String > ,
172
+ cargo_git_commit_hash : Option < String > ,
173
+ rls_git_commit_hash : Option < String > ,
171
174
}
172
175
173
176
fn main ( ) {
@@ -195,6 +198,9 @@ fn main() {
195
198
rust_version : String :: new ( ) ,
196
199
cargo_version : String :: new ( ) ,
197
200
rls_version : String :: new ( ) ,
201
+ rust_git_commit_hash : None ,
202
+ cargo_git_commit_hash : None ,
203
+ rls_git_commit_hash : None ,
198
204
} . build ( ) ;
199
205
}
200
206
@@ -203,6 +209,9 @@ impl Builder {
203
209
self . rust_version = self . version ( "rust" , "x86_64-unknown-linux-gnu" ) ;
204
210
self . cargo_version = self . version ( "cargo" , "x86_64-unknown-linux-gnu" ) ;
205
211
self . rls_version = self . version ( "rls" , "x86_64-unknown-linux-gnu" ) ;
212
+ self . rust_git_commit_hash = self . git_commit_hash ( "rust" , "x86_64-unknown-linux-gnu" ) ;
213
+ self . cargo_git_commit_hash = self . git_commit_hash ( "cargo" , "x86_64-unknown-linux-gnu" ) ;
214
+ self . rls_git_commit_hash = self . git_commit_hash ( "rls" , "x86_64-unknown-linux-gnu" ) ;
206
215
207
216
self . digest_and_sign ( ) ;
208
217
let manifest = self . build_manifest ( ) ;
@@ -226,7 +235,6 @@ impl Builder {
226
235
let mut manifest = Manifest {
227
236
manifest_version : "2" . to_string ( ) ,
228
237
date : self . date . to_string ( ) ,
229
- git_commit_hash : self . git_commit_hash ( "rust" , "x86_64-unknown-linux-gnu" ) ,
230
238
pkg : BTreeMap :: new ( ) ,
231
239
} ;
232
240
@@ -246,6 +254,7 @@ impl Builder {
246
254
247
255
let mut pkg = Package {
248
256
version : self . cached_version ( "rust" ) . to_string ( ) ,
257
+ git_commit_hash : self . cached_git_commit_hash ( "rust" ) . clone ( ) ,
249
258
target : BTreeMap :: new ( ) ,
250
259
} ;
251
260
for host in HOSTS {
@@ -339,6 +348,7 @@ impl Builder {
339
348
340
349
dst. insert ( pkgname. to_string ( ) , Package {
341
350
version : self . cached_version ( pkgname) . to_string ( ) ,
351
+ git_commit_hash : self . cached_git_commit_hash ( pkgname) . clone ( ) ,
342
352
target : targets,
343
353
} ) ;
344
354
}
@@ -372,6 +382,16 @@ impl Builder {
372
382
}
373
383
}
374
384
385
+ fn cached_git_commit_hash ( & self , component : & str ) -> & Option < String > {
386
+ if component == "cargo" {
387
+ & self . cargo_git_commit_hash
388
+ } else if component == "rls" || component == "rls-preview" {
389
+ & self . rls_git_commit_hash
390
+ } else {
391
+ & self . rust_git_commit_hash
392
+ }
393
+ }
394
+
375
395
fn version ( & self , component : & str , target : & str ) -> String {
376
396
let mut cmd = Command :: new ( "tar" ) ;
377
397
let filename = self . filename ( component, target) ;
@@ -389,21 +409,23 @@ impl Builder {
389
409
String :: from_utf8_lossy ( & output. stdout ) . trim ( ) . to_string ( )
390
410
}
391
411
392
- fn git_commit_hash ( & self , component : & str , target : & str ) -> String {
412
+ fn git_commit_hash ( & self , component : & str , target : & str ) -> Option < String > {
393
413
let mut cmd = Command :: new ( "tar" ) ;
394
414
let filename = self . filename ( component, target) ;
395
415
cmd. arg ( "xf" )
396
416
. arg ( self . input . join ( & filename) )
397
417
. arg ( format ! ( "{}/git-commit-hash" , filename. replace( ".tar.gz" , "" ) ) )
398
418
. arg ( "-O" ) ;
399
419
let output = t ! ( cmd. output( ) ) ;
400
- if !output. status . success ( ) {
401
- panic ! ( "failed to learn git commit hash:\n \n {:?}\n \n {}\n \n {}" ,
402
- cmd,
403
- String :: from_utf8_lossy( & output. stdout) ,
404
- String :: from_utf8_lossy( & output. stderr) ) ;
420
+ if output. status . success ( ) {
421
+ Some ( String :: from_utf8_lossy ( & output. stdout ) . trim ( ) . to_string ( ) )
422
+ } else {
423
+ // This is always called after `.version()`.
424
+ // So if that didn’t fail but this does,
425
+ // that’s very probably because the tarball is valid
426
+ // but does not contain a `git-commit-hash` file.
427
+ None
405
428
}
406
- String :: from_utf8_lossy ( & output. stdout ) . trim ( ) . to_string ( )
407
429
}
408
430
409
431
fn hash ( & self , path : & Path ) -> String {
@@ -442,7 +464,8 @@ impl Builder {
442
464
fn write_channel_files ( & self , channel_name : & str , manifest : & Manifest ) {
443
465
self . write ( & toml:: to_string ( & manifest) . unwrap ( ) , channel_name, ".toml" ) ;
444
466
self . write ( & manifest. date , channel_name, "-date.txt" ) ;
445
- self . write ( & manifest. git_commit_hash , channel_name, "-git-commit-hash.txt" ) ;
467
+ self . write ( manifest. pkg [ "rust" ] . git_commit_hash . as_ref ( ) . unwrap ( ) ,
468
+ channel_name, "-git-commit-hash.txt" ) ;
446
469
}
447
470
448
471
fn write ( & self , contents : & str , channel_name : & str , suffix : & str ) {
0 commit comments