11
11
extern crate toml;
12
12
#[ macro_use]
13
13
extern crate serde_derive;
14
- extern crate serde;
15
14
16
15
use std:: collections:: BTreeMap ;
17
16
use std:: env;
@@ -175,9 +174,9 @@ struct Builder {
175
174
digests : BTreeMap < String , String > ,
176
175
s3_address : String ,
177
176
date : String ,
178
- rust_version : String ,
179
- cargo_version : String ,
180
- rls_version : String ,
177
+ rust_version : Option < String > ,
178
+ cargo_version : Option < String > ,
179
+ rls_version : Option < String > ,
181
180
rust_git_commit_hash : Option < String > ,
182
181
cargo_git_commit_hash : Option < String > ,
183
182
rls_git_commit_hash : Option < String > ,
@@ -205,9 +204,9 @@ fn main() {
205
204
digests : BTreeMap :: new ( ) ,
206
205
s3_address,
207
206
date,
208
- rust_version : String :: new ( ) ,
209
- cargo_version : String :: new ( ) ,
210
- rls_version : String :: new ( ) ,
207
+ rust_version : None ,
208
+ cargo_version : None ,
209
+ rls_version : None ,
211
210
rust_git_commit_hash : None ,
212
211
cargo_git_commit_hash : None ,
213
212
rls_git_commit_hash : None ,
@@ -258,10 +257,17 @@ impl Builder {
258
257
self . package ( "rls-preview" , & mut manifest. pkg , HOSTS ) ;
259
258
self . package ( "rust-analysis" , & mut manifest. pkg , TARGETS ) ;
260
259
261
- manifest. renames . insert ( "rls" . to_owned ( ) , Rename { to : "rls-preview" . to_owned ( ) } ) ;
260
+ let rls_present = manifest. pkg . contains_key ( "rls-preview" ) ;
261
+
262
+ if rls_present {
263
+ manifest. renames . insert ( "rls" . to_owned ( ) , Rename { to : "rls-preview" . to_owned ( ) } ) ;
264
+ }
262
265
263
266
let mut pkg = Package {
264
- version : self . cached_version ( "rust" ) . to_string ( ) ,
267
+ version : self . cached_version ( "rust" )
268
+ . as_ref ( )
269
+ . expect ( "Couldn't find Rust version" )
270
+ . clone ( ) ,
265
271
git_commit_hash : self . cached_git_commit_hash ( "rust" ) . clone ( ) ,
266
272
target : BTreeMap :: new ( ) ,
267
273
} ;
@@ -294,10 +300,12 @@ impl Builder {
294
300
} ) ;
295
301
}
296
302
297
- extensions. push ( Component {
298
- pkg : "rls-preview" . to_string ( ) ,
299
- target : host. to_string ( ) ,
300
- } ) ;
303
+ if rls_present {
304
+ extensions. push ( Component {
305
+ pkg : "rls-preview" . to_string ( ) ,
306
+ target : host. to_string ( ) ,
307
+ } ) ;
308
+ }
301
309
extensions. push ( Component {
302
310
pkg : "rust-analysis" . to_string ( ) ,
303
311
target : host. to_string ( ) ,
@@ -334,6 +342,14 @@ impl Builder {
334
342
pkgname : & str ,
335
343
dst : & mut BTreeMap < String , Package > ,
336
344
targets : & [ & str ] ) {
345
+ let version = match * self . cached_version ( pkgname) {
346
+ Some ( ref version) => version. clone ( ) ,
347
+ None => {
348
+ println ! ( "Skipping package {}" , pkgname) ;
349
+ return ;
350
+ }
351
+ } ;
352
+
337
353
let targets = targets. iter ( ) . map ( |name| {
338
354
let filename = self . filename ( pkgname, name) ;
339
355
let digest = match self . digests . remove ( & filename) {
@@ -355,7 +371,7 @@ impl Builder {
355
371
} ) . collect ( ) ;
356
372
357
373
dst. insert ( pkgname. to_string ( ) , Package {
358
- version : self . cached_version ( pkgname ) . to_string ( ) ,
374
+ version,
359
375
git_commit_hash : self . cached_git_commit_hash ( pkgname) . clone ( ) ,
360
376
target : targets,
361
377
} ) ;
@@ -380,7 +396,7 @@ impl Builder {
380
396
}
381
397
}
382
398
383
- fn cached_version ( & self , component : & str ) -> & str {
399
+ fn cached_version ( & self , component : & str ) -> & Option < String > {
384
400
if component == "cargo" {
385
401
& self . cargo_version
386
402
} else if component == "rls" || component == "rls-preview" {
@@ -400,21 +416,20 @@ impl Builder {
400
416
}
401
417
}
402
418
403
- fn version ( & self , component : & str , target : & str ) -> String {
419
+ fn version ( & self , component : & str , target : & str ) -> Option < String > {
404
420
let mut cmd = Command :: new ( "tar" ) ;
405
421
let filename = self . filename ( component, target) ;
406
422
cmd. arg ( "xf" )
407
423
. arg ( self . input . join ( & filename) )
408
424
. arg ( format ! ( "{}/version" , filename. replace( ".tar.gz" , "" ) ) )
409
425
. arg ( "-O" ) ;
410
426
let output = t ! ( cmd. output( ) ) ;
411
- if ! output. status . success ( ) {
412
- panic ! ( "failed to learn version: \n \n {:?} \n \n {} \n \n {}" ,
413
- cmd ,
414
- String :: from_utf8_lossy ( & output . stdout ) ,
415
- String :: from_utf8_lossy ( & output . stderr ) ) ;
427
+ if output. status . success ( ) {
428
+ Some ( String :: from_utf8_lossy ( & output . stdout ) . trim ( ) . to_string ( ) )
429
+ } else {
430
+ // Perhaps we didn't build this package.
431
+ None
416
432
}
417
- String :: from_utf8_lossy ( & output. stdout ) . trim ( ) . to_string ( )
418
433
}
419
434
420
435
fn git_commit_hash ( & self , component : & str , target : & str ) -> Option < String > {
@@ -428,10 +443,6 @@ impl Builder {
428
443
if output. status . success ( ) {
429
444
Some ( String :: from_utf8_lossy ( & output. stdout ) . trim ( ) . to_string ( ) )
430
445
} else {
431
- // This is always called after `.version()`.
432
- // So if that didn’t fail but this does,
433
- // that’s very probably because the tarball is valid
434
- // but does not contain a `git-commit-hash` file.
435
446
None
436
447
}
437
448
}
0 commit comments