diff options
| author | Jakub Beránek <berykubik@gmail.com> | 2025-09-25 15:07:34 +0200 |
|---|---|---|
| committer | Jakub Beránek <berykubik@gmail.com> | 2025-09-25 15:07:34 +0200 |
| commit | 079addf985d1902e8f79620697834c3ea3de84c8 (patch) | |
| tree | 5f9a53d1e0bd4147df68e5bd10c98cc5bc784688 /src | |
| parent | aaa82aea053bfbb226916b38c66243a28a296b6e (diff) | |
| download | rust-079addf985d1902e8f79620697834c3ea3de84c8.tar.gz rust-079addf985d1902e8f79620697834c3ea3de84c8.zip | |
Ensure that `--build-dir` is always specified in tests
Diffstat (limited to 'src')
| -rw-r--r-- | src/bootstrap/src/core/config/config.rs | 27 |
1 files changed, 4 insertions, 23 deletions
diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 1e207380a0a..74a272c740b 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -642,12 +642,12 @@ impl Config { let llvm_assertions = llvm_assertions.unwrap_or(false); let mut target_config = HashMap::new(); let mut channel = "dev".to_string(); + + let out = flags_build_dir.or_else(|| build_build_dir.map(PathBuf::from)); let out = if cfg!(test) { - test_build_dir() + out.expect("--build-dir has to be specified in tests") } else { - flags_build_dir - .or_else(|| build_build_dir.map(PathBuf::from)) - .unwrap_or_else(|| PathBuf::from("build")) + out.unwrap_or_else(|| PathBuf::from("build")) }; // NOTE: Bootstrap spawns various commands with different working directories. @@ -2490,22 +2490,3 @@ fn find_correct_section_for_field(field_name: &str) -> Vec<WouldBeValidFor> { }) .collect() } - -/// Resolve the build directory used for tests. -/// -/// - When tests are run through bootstrap (`x.py test`), the build system -/// sets `CARGO_TARGET_DIR`, so we can trust and use it here. -/// - When tests are run directly with cargo test, `CARGO_TARGET_DIR` will -/// not be set. In that case we fall back to resolving relative to -/// `CARGO_MANIFEST_DIR`, by walking two parents up and appending `build`. -fn test_build_dir() -> PathBuf { - env::var_os("CARGO_TARGET_DIR") - .map(|value| Path::new(&value).parent().unwrap().to_path_buf()) - .unwrap_or_else(|| { - let base = option_env!("CARGO_MANIFEST_DIR") - .map(PathBuf::from) - .unwrap_or_else(|| std::env::current_dir().expect("failed to get current dir")); - - base.ancestors().nth(2).unwrap_or_else(|| Path::new(".")).join("build") - }) -} |
