@@ -113,6 +113,7 @@ struct Manifest {
113
113
#[ derive( Serialize ) ]
114
114
struct Package {
115
115
version : String ,
116
+ git_commit_hash : Option < String > ,
116
117
target : BTreeMap < String , Target > ,
117
118
}
118
119
@@ -167,6 +168,9 @@ struct Builder {
167
168
rust_version : String ,
168
169
cargo_version : String ,
169
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 > ,
170
174
}
171
175
172
176
fn main ( ) {
@@ -194,6 +198,9 @@ fn main() {
194
198
rust_version : String :: new ( ) ,
195
199
cargo_version : String :: new ( ) ,
196
200
rls_version : String :: new ( ) ,
201
+ rust_git_commit_hash : None ,
202
+ cargo_git_commit_hash : None ,
203
+ rls_git_commit_hash : None ,
197
204
} . build ( ) ;
198
205
}
199
206
@@ -202,18 +209,16 @@ impl Builder {
202
209
self . rust_version = self . version ( "rust" , "x86_64-unknown-linux-gnu" ) ;
203
210
self . cargo_version = self . version ( "cargo" , "x86_64-unknown-linux-gnu" ) ;
204
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" ) ;
205
215
206
216
self . digest_and_sign ( ) ;
207
217
let manifest = self . build_manifest ( ) ;
208
- let filename = format ! ( "channel-rust-{}.toml" , self . rust_release) ;
209
- self . write_manifest ( & toml:: to_string ( & manifest) . unwrap ( ) , & filename) ;
210
-
211
- let filename = format ! ( "channel-rust-{}-date.txt" , self . rust_release) ;
212
- self . write_date_stamp ( & manifest. date , & filename) ;
218
+ self . write_channel_files ( & self . rust_release , & manifest) ;
213
219
214
220
if self . rust_release != "beta" && self . rust_release != "nightly" {
215
- self . write_manifest ( & toml:: to_string ( & manifest) . unwrap ( ) , "channel-rust-stable.toml" ) ;
216
- self . write_date_stamp ( & manifest. date , "channel-rust-stable-date.txt" ) ;
221
+ self . write_channel_files ( "stable" , & manifest) ;
217
222
}
218
223
}
219
224
@@ -249,6 +254,7 @@ impl Builder {
249
254
250
255
let mut pkg = Package {
251
256
version : self . cached_version ( "rust" ) . to_string ( ) ,
257
+ git_commit_hash : self . cached_git_commit_hash ( "rust" ) . clone ( ) ,
252
258
target : BTreeMap :: new ( ) ,
253
259
} ;
254
260
for host in HOSTS {
@@ -342,6 +348,7 @@ impl Builder {
342
348
343
349
dst. insert ( pkgname. to_string ( ) , Package {
344
350
version : self . cached_version ( pkgname) . to_string ( ) ,
351
+ git_commit_hash : self . cached_git_commit_hash ( pkgname) . clone ( ) ,
345
352
target : targets,
346
353
} ) ;
347
354
}
@@ -375,21 +382,50 @@ impl Builder {
375
382
}
376
383
}
377
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
+
378
395
fn version ( & self , component : & str , target : & str ) -> String {
379
396
let mut cmd = Command :: new ( "tar" ) ;
380
397
let filename = self . filename ( component, target) ;
381
398
cmd. arg ( "xf" )
382
399
. arg ( self . input . join ( & filename) )
383
400
. arg ( format ! ( "{}/version" , filename. replace( ".tar.gz" , "" ) ) )
384
401
. arg ( "-O" ) ;
385
- let version = t ! ( cmd. output( ) ) ;
386
- if !version . status . success ( ) {
402
+ let output = t ! ( cmd. output( ) ) ;
403
+ if !output . status . success ( ) {
387
404
panic ! ( "failed to learn version:\n \n {:?}\n \n {}\n \n {}" ,
388
405
cmd,
389
- String :: from_utf8_lossy( & version. stdout) ,
390
- String :: from_utf8_lossy( & version. stderr) ) ;
406
+ String :: from_utf8_lossy( & output. stdout) ,
407
+ String :: from_utf8_lossy( & output. stderr) ) ;
408
+ }
409
+ String :: from_utf8_lossy ( & output. stdout ) . trim ( ) . to_string ( )
410
+ }
411
+
412
+ fn git_commit_hash ( & self , component : & str , target : & str ) -> Option < String > {
413
+ let mut cmd = Command :: new ( "tar" ) ;
414
+ let filename = self . filename ( component, target) ;
415
+ cmd. arg ( "xf" )
416
+ . arg ( self . input . join ( & filename) )
417
+ . arg ( format ! ( "{}/git-commit-hash" , filename. replace( ".tar.gz" , "" ) ) )
418
+ . arg ( "-O" ) ;
419
+ let output = t ! ( cmd. output( ) ) ;
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
391
428
}
392
- String :: from_utf8_lossy ( & version. stdout ) . trim ( ) . to_string ( )
393
429
}
394
430
395
431
fn hash ( & self , path : & Path ) -> String {
@@ -425,16 +461,16 @@ impl Builder {
425
461
assert ! ( t!( child. wait( ) ) . success( ) ) ;
426
462
}
427
463
428
- fn write_manifest ( & self , manifest : & str , name : & str ) {
429
- let dst = self . output . join ( name ) ;
430
- t ! ( t! ( File :: create ( & dst ) ) . write_all ( manifest. as_bytes ( ) ) ) ;
431
- self . hash ( & dst ) ;
432
- self . sign ( & dst ) ;
464
+ fn write_channel_files ( & self , channel_name : & str , manifest : & Manifest ) {
465
+ self . write ( & toml :: to_string ( & manifest ) . unwrap ( ) , channel_name , ".toml" ) ;
466
+ self . write ( & manifest. date , channel_name , "-date.txt" ) ;
467
+ self . write ( manifest . pkg [ "rust" ] . git_commit_hash . as_ref ( ) . unwrap ( ) ,
468
+ channel_name , "-git-commit-hash.txt" ) ;
433
469
}
434
470
435
- fn write_date_stamp ( & self , date : & str , name : & str ) {
436
- let dst = self . output . join ( name ) ;
437
- t ! ( t!( File :: create( & dst) ) . write_all( date . as_bytes( ) ) ) ;
471
+ fn write ( & self , contents : & str , channel_name : & str , suffix : & str ) {
472
+ let dst = self . output . join ( format ! ( "channel-rust-{}{}" , channel_name , suffix ) ) ;
473
+ t ! ( t!( File :: create( & dst) ) . write_all( contents . as_bytes( ) ) ) ;
438
474
self . hash ( & dst) ;
439
475
self . sign ( & dst) ;
440
476
}
0 commit comments