@@ -630,9 +630,13 @@ impl Config {
630
630
let llvm_assertions = llvm_assertions. unwrap_or ( false ) ;
631
631
let mut target_config = HashMap :: new ( ) ;
632
632
let mut channel = "dev" . to_string ( ) ;
633
- let out = flags_build_dir
634
- . or ( build_build_dir. map ( PathBuf :: from) )
635
- . unwrap_or_else ( || PathBuf :: from ( "build" ) ) ;
633
+ let out = if cfg ! ( test) {
634
+ test_build_dir ( )
635
+ } else {
636
+ flags_build_dir
637
+ . or_else ( || build_build_dir. map ( PathBuf :: from) )
638
+ . unwrap_or_else ( || PathBuf :: from ( "build" ) )
639
+ } ;
636
640
637
641
// NOTE: Bootstrap spawns various commands with different working directories.
638
642
// To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
@@ -683,11 +687,6 @@ impl Config {
683
687
} ;
684
688
685
689
let initial_rustc = build_rustc. unwrap_or_else ( || {
686
- let out = if cfg ! ( test) {
687
- std:: env:: current_dir ( ) . unwrap ( ) . ancestors ( ) . nth ( 2 ) . unwrap ( ) . join ( "build" )
688
- } else {
689
- out. clone ( )
690
- } ;
691
690
download_beta_toolchain ( & dwn_ctx, & out) ;
692
691
let target = if cfg ! ( test) { get_host_target ( ) } else { host_target } ;
693
692
@@ -2481,3 +2480,15 @@ fn find_correct_section_for_field(field_name: &str) -> Vec<WouldBeValidFor> {
2481
2480
} )
2482
2481
. collect ( )
2483
2482
}
2483
+
2484
+ fn test_build_dir ( ) -> PathBuf {
2485
+ env:: var_os ( "CARGO_TARGET_DIR" )
2486
+ . map ( |value| Path :: new ( & value) . parent ( ) . unwrap ( ) . to_path_buf ( ) )
2487
+ . unwrap_or_else ( || {
2488
+ let base = option_env ! ( "CARGO_MANIFEST_DIR" )
2489
+ . map ( PathBuf :: from)
2490
+ . unwrap_or_else ( || std:: env:: current_dir ( ) . expect ( "failed to get current dir" ) ) ;
2491
+
2492
+ base. ancestors ( ) . nth ( 2 ) . unwrap_or_else ( || Path :: new ( "." ) ) . join ( "build" )
2493
+ } )
2494
+ }
0 commit comments