@@ -54,7 +54,7 @@ use std::cell::{RefCell, RefMut};
54
54
use std:: collections:: hash_map:: Entry :: { Occupied , Vacant } ;
55
55
use std:: collections:: { HashMap , HashSet } ;
56
56
use std:: env;
57
- use std:: ffi:: { OsStr , OsString } ;
57
+ use std:: ffi:: OsStr ;
58
58
use std:: fmt;
59
59
use std:: fs:: { self , File } ;
60
60
use std:: io:: prelude:: * ;
@@ -765,14 +765,24 @@ impl Config {
765
765
}
766
766
}
767
767
768
- /// Wrapper around `std::env::var`.
769
- pub fn get_env ( & self , key : impl AsRef < OsStr > ) -> CargoResult < String > {
770
- Ok ( std:: env:: var ( key) ?)
768
+ /// Get the value of environment variable `key` through the `Config` snapshot.
769
+ ///
770
+ /// This can be used similarly to `std::env::var`.
771
+ pub fn get_env ( & self , key : impl AsRef < str > ) -> CargoResult < String > {
772
+ match self . env . get ( key. as_ref ( ) ) {
773
+ Some ( s) => Ok ( s. clone ( ) ) ,
774
+ None => bail ! (
775
+ "{} could not be found in the environment snapshot" ,
776
+ key. as_ref( )
777
+ ) ,
778
+ }
771
779
}
772
780
773
- /// Wrapper around `std::env::var`.
774
- pub fn get_env_os ( & self , key : impl AsRef < OsStr > ) -> Option < OsString > {
775
- std:: env:: var_os ( key)
781
+ /// Get the value of environment variable `key` through the `Config` snapshot.
782
+ ///
783
+ /// This can be used similarly to `std::env::var_os`.
784
+ pub fn get_env_os ( & self , key : impl AsRef < str > ) -> Option < String > {
785
+ self . env . get ( key. as_ref ( ) ) . cloned ( )
776
786
}
777
787
778
788
/// Check if the [`Config`] contains a given [`ConfigKey`].
@@ -1629,10 +1639,7 @@ impl Config {
1629
1639
1630
1640
match self . get_env_os ( & var) {
1631
1641
Some ( tool_path) => {
1632
- let maybe_relative = match tool_path. to_str ( ) {
1633
- Some ( s) => s. contains ( '/' ) || s. contains ( '\\' ) ,
1634
- None => false ,
1635
- } ;
1642
+ let maybe_relative = tool_path. contains ( '/' ) || tool_path. contains ( '\\' ) ;
1636
1643
let path = if maybe_relative {
1637
1644
self . cwd . join ( tool_path)
1638
1645
} else {
0 commit comments