1- use std:: env;
21use std:: ffi:: OsStr ;
32use std:: fs:: File ;
43use std:: io:: { self , Write , BufRead , BufReader , Seek , SeekFrom } ;
5- use std:: path:: PathBuf ;
64use std:: process:: { self , Command , Stdio } ;
75use std:: time:: Instant ;
86use regex:: Regex ;
@@ -16,21 +14,19 @@ use telemetry::{Telemetry, TelemetryEvent};
1614
1715
1816pub fn run_command_for_dir < S : AsRef < OsStr > > ( cmd : Command ,
17+ arg0 : & S ,
1918 args : & [ S ] ,
2019 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) ;
2822 }
2923
30- run_command_for_dir_without_telemetry ( cmd, args)
24+ run_command_for_dir_without_telemetry ( cmd, arg0 , args)
3125}
3226
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 < ( ) > {
3430 #[ cfg( unix) ]
3531 fn file_as_stdio ( file : & File ) -> Stdio {
3632 use std:: os:: unix:: io:: { AsRawFd , FromRawFd } ;
@@ -45,7 +41,7 @@ fn telemetry_rustc<S: AsRef<OsStr>>(mut cmd: Command, args: &[S], cfg: &Cfg) ->
4541
4642 let now = Instant :: now ( ) ;
4743
48- cmd. args ( & args[ 1 .. ] ) ;
44+ cmd. args ( args) ;
4945
5046 let has_color_args = args. iter ( ) . any ( |e| {
5147 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) ->
130126 } ) ;
131127
132128 Err ( e) . chain_err ( || rustup_utils:: ErrorKind :: RunningCommand {
133- name : args [ 0 ] . as_ref ( ) . to_owned ( ) ,
129+ name : arg0 . as_ref ( ) . to_owned ( ) ,
134130 } )
135131 } ,
136132 }
137133}
138134
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) ;
141139
142140 // FIXME rust-lang/rust#32254. It's not clear to me
143141 // when and why this is needed.
144142 cmd. stdin ( process:: Stdio :: inherit ( ) ) ;
145143
144+ println ! ( "ARG0 {}" , arg0. as_ref( ) . to_string_lossy( ) ) ;
146145 match cmd. status ( ) {
147146 Ok ( status) => {
148147 // Ensure correct exit code is returned
@@ -151,7 +150,7 @@ fn run_command_for_dir_without_telemetry<S: AsRef<OsStr>>(mut cmd: Command, args
151150 }
152151 Err ( e) => {
153152 Err ( e) . chain_err ( || rustup_utils:: ErrorKind :: RunningCommand {
154- name : args [ 0 ] . as_ref ( ) . to_owned ( ) ,
153+ name : arg0 . as_ref ( ) . to_owned ( ) ,
155154 } )
156155 }
157156 }
0 commit comments