@@ -2,10 +2,12 @@ use std::collections::HashMap;
2
2
use std:: ffi:: OsStr ;
3
3
use std:: path:: PathBuf ;
4
4
5
+ #[ cfg( unix) ]
6
+ use std:: os:: unix:: process:: CommandExt ;
7
+
5
8
use crate :: config:: ConfigInfo ;
6
9
use crate :: utils:: {
7
- get_toolchain, run_command_with_output_and_env_no_err, rustc_toolchain_version_info,
8
- rustc_version_info,
10
+ get_toolchain, rustc_toolchain_version_info, rustc_version_info,
9
11
} ;
10
12
11
13
fn args ( command : & str ) -> Result < Option < Vec < String > > , String > {
@@ -97,6 +99,22 @@ impl RustcTools {
97
99
}
98
100
}
99
101
102
+ fn exec ( input : & [ & dyn AsRef < OsStr > ] , env : & HashMap < String , String > ) -> Result < ( ) , String > {
103
+ #[ cfg( unix) ]
104
+ {
105
+ let error = crate :: utils:: get_command_inner ( input, None , Some ( env) ) . exec ( ) ;
106
+ eprintln ! ( "Command failed: {error:?}" ) ;
107
+ std:: process:: exit ( 1 ) ;
108
+ }
109
+ #[ cfg( not( unix) ) ]
110
+ {
111
+ if crate :: utils:: run_command_with_output_and_env_no_err ( input, None , Some ( env) ) . is_err ( ) {
112
+ std:: process:: exit ( 1 ) ;
113
+ }
114
+ Ok ( ( ) )
115
+ }
116
+ }
117
+
100
118
pub fn run_cargo ( ) -> Result < ( ) , String > {
101
119
let Some ( mut tools) = RustcTools :: new ( "cargo" ) ? else { return Ok ( ( ) ) } ;
102
120
let rustflags = tools. env . get ( "RUSTFLAGS" ) . cloned ( ) . unwrap_or_default ( ) ;
@@ -105,11 +123,7 @@ pub fn run_cargo() -> Result<(), String> {
105
123
for arg in & tools. args {
106
124
command. push ( arg) ;
107
125
}
108
- if run_command_with_output_and_env_no_err ( & command, None , Some ( & tools. env ) ) . is_err ( ) {
109
- std:: process:: exit ( 1 ) ;
110
- }
111
-
112
- Ok ( ( ) )
126
+ exec ( & command, & tools. env )
113
127
}
114
128
115
129
pub fn run_rustc ( ) -> Result < ( ) , String > {
@@ -118,8 +132,5 @@ pub fn run_rustc() -> Result<(), String> {
118
132
for arg in & tools. args {
119
133
command. push ( arg) ;
120
134
}
121
- if run_command_with_output_and_env_no_err ( & command, None , Some ( & tools. env ) ) . is_err ( ) {
122
- std:: process:: exit ( 1 ) ;
123
- }
124
- Ok ( ( ) )
135
+ exec ( & command, & tools. env )
125
136
}
0 commit comments