@@ -14,11 +14,12 @@ use cargo::GlobalContext;
1414use cargo_test_support:: paths:: { self , CargoPathExt } ;
1515use cargo_test_support:: registry:: { Package , RegistryBuilder } ;
1616use cargo_test_support:: {
17- basic_manifest, cargo_process, execs, git, project, retry, sleep_ms, thread_wait_timeout ,
18- Project ,
17+ basic_manifest, cargo_process, execs, git, process , project, retry, sleep_ms,
18+ thread_wait_timeout , Execs , Project ,
1919} ;
2020use itertools:: Itertools ;
2121use std:: fmt:: Write ;
22+ use std:: path:: Path ;
2223use std:: path:: PathBuf ;
2324use std:: process:: Stdio ;
2425use std:: time:: { Duration , SystemTime } ;
@@ -153,6 +154,14 @@ fn populate_cache(
153154 ( cache_dir, src_dir)
154155}
155156
157+ fn rustup_cargo ( ) -> Execs {
158+ // Get the path to the rustup cargo wrapper. This is necessary because
159+ // cargo adds the "deps" directory into PATH on Windows, which points to
160+ // the wrong cargo.
161+ let rustup_cargo = Path :: new ( & std:: env:: var_os ( "CARGO_HOME" ) . unwrap ( ) ) . join ( "bin/cargo" ) ;
162+ execs ( ) . with_process_builder ( process ( rustup_cargo) )
163+ }
164+
156165#[ cargo_test]
157166fn auto_gc_gated ( ) {
158167 // Requires -Zgc to both track last-use data and to run auto-gc.
@@ -1915,12 +1924,11 @@ fn compatible_with_older_cargo() {
19151924 middle = "1.0"
19161925 "# ,
19171926 ) ;
1918- p . process ( "cargo" )
1927+ rustup_cargo ( )
19191928 . args ( & [ "+stable" , "check" , "-Zgc" ] )
1929+ . cwd ( p. root ( ) )
19201930 . masquerade_as_nightly_cargo ( & [ "gc" ] )
19211931 . env ( "__CARGO_TEST_LAST_USE_NOW" , months_ago_unix ( 2 ) )
1922- // Necessary since `process` removes rustup.
1923- . env ( "PATH" , std:: env:: var_os ( "PATH" ) . unwrap ( ) )
19241932 . run ( ) ;
19251933 assert_eq ! ( get_registry_names( "src" ) , [ "middle-1.0.0" , "new-1.0.0" ] ) ;
19261934 assert_eq ! (
@@ -1978,11 +1986,10 @@ fn forward_compatible() {
19781986 . file ( "src/lib.rs" , "" )
19791987 . build ( ) ;
19801988
1981- p . process ( "cargo" )
1989+ rustup_cargo ( )
19821990 . args ( & [ "+stable" , "check" , "-Zgc" ] )
1991+ . cwd ( p. root ( ) )
19831992 . masquerade_as_nightly_cargo ( & [ "gc" ] )
1984- // Necessary since `process` removes rustup.
1985- . env ( "PATH" , std:: env:: var_os ( "PATH" ) . unwrap ( ) )
19861993 . run ( ) ;
19871994
19881995 let config = GlobalContextBuilder :: new ( ) . unstable_flag ( "gc" ) . build ( ) ;
0 commit comments