@@ -15,7 +15,6 @@ use std::io::Write;
15
15
use std:: process:: ExitStatus ;
16
16
use std:: { env, io, process} ;
17
17
18
- use error_chain:: bail;
19
18
use toml:: { Value , value:: Table } ;
20
19
21
20
use self :: cargo:: { Root , Subcommand } ;
@@ -363,38 +362,44 @@ impl Toml {
363
362
/// Returns the list of environment variables to pass through for `target`,
364
363
/// including variables specified under `build` and under `target`.
365
364
pub fn env_passthrough ( & self , target : & Target ) -> Result < Vec < & str > > {
366
- let mut bwl = self . build_env_passthrough ( ) ?;
367
- let mut twl = self . target_env_passthrough ( target) ?;
365
+ let mut bwl = self . build_env ( "passthrough" ) ?;
366
+ let mut twl = self . target_env ( target, "passthrough" ) ?;
368
367
bwl. extend ( twl. drain ( ..) ) ;
369
368
370
369
Ok ( bwl)
371
370
}
372
371
373
- /// Returns the `build.env.passthrough` part of `Cross.toml`
374
- fn build_env_passthrough ( & self ) -> Result < Vec < & str > > {
375
- match self . table . get ( "build" ) . and_then ( |b| b. get ( "env" ) ) . and_then ( |e| e. get ( "passthrough" ) ) {
372
+ /// Returns the list of volumes to pass through for `target`,
373
+ /// including volumes specified under `build` and under `target`.
374
+ pub fn env_volumes ( & self , target : & Target ) -> Result < Vec < & str > > {
375
+ let mut bwl = self . build_env ( "volumes" ) ?;
376
+ let mut twl = self . target_env ( target, "volumes" ) ?;
377
+ bwl. extend ( twl. drain ( ..) ) ;
378
+
379
+ Ok ( bwl)
380
+ }
381
+
382
+ fn target_env ( & self , target : & Target , key : & str ) -> Result < Vec < & str > > {
383
+ let triple = target. triple ( ) ;
384
+
385
+ match self . table . get ( "target" ) . and_then ( |t| t. get ( triple) ) . and_then ( |t| t. get ( "env" ) ) . and_then ( |e| e. get ( key) ) {
376
386
Some ( & Value :: Array ( ref vec) ) => {
377
- if vec. iter ( ) . any ( |val| val. as_str ( ) . is_none ( ) ) {
378
- bail ! ( "every build.env.passthrough element must be a string" ) ;
379
- }
380
- Ok ( vec. iter ( ) . map ( |val| val. as_str ( ) . unwrap ( ) ) . collect ( ) )
387
+ vec. iter ( ) . map ( |val| {
388
+ val. as_str ( ) . ok_or_else ( || {
389
+ format ! ( "every target.{}.env.{} element must be a string" , triple, key) . into ( )
390
+ } )
391
+ } ) . collect ( )
381
392
} ,
382
393
_ => Ok ( Vec :: new ( ) ) ,
383
394
}
384
395
}
385
396
386
- /// Returns the `target.<triple>.env.passthrough` part of `Cross.toml` for `target`.
387
- fn target_env_passthrough ( & self , target : & Target ) -> Result < Vec < & str > > {
388
- let triple = target. triple ( ) ;
389
-
390
- let key = format ! ( "target.{}.env.passthrough" , triple) ;
391
-
392
- match self . table . get ( "target" ) . and_then ( |t| t. get ( triple) ) . and_then ( |t| t. get ( "env" ) ) . and_then ( |e| e. get ( "passthrough" ) ) {
397
+ fn build_env ( & self , key : & str ) -> Result < Vec < & str > > {
398
+ match self . table . get ( "build" ) . and_then ( |b| b. get ( "env" ) ) . and_then ( |e| e. get ( key) ) {
393
399
Some ( & Value :: Array ( ref vec) ) => {
394
- if vec. iter ( ) . any ( |val| val. as_str ( ) . is_none ( ) ) {
395
- bail ! ( "every {} element must be a string" , key) ;
396
- }
397
- Ok ( vec. iter ( ) . map ( |val| val. as_str ( ) . unwrap ( ) ) . collect ( ) )
400
+ vec. iter ( ) . map ( |val| {
401
+ val. as_str ( ) . ok_or_else ( || format ! ( "every build.env.{} element must be a string" , key) . into ( ) )
402
+ } ) . collect ( )
398
403
} ,
399
404
_ => Ok ( Vec :: new ( ) ) ,
400
405
}
0 commit comments