Skip to content

Commit afe380d

Browse files
committed
initialize out with CARGO_TARGET_DIR and then go for manifest and then for current
1 parent 671aabd commit afe380d

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/bootstrap/src/core/config/config.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,13 @@ impl Config {
630630
let llvm_assertions = llvm_assertions.unwrap_or(false);
631631
let mut target_config = HashMap::new();
632632
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+
};
636640

637641
// NOTE: Bootstrap spawns various commands with different working directories.
638642
// To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
@@ -683,11 +687,6 @@ impl Config {
683687
};
684688

685689
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-
};
691690
download_beta_toolchain(&dwn_ctx, &out);
692691
let target = if cfg!(test) { get_host_target() } else { host_target };
693692

@@ -2481,3 +2480,15 @@ fn find_correct_section_for_field(field_name: &str) -> Vec<WouldBeValidFor> {
24812480
})
24822481
.collect()
24832482
}
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

Comments
 (0)