Skip to content

Commit 079addf

Browse files
committed
Ensure that --build-dir is always specified in tests
1 parent aaa82ae commit 079addf

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

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

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -642,12 +642,12 @@ impl Config {
642642
let llvm_assertions = llvm_assertions.unwrap_or(false);
643643
let mut target_config = HashMap::new();
644644
let mut channel = "dev".to_string();
645+
646+
let out = flags_build_dir.or_else(|| build_build_dir.map(PathBuf::from));
645647
let out = if cfg!(test) {
646-
test_build_dir()
648+
out.expect("--build-dir has to be specified in tests")
647649
} else {
648-
flags_build_dir
649-
.or_else(|| build_build_dir.map(PathBuf::from))
650-
.unwrap_or_else(|| PathBuf::from("build"))
650+
out.unwrap_or_else(|| PathBuf::from("build"))
651651
};
652652

653653
// NOTE: Bootstrap spawns various commands with different working directories.
@@ -2490,22 +2490,3 @@ fn find_correct_section_for_field(field_name: &str) -> Vec<WouldBeValidFor> {
24902490
})
24912491
.collect()
24922492
}
2493-
2494-
/// Resolve the build directory used for tests.
2495-
///
2496-
/// - When tests are run through bootstrap (`x.py test`), the build system
2497-
/// sets `CARGO_TARGET_DIR`, so we can trust and use it here.
2498-
/// - When tests are run directly with cargo test, `CARGO_TARGET_DIR` will
2499-
/// not be set. In that case we fall back to resolving relative to
2500-
/// `CARGO_MANIFEST_DIR`, by walking two parents up and appending `build`.
2501-
fn test_build_dir() -> PathBuf {
2502-
env::var_os("CARGO_TARGET_DIR")
2503-
.map(|value| Path::new(&value).parent().unwrap().to_path_buf())
2504-
.unwrap_or_else(|| {
2505-
let base = option_env!("CARGO_MANIFEST_DIR")
2506-
.map(PathBuf::from)
2507-
.unwrap_or_else(|| std::env::current_dir().expect("failed to get current dir"));
2508-
2509-
base.ancestors().nth(2).unwrap_or_else(|| Path::new(".")).join("build")
2510-
})
2511-
}

0 commit comments

Comments
 (0)