@@ -30,6 +30,7 @@ use util::fs::fix_windows_verbatim_for_gcc;
3030use rustc_back:: tempdir:: TempDir ;
3131
3232use std:: env;
33+ use std:: ffi:: OsString ;
3334use std:: fs:: { self , PathExt } ;
3435use std:: io:: { self , Read , Write } ;
3536use std:: mem;
@@ -370,6 +371,17 @@ pub fn get_ar_prog(sess: &Session) -> String {
370371 } )
371372}
372373
374+ fn command_path ( sess : & Session ) -> OsString {
375+ // The compiler's sysroot often has some bundled tools, so add it to the
376+ // PATH for the child.
377+ let mut new_path = sess. host_filesearch ( PathKind :: All )
378+ . get_tools_search_paths ( ) ;
379+ if let Some ( path) = env:: var_os ( "PATH" ) {
380+ new_path. extend ( env:: split_paths ( & path) ) ;
381+ }
382+ env:: join_paths ( new_path) . unwrap ( )
383+ }
384+
373385pub fn remove ( sess : & Session , path : & Path ) {
374386 match fs:: remove_file ( path) {
375387 Ok ( ..) => { }
@@ -554,6 +566,7 @@ fn link_rlib<'a>(sess: &'a Session,
554566 slib_prefix : sess. target . target . options . staticlib_prefix . clone ( ) ,
555567 slib_suffix : sess. target . target . options . staticlib_suffix . clone ( ) ,
556568 ar_prog : get_ar_prog ( sess) ,
569+ command_path : command_path ( sess) ,
557570 } ;
558571 let mut ab = ArchiveBuilder :: create ( config) ;
559572 ab. add_file ( obj_filename) . unwrap ( ) ;
@@ -796,15 +809,7 @@ fn link_natively(sess: &Session, trans: &CrateTranslation, dylib: bool,
796809 // The invocations of cc share some flags across platforms
797810 let pname = get_cc_prog ( sess) ;
798811 let mut cmd = Command :: new ( & pname) ;
799-
800- // The compiler's sysroot often has some bundled tools, so add it to the
801- // PATH for the child.
802- let mut new_path = sess. host_filesearch ( PathKind :: All )
803- . get_tools_search_paths ( ) ;
804- if let Some ( path) = env:: var_os ( "PATH" ) {
805- new_path. extend ( env:: split_paths ( & path) ) ;
806- }
807- cmd. env ( "PATH" , env:: join_paths ( new_path) . unwrap ( ) ) ;
812+ cmd. env ( "PATH" , command_path ( sess) ) ;
808813
809814 let root = sess. target_filesearch ( PathKind :: Native ) . get_lib_path ( ) ;
810815 cmd. args ( & sess. target . target . options . pre_link_args ) ;
@@ -1187,6 +1192,7 @@ fn add_upstream_rust_crates(cmd: &mut Linker, sess: &Session,
11871192 slib_prefix : sess. target . target . options . staticlib_prefix . clone ( ) ,
11881193 slib_suffix : sess. target . target . options . staticlib_suffix . clone ( ) ,
11891194 ar_prog : get_ar_prog ( sess) ,
1195+ command_path : command_path ( sess) ,
11901196 } ;
11911197 let mut archive = Archive :: open ( config) ;
11921198 archive. remove_file ( & format ! ( "{}.o" , name) ) ;
0 commit comments