1
- use std:: env;
2
1
use std:: ffi:: OsStr ;
3
2
use std:: fs:: File ;
4
3
use std:: io:: { self , Write , BufRead , BufReader , Seek , SeekFrom } ;
5
- use std:: path:: PathBuf ;
6
4
use std:: process:: { self , Command , Stdio } ;
7
5
use std:: time:: Instant ;
8
6
use regex:: Regex ;
@@ -16,21 +14,19 @@ use telemetry::{Telemetry, TelemetryEvent};
16
14
17
15
18
16
pub fn run_command_for_dir < S : AsRef < OsStr > > ( cmd : Command ,
17
+ arg0 : & S ,
19
18
args : & [ S ] ,
20
19
cfg : & Cfg ) -> Result < ( ) > {
21
- let arg0 = env:: args ( ) . next ( ) . map ( PathBuf :: from) ;
22
- let arg0 = arg0. as_ref ( )
23
- . and_then ( |a| a. file_name ( ) )
24
- . and_then ( |a| a. to_str ( ) ) ;
25
- let arg0 = try!( arg0. ok_or ( ErrorKind :: NoExeName ) ) ;
26
- if ( arg0 == "rustc" || arg0 == "rustc.exe" ) && try!( cfg. telemetry_enabled ( ) ) {
27
- return telemetry_rustc ( cmd, args, cfg) ;
20
+ if ( arg0. as_ref ( ) == "rustc" || arg0. as_ref ( ) == "rustc.exe" ) && try!( cfg. telemetry_enabled ( ) ) {
21
+ return telemetry_rustc ( cmd, arg0, args, cfg) ;
28
22
}
29
23
30
- run_command_for_dir_without_telemetry ( cmd, args)
24
+ run_command_for_dir_without_telemetry ( cmd, arg0 , args)
31
25
}
32
26
33
- fn telemetry_rustc < S : AsRef < OsStr > > ( mut cmd : Command , args : & [ S ] , cfg : & Cfg ) -> Result < ( ) > {
27
+ fn telemetry_rustc < S : AsRef < OsStr > > ( mut cmd : Command ,
28
+ arg0 : & S ,
29
+ args : & [ S ] , cfg : & Cfg ) -> Result < ( ) > {
34
30
#[ cfg( unix) ]
35
31
fn file_as_stdio ( file : & File ) -> Stdio {
36
32
use std:: os:: unix:: io:: { AsRawFd , FromRawFd } ;
@@ -45,7 +41,7 @@ fn telemetry_rustc<S: AsRef<OsStr>>(mut cmd: Command, args: &[S], cfg: &Cfg) ->
45
41
46
42
let now = Instant :: now ( ) ;
47
43
48
- cmd. args ( & args[ 1 .. ] ) ;
44
+ cmd. args ( args) ;
49
45
50
46
let has_color_args = args. iter ( ) . any ( |e| {
51
47
let e = e. as_ref ( ) . to_str ( ) . unwrap_or ( "" ) ;
@@ -130,19 +126,22 @@ fn telemetry_rustc<S: AsRef<OsStr>>(mut cmd: Command, args: &[S], cfg: &Cfg) ->
130
126
} ) ;
131
127
132
128
Err ( e) . chain_err ( || rustup_utils:: ErrorKind :: RunningCommand {
133
- name : args [ 0 ] . as_ref ( ) . to_owned ( ) ,
129
+ name : arg0 . as_ref ( ) . to_owned ( ) ,
134
130
} )
135
131
} ,
136
132
}
137
133
}
138
134
139
- fn run_command_for_dir_without_telemetry < S : AsRef < OsStr > > ( mut cmd : Command , args : & [ S ] ) -> Result < ( ) > {
140
- cmd. args ( & args[ 1 ..] ) ;
135
+ fn run_command_for_dir_without_telemetry < S : AsRef < OsStr > > (
136
+ mut cmd : Command , arg0 : & S , args : & [ S ] ) -> Result < ( ) >
137
+ {
138
+ cmd. args ( & args) ;
141
139
142
140
// FIXME rust-lang/rust#32254. It's not clear to me
143
141
// when and why this is needed.
144
142
cmd. stdin ( process:: Stdio :: inherit ( ) ) ;
145
143
144
+ println ! ( "ARG0 {}" , arg0. as_ref( ) . to_string_lossy( ) ) ;
146
145
match cmd. status ( ) {
147
146
Ok ( status) => {
148
147
// Ensure correct exit code is returned
@@ -151,7 +150,7 @@ fn run_command_for_dir_without_telemetry<S: AsRef<OsStr>>(mut cmd: Command, args
151
150
}
152
151
Err ( e) => {
153
152
Err ( e) . chain_err ( || rustup_utils:: ErrorKind :: RunningCommand {
154
- name : args [ 0 ] . as_ref ( ) . to_owned ( ) ,
153
+ name : arg0 . as_ref ( ) . to_owned ( ) ,
155
154
} )
156
155
}
157
156
}
0 commit comments