File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed
Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ use cargo_test_support::{
2020 thread_wait_timeout, Execs , Project ,
2121} ;
2222use itertools:: Itertools ;
23+ use std:: env;
2324use std:: fmt:: Write ;
2425use std:: path:: Path ;
2526use std:: path:: PathBuf ;
@@ -169,12 +170,19 @@ fn populate_cache(
169170 ( cache_dir, src_dir)
170171}
171172
173+ /// Returns an `Execs` that will run the rustup `cargo` proxy from the global
174+ /// system's cargo home directory.
172175fn rustup_cargo ( ) -> Execs {
173- // Get the path to the rustup cargo wrapper. This is necessary because
174- // cargo adds the "deps" directory into PATH on Windows, which points to
175- // the wrong cargo.
176- let rustup_cargo = Path :: new ( & std:: env:: var_os ( "CARGO_HOME" ) . unwrap ( ) ) . join ( "bin/cargo" ) ;
177- execs ( ) . with_process_builder ( process ( rustup_cargo) )
176+ // Modify the PATH to ensure that `cargo` and `rustc` comes from
177+ // CARGO_HOME. This is necessary because cargo adds the "deps" directory
178+ // into PATH on Windows, which points to the wrong cargo.
179+ let real_cargo_home_bin = Path :: new ( & std:: env:: var_os ( "CARGO_HOME" ) . unwrap ( ) ) . join ( "bin" ) ;
180+ let mut paths = vec ! [ real_cargo_home_bin] ;
181+ paths. extend ( env:: split_paths ( & env:: var_os ( "PATH" ) . unwrap_or_default ( ) ) ) ;
182+ let path = env:: join_paths ( paths) . unwrap ( ) ;
183+ let mut e = execs ( ) . with_process_builder ( process ( "cargo" ) ) ;
184+ e. env ( "PATH" , path) ;
185+ e
178186}
179187
180188#[ cargo_test]
You can’t perform that action at this time.
0 commit comments