about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/bootstrap/src/core/config/config.rs24
-rw-r--r--src/bootstrap/src/core/config/tests.rs62
-rw-r--r--src/bootstrap/src/utils/helpers/tests.rs4
3 files changed, 17 insertions, 73 deletions
diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs
index dd2d5a1fd53..19fcaeaaa24 100644
--- a/src/bootstrap/src/core/config/config.rs
+++ b/src/bootstrap/src/core/config/config.rs
@@ -630,19 +630,9 @@ 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(build_build_dir.map(PathBuf::from)).unwrap_or_else(|| {
-            if cfg!(test) {
-                // Use the build directory of the original x.py invocation, so that we can set `initial_rustc` properly.
-                Path::new(
-                    &env::var_os("CARGO_TARGET_DIR").expect("cargo test directly is not supported"),
-                )
-                .parent()
-                .unwrap()
-                .to_path_buf()
-            } else {
-                PathBuf::from("build")
-            }
-        });
+        let out = flags_build_dir
+            .or(build_build_dir.map(PathBuf::from))
+            .unwrap_or_else(|| PathBuf::from("build"));
 
         // NOTE: Bootstrap spawns various commands with different working directories.
         // To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
@@ -693,8 +683,14 @@ impl Config {
         };
 
         let initial_rustc = build_rustc.unwrap_or_else(|| {
+            let out = if cfg!(test) { Path::new("../../build").to_path_buf() } else { out.clone() };
+
             download_beta_toolchain(&dwn_ctx, &out);
-            out.join(host_target).join("stage0").join("bin").join(exe("rustc", host_target))
+
+            out.join(if cfg!(test) { get_host_target() } else { host_target })
+                .join("stage0")
+                .join("bin")
+                .join(exe("rustc", host_target))
         });
 
         let initial_sysroot = t!(PathBuf::from_str(
diff --git a/src/bootstrap/src/core/config/tests.rs b/src/bootstrap/src/core/config/tests.rs
index e93525fbd09..46d05fbc068 100644
--- a/src/bootstrap/src/core/config/tests.rs
+++ b/src/bootstrap/src/core/config/tests.rs
@@ -39,7 +39,11 @@ fn prepare_test_specific_dir() -> PathBuf {
     // Replace "::" with "_" to make it safe for directory names on Windows systems
     let test_path = current.name().unwrap().replace("::", "_");
 
-    let testdir = parse("").tempdir().join(test_path);
+    let testdir = crate::utils::tests::TestCtx::new()
+        .config("check")
+        .create_config()
+        .tempdir()
+        .join(test_path);
 
     // clean up any old test files
     let _ = fs::remove_dir_all(&testdir);
@@ -64,62 +68,6 @@ fn download_ci_llvm() {
     }
 }
 
-// FIXME(onur-ozkan): extend scope of the test
-// refs:
-//   - https://github.com/rust-lang/rust/issues/109120
-//   - https://github.com/rust-lang/rust/pull/109162#issuecomment-1496782487
-#[test]
-fn detect_src_and_out() {
-    fn test(cfg: Config, build_dir: Option<&str>) {
-        // This will bring absolute form of `src/bootstrap` path
-        let current_dir = std::env::current_dir().unwrap();
-
-        // get `src` by moving into project root path
-        let expected_src = current_dir.ancestors().nth(2).unwrap();
-        assert_eq!(&cfg.src, expected_src);
-
-        // Sanity check for `src`
-        let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
-        let expected_src = manifest_dir.ancestors().nth(2).unwrap();
-        assert_eq!(&cfg.src, expected_src);
-
-        // test if build-dir was manually given in bootstrap.toml
-        if let Some(custom_build_dir) = build_dir {
-            assert_eq!(&cfg.out, Path::new(custom_build_dir));
-        }
-        // test the native bootstrap way
-        else {
-            // This should bring output path of bootstrap in absolute form
-            let cargo_target_dir = env::var_os("CARGO_TARGET_DIR").expect(
-                "CARGO_TARGET_DIR must been provided for the test environment from bootstrap",
-            );
-
-            // Move to `build` from `build/bootstrap`
-            let expected_out = Path::new(&cargo_target_dir).parent().unwrap();
-            assert_eq!(&cfg.out, expected_out);
-
-            let args: Vec<String> = env::args().collect();
-
-            // Another test for `out` as a sanity check
-            //
-            // This will bring something similar to:
-            //     `{build-dir}/bootstrap/debug/deps/bootstrap-c7ee91d5661e2804`
-            // `{build-dir}` can be anywhere, not just in the rust project directory.
-            let dep = Path::new(args.first().unwrap());
-            let expected_out = dep.ancestors().nth(5).unwrap();
-
-            assert_eq!(&cfg.out, expected_out);
-        }
-    }
-
-    test(parse(""), None);
-
-    {
-        let build_dir = if cfg!(windows) { "C:\\tmp" } else { "/tmp" };
-        test(parse(&format!("build.build-dir = '{build_dir}'")), Some(build_dir));
-    }
-}
-
 #[test]
 fn clap_verify() {
     Flags::command().debug_assert();
diff --git a/src/bootstrap/src/utils/helpers/tests.rs b/src/bootstrap/src/utils/helpers/tests.rs
index 9030ca2820a..e586fe77b4f 100644
--- a/src/bootstrap/src/utils/helpers/tests.rs
+++ b/src/bootstrap/src/utils/helpers/tests.rs
@@ -6,6 +6,7 @@ use crate::utils::helpers::{
     check_cfg_arg, extract_beta_rev, hex_encode, make, set_file_times, submodule_path_of,
     symlink_dir,
 };
+use crate::utils::tests::TestCtx;
 use crate::{Config, Flags};
 
 #[test]
@@ -80,8 +81,7 @@ fn test_symlink_dir() {
 
 #[test]
 fn test_set_file_times_sanity_check() {
-    let config =
-        Config::parse(Flags::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]));
+    let config = TestCtx::new().config("check").create_config();
     let tempfile = config.tempdir().join(".tmp-file");
 
     {