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