22
33use std:: collections:: hash_map:: { Entry , HashMap } ;
44use std:: env;
5- use std:: ffi:: { OsStr , OsString } ;
65use std:: hash:: { Hash , Hasher , SipHasher } ;
76use std:: path:: { Path , PathBuf } ;
87use std:: process:: Stdio ;
@@ -21,64 +20,14 @@ pub struct Rustc {
2120 pub path : PathBuf ,
2221 /// An optional program that will be passed the path of the rust exe as its first argument, and
2322 /// rustc args following this.
24- pub wrapper : Option < RustcWrapper > ,
23+ pub wrapper : Option < ProcessBuilder > ,
2524 /// Verbose version information (the output of `rustc -vV`)
2625 pub verbose_version : String ,
2726 /// The host triple (arch-platform-OS), this comes from verbose_version.
2827 pub host : String ,
2928 cache : Mutex < Cache > ,
3029}
3130
32- /// Information on the `rustc` wrapper
33- #[ derive( Debug ) ]
34- pub struct RustcWrapper {
35- path : PathBuf ,
36- env : HashMap < String , Option < OsString > > ,
37- }
38-
39- impl RustcWrapper {
40- pub fn new < T : Into < PathBuf > > ( path : T ) -> RustcWrapper {
41- RustcWrapper {
42- path : path. into ( ) ,
43- env : HashMap :: new ( ) ,
44- }
45- }
46-
47- /// (chainable) Sets an environment variable for the process.
48- pub fn env < T : AsRef < OsStr > > ( & mut self , key : & str , val : T ) -> & mut RustcWrapper {
49- self . env
50- . insert ( key. to_string ( ) , Some ( val. as_ref ( ) . to_os_string ( ) ) ) ;
51- self
52- }
53-
54- /// (chainable) Unsets an environment variable for the process.
55- pub fn env_remove ( & mut self , key : & str ) -> & mut RustcWrapper {
56- self . env . insert ( key. to_string ( ) , None ) ;
57- self
58- }
59-
60- pub fn process ( & self ) -> ProcessBuilder {
61- let mut cmd = util:: process ( & self . path ) ;
62-
63- for ( k, v) in & self . env {
64- match * v {
65- Some ( ref v) => {
66- cmd. env ( k, v) ;
67- }
68- None => {
69- cmd. env_remove ( k) ;
70- }
71- }
72- }
73-
74- cmd
75- }
76-
77- pub fn is_empty ( & self ) -> bool {
78- self . path . as_os_str ( ) . is_empty ( )
79- }
80- }
81-
8231impl Rustc {
8332 /// Runs the compiler at `path` to learn various pieces of information about
8433 /// it, with an optional wrapper.
@@ -110,7 +59,7 @@ impl Rustc {
11059
11160 Ok ( Rustc {
11261 path,
113- wrapper : wrapper. map ( RustcWrapper :: new ) ,
62+ wrapper : wrapper. map ( util :: process ) ,
11463 verbose_version,
11564 host,
11665 cache : Mutex :: new ( cache) ,
@@ -120,8 +69,8 @@ impl Rustc {
12069 /// Gets a process builder set up to use the found rustc version, with a wrapper if `Some`.
12170 pub fn process ( & self ) -> ProcessBuilder {
12271 match self . wrapper {
123- Some ( ref wrapper) if !wrapper. is_empty ( ) => {
124- let mut cmd = wrapper. process ( ) ;
72+ Some ( ref wrapper) if !wrapper. get_program ( ) . is_empty ( ) => {
73+ let mut cmd = wrapper. clone ( ) ;
12574 cmd. arg ( & self . path ) ;
12675 cmd
12776 }
@@ -141,8 +90,8 @@ impl Rustc {
14190 self . cache . lock ( ) . unwrap ( ) . cached_success ( cmd)
14291 }
14392
144- pub fn push_wrapper < T : Into < Option < RustcWrapper > > > ( & mut self , wrapper : T ) {
145- self . wrapper = wrapper . into ( ) ;
93+ pub fn set_wrapper ( & mut self , wrapper : ProcessBuilder ) {
94+ self . wrapper = Some ( wrapper ) ;
14695 }
14796}
14897
0 commit comments