2
2
3
3
use std:: collections:: hash_map:: { Entry , HashMap } ;
4
4
use std:: env;
5
- use std:: ffi:: { OsStr , OsString } ;
6
5
use std:: hash:: { Hash , Hasher , SipHasher } ;
7
6
use std:: path:: { Path , PathBuf } ;
8
7
use std:: process:: Stdio ;
@@ -21,64 +20,14 @@ pub struct Rustc {
21
20
pub path : PathBuf ,
22
21
/// An optional program that will be passed the path of the rust exe as its first argument, and
23
22
/// rustc args following this.
24
- pub wrapper : Option < RustcWrapper > ,
23
+ pub wrapper : Option < ProcessBuilder > ,
25
24
/// Verbose version information (the output of `rustc -vV`)
26
25
pub verbose_version : String ,
27
26
/// The host triple (arch-platform-OS), this comes from verbose_version.
28
27
pub host : String ,
29
28
cache : Mutex < Cache > ,
30
29
}
31
30
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
-
82
31
impl Rustc {
83
32
/// Runs the compiler at `path` to learn various pieces of information about
84
33
/// it, with an optional wrapper.
@@ -110,7 +59,7 @@ impl Rustc {
110
59
111
60
Ok ( Rustc {
112
61
path,
113
- wrapper : wrapper. map ( RustcWrapper :: new ) ,
62
+ wrapper : wrapper. map ( util :: process ) ,
114
63
verbose_version,
115
64
host,
116
65
cache : Mutex :: new ( cache) ,
@@ -120,8 +69,8 @@ impl Rustc {
120
69
/// Gets a process builder set up to use the found rustc version, with a wrapper if `Some`.
121
70
pub fn process ( & self ) -> ProcessBuilder {
122
71
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 ( ) ;
125
74
cmd. arg ( & self . path ) ;
126
75
cmd
127
76
}
@@ -141,8 +90,8 @@ impl Rustc {
141
90
self . cache . lock ( ) . unwrap ( ) . cached_success ( cmd)
142
91
}
143
92
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 ) ;
146
95
}
147
96
}
148
97
0 commit comments