about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/bootstrap.py2
-rw-r--r--src/bootstrap/src/core/build_steps/clippy.rs2
-rw-r--r--src/bootstrap/src/core/build_steps/compile.rs16
-rw-r--r--src/bootstrap/src/core/build_steps/dist.rs2
-rw-r--r--src/bootstrap/src/core/build_steps/gcc.rs2
-rw-r--r--src/bootstrap/src/core/build_steps/test.rs6
-rw-r--r--src/bootstrap/src/core/builder/cargo.rs2
-rw-r--r--src/bootstrap/src/core/builder/mod.rs4
-rw-r--r--src/bootstrap/src/core/builder/tests.rs49
-rw-r--r--src/bootstrap/src/core/config/config.rs72
-rw-r--r--src/bootstrap/src/core/config/tests.rs548
-rw-r--r--src/bootstrap/src/core/config/toml/mod.rs4
-rw-r--r--src/bootstrap/src/core/download.rs18
-rw-r--r--src/bootstrap/src/core/sanity.rs5
-rw-r--r--src/bootstrap/src/lib.rs28
-rw-r--r--src/bootstrap/src/utils/build_stamp.rs2
-rw-r--r--src/bootstrap/src/utils/cc_detect.rs10
-rw-r--r--src/bootstrap/src/utils/exec.rs6
-rw-r--r--src/bootstrap/src/utils/helpers/tests.rs11
-rw-r--r--src/bootstrap/src/utils/render_tests.rs2
-rw-r--r--src/bootstrap/src/utils/tarball.rs2
-rw-r--r--src/bootstrap/src/utils/tests/mod.rs53
22 files changed, 394 insertions, 452 deletions
diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py
index effd33d288f..8b1775178c9 100644
--- a/src/bootstrap/bootstrap.py
+++ b/src/bootstrap/bootstrap.py
@@ -596,6 +596,7 @@ class RustBuild(object):
         self.download_url = (
             os.getenv("RUSTUP_DIST_SERVER") or self.stage0_data["dist_server"]
         )
+        self.jobs = self.get_toml("jobs", "build") or "default"
 
         self.build = args.build or self.build_triple()
 
@@ -1144,6 +1145,7 @@ class RustBuild(object):
         args = [
             self.cargo(),
             "build",
+            "--jobs=" + self.jobs,
             "--manifest-path",
             os.path.join(self.rust_root, "src/bootstrap/Cargo.toml"),
             "-Zroot-dir=" + self.rust_root,
diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs
index 2083c675e1f..d5b15d79086 100644
--- a/src/bootstrap/src/core/build_steps/clippy.rs
+++ b/src/bootstrap/src/core/build_steps/clippy.rs
@@ -564,6 +564,7 @@ impl Step for CI {
                 "clippy::same_item_push".into(),
                 "clippy::single_char_add_str".into(),
                 "clippy::to_string_in_format_args".into(),
+                "clippy::unconditional_recursion".into(),
             ],
             forbid: vec![],
         };
@@ -591,6 +592,7 @@ impl Step for CI {
                 "clippy::same_item_push".into(),
                 "clippy::single_char_add_str".into(),
                 "clippy::to_string_in_format_args".into(),
+                "clippy::unconditional_recursion".into(),
             ],
             forbid: vec![],
         };
diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs
index 14104d7d1d7..884b5750974 100644
--- a/src/bootstrap/src/core/build_steps/compile.rs
+++ b/src/bootstrap/src/core/build_steps/compile.rs
@@ -895,6 +895,8 @@ impl Step for StartupObjects {
     fn run(self, builder: &Builder<'_>) -> Vec<(PathBuf, DependencyType)> {
         let for_compiler = self.compiler;
         let target = self.target;
+        // Even though no longer necessary on x86_64, they are kept for now to
+        // avoid potential issues in downstream crates.
         if !target.is_windows_gnu() {
             return vec![];
         }
@@ -1832,8 +1834,9 @@ impl Step for Sysroot {
         let sysroot = sysroot_dir(compiler.stage);
         trace!(stage = ?compiler.stage, ?sysroot);
 
-        builder
-            .verbose(|| println!("Removing sysroot {} to avoid caching bugs", sysroot.display()));
+        builder.do_if_verbose(|| {
+            println!("Removing sysroot {} to avoid caching bugs", sysroot.display())
+        });
         let _ = fs::remove_dir_all(&sysroot);
         t!(fs::create_dir_all(&sysroot));
 
@@ -1902,12 +1905,7 @@ impl Step for Sysroot {
                 if !path.parent().is_none_or(|p| p.ends_with(&suffix)) {
                     return true;
                 }
-                if !filtered_files.iter().all(|f| f != path.file_name().unwrap()) {
-                    builder.verbose_than(1, || println!("ignoring {}", path.display()));
-                    false
-                } else {
-                    true
-                }
+                filtered_files.iter().all(|f| f != path.file_name().unwrap())
             });
         }
 
@@ -2596,7 +2594,7 @@ pub fn stream_cargo(
         cmd.arg(arg);
     }
 
-    builder.verbose(|| println!("running: {cmd:?}"));
+    builder.do_if_verbose(|| println!("running: {cmd:?}"));
 
     let streaming_command = cmd.stream_capture_stdout(&builder.config.exec_ctx);
 
diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs
index 99a1062109a..b79d2cb413d 100644
--- a/src/bootstrap/src/core/build_steps/dist.rs
+++ b/src/bootstrap/src/core/build_steps/dist.rs
@@ -2304,7 +2304,7 @@ fn maybe_install_llvm(
         let mut cmd = command(host_llvm_config);
         cmd.cached();
         cmd.arg("--libfiles");
-        builder.verbose(|| println!("running {cmd:?}"));
+        builder.do_if_verbose(|| println!("running {cmd:?}"));
         let files = cmd.run_capture_stdout(builder).stdout();
         let build_llvm_out = &builder.llvm_out(builder.config.host_target);
         let target_llvm_out = &builder.llvm_out(target);
diff --git a/src/bootstrap/src/core/build_steps/gcc.rs b/src/bootstrap/src/core/build_steps/gcc.rs
index 717dea37e9e..17ab8c4e2f4 100644
--- a/src/bootstrap/src/core/build_steps/gcc.rs
+++ b/src/bootstrap/src/core/build_steps/gcc.rs
@@ -128,7 +128,7 @@ fn try_download_gcc(builder: &Builder<'_>, target: TargetSelection) -> Option<Pa
         &builder.config,
         builder.config.rust_info.is_managed_git_subrepository(),
     );
-    builder.verbose(|| {
+    builder.do_if_verbose(|| {
         eprintln!("GCC freshness: {source:?}");
     });
     match source {
diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs
index e7f5879b5f5..ca2731819e7 100644
--- a/src/bootstrap/src/core/build_steps/test.rs
+++ b/src/bootstrap/src/core/build_steps/test.rs
@@ -582,11 +582,11 @@ impl Miri {
         // We re-use the `cargo` from above.
         cargo.arg("--print-sysroot");
 
-        builder.verbose(|| println!("running: {cargo:?}"));
+        builder.do_if_verbose(|| println!("running: {cargo:?}"));
         let stdout = cargo.run_capture_stdout(builder).stdout();
         // Output is "<sysroot>\n".
         let sysroot = stdout.trim_end();
-        builder.verbose(|| println!("`cargo miri setup --print-sysroot` said: {sysroot:?}"));
+        builder.do_if_verbose(|| println!("`cargo miri setup --print-sysroot` said: {sysroot:?}"));
         PathBuf::from(sysroot)
     }
 }
@@ -2675,7 +2675,7 @@ fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) ->
         return true;
     }
 
-    builder.verbose(|| println!("doc tests for: {}", markdown.display()));
+    builder.do_if_verbose(|| println!("doc tests for: {}", markdown.display()));
     let mut cmd = builder.rustdoc_cmd(compiler);
     builder.add_rust_test_threads(&mut cmd);
     // allow for unstable options such as new editions
diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs
index ee2bb710674..9fc4ce669c2 100644
--- a/src/bootstrap/src/core/builder/cargo.rs
+++ b/src/bootstrap/src/core/builder/cargo.rs
@@ -1139,7 +1139,7 @@ impl Builder<'_> {
             cargo.env("RUSTC_BACKTRACE_ON_ICE", "1");
         }
 
-        if self.is_verbose_than(1) {
+        if self.verbosity >= 2 {
             // This provides very useful logs especially when debugging build cache-related stuff.
             cargo.env("CARGO_LOG", "cargo::core::compiler::fingerprint=info");
         }
diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs
index 8226b4325b6..049d2647bec 100644
--- a/src/bootstrap/src/core/builder/mod.rs
+++ b/src/bootstrap/src/core/builder/mod.rs
@@ -545,7 +545,7 @@ impl StepDescription {
         if !builder.config.skip.is_empty()
             && !matches!(builder.config.get_dry_run(), DryRun::SelfCheck)
         {
-            builder.verbose(|| {
+            builder.do_if_verbose(|| {
                 println!(
                     "{:?} not skipped for {:?} -- not in {:?}",
                     pathset, self.name, builder.config.skip
@@ -947,7 +947,7 @@ impl Step for Libdir {
             // Sysroot`).
             if !builder.download_rustc() {
                 let sysroot_target_libdir = sysroot.join(self.target).join("lib");
-                builder.verbose(|| {
+                builder.do_if_verbose(|| {
                     eprintln!(
                         "Removing sysroot {} to avoid caching bugs",
                         sysroot_target_libdir.display()
diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs
index 229adf71459..4555f0d2091 100644
--- a/src/bootstrap/src/core/builder/tests.rs
+++ b/src/bootstrap/src/core/builder/tests.rs
@@ -22,13 +22,7 @@ fn configure(cmd: &str, host: &[&str], target: &[&str]) -> Config {
 }
 
 fn configure_with_args(cmd: &[&str], host: &[&str], target: &[&str]) -> Config {
-    TestCtx::new()
-        .config(cmd[0])
-        .args(&cmd[1..])
-        .hosts(host)
-        .targets(target)
-        .args(&["--build", TEST_TRIPLE_1])
-        .create_config()
+    TestCtx::new().config(cmd[0]).args(&cmd[1..]).hosts(host).targets(target).create_config()
 }
 
 fn first<A, B>(v: Vec<(A, B)>) -> Vec<A> {
@@ -218,18 +212,17 @@ fn prepare_rustc_checkout(ctx: &mut GitCtx) {
 
 /// Parses a Config directory from `path`, with the given value of `download_rustc`.
 fn parse_config_download_rustc_at(path: &Path, download_rustc: &str, ci: bool) -> Config {
-    Config::parse_inner(
-        Flags::parse(&[
-            "build".to_owned(),
-            "--dry-run".to_owned(),
-            "--ci".to_owned(),
-            if ci { "true" } else { "false" }.to_owned(),
-            format!("--set=rust.download-rustc='{download_rustc}'"),
-            "--src".to_owned(),
-            path.to_str().unwrap().to_owned(),
-        ]),
-        |&_| Ok(Default::default()),
-    )
+    TestCtx::new()
+        .config("build")
+        .args(&[
+            "--ci",
+            if ci { "true" } else { "false" },
+            format!("--set=rust.download-rustc='{download_rustc}'").as_str(),
+            "--src",
+            path.to_str().unwrap(),
+        ])
+        .no_override_download_ci_llvm()
+        .create_config()
 }
 
 mod dist {
@@ -237,6 +230,7 @@ mod dist {
 
     use super::{Config, TEST_TRIPLE_1, TEST_TRIPLE_2, TEST_TRIPLE_3, first, run_build};
     use crate::Flags;
+    use crate::core::builder::tests::host_target;
     use crate::core::builder::*;
 
     fn configure(host: &[&str], target: &[&str]) -> Config {
@@ -245,11 +239,11 @@ mod dist {
 
     #[test]
     fn llvm_out_behaviour() {
-        let mut config = configure(&[TEST_TRIPLE_1], &[TEST_TRIPLE_2]);
+        let mut config = configure(&[], &[TEST_TRIPLE_2]);
         config.llvm_from_ci = true;
         let build = Build::new(config.clone());
 
-        let target = TargetSelection::from_user(TEST_TRIPLE_1);
+        let target = TargetSelection::from_user(&host_target());
         assert!(build.llvm_out(target).ends_with("ci-llvm"));
         let target = TargetSelection::from_user(TEST_TRIPLE_2);
         assert!(build.llvm_out(target).ends_with("llvm"));
@@ -314,7 +308,7 @@ mod sysroot_target_dirs {
 /// cg_gcc tests instead.
 #[test]
 fn test_test_compiler() {
-    let config = configure_with_args(&["test", "compiler"], &[TEST_TRIPLE_1], &[TEST_TRIPLE_1]);
+    let config = configure_with_args(&["test", "compiler"], &[&host_target()], &[TEST_TRIPLE_1]);
     let cache = run_build(&config.paths.clone(), config);
 
     let compiler = cache.contains::<test::CrateLibrustc>();
@@ -347,7 +341,7 @@ fn test_test_coverage() {
         // Print each test case so that if one fails, the most recently printed
         // case is the one that failed.
         println!("Testing case: {cmd:?}");
-        let config = configure_with_args(cmd, &[TEST_TRIPLE_1], &[TEST_TRIPLE_1]);
+        let config = configure_with_args(cmd, &[], &[TEST_TRIPLE_1]);
         let mut cache = run_build(&config.paths.clone(), config);
 
         let modes =
@@ -359,14 +353,7 @@ fn test_test_coverage() {
 #[test]
 fn test_prebuilt_llvm_config_path_resolution() {
     fn configure(config: &str) -> Config {
-        Config::parse_inner(
-            Flags::parse(&[
-                "build".to_string(),
-                "--dry-run".to_string(),
-                "--config=/does/not/exist".to_string(),
-            ]),
-            |&_| toml::from_str(&config),
-        )
+        TestCtx::new().config("build").with_default_toml_config(config).create_config()
     }
 
     // Removes Windows disk prefix if present
diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs
index dd2d5a1fd53..6d9e3b54156 100644
--- a/src/bootstrap/src/core/config/config.rs
+++ b/src/bootstrap/src/core/config/config.rs
@@ -414,14 +414,28 @@ impl Config {
         // Set config values based on flags.
         let mut exec_ctx = ExecutionContext::new(flags_verbose, flags_cmd.fail_fast());
         exec_ctx.set_dry_run(if flags_dry_run { DryRun::UserSelected } else { DryRun::Disabled });
-        let mut src = {
+
+        let default_src_dir = {
             let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
             // Undo `src/bootstrap`
             manifest_dir.parent().unwrap().parent().unwrap().to_owned()
         };
+        let src = if let Some(s) = compute_src_directory(flags_src, &exec_ctx) {
+            s
+        } else {
+            default_src_dir.clone()
+        };
 
-        if let Some(src_) = compute_src_directory(flags_src, &exec_ctx) {
-            src = src_;
+        #[cfg(test)]
+        {
+            if let Some(config_path) = flags_config.as_ref() {
+                assert!(
+                    !config_path.starts_with(&src),
+                    "Path {config_path:?} should not be inside or equal to src dir {src:?}"
+                );
+            } else {
+                panic!("During test the config should be explicitly added");
+            }
         }
 
         // Now load the TOML config, as soon as possible
@@ -630,19 +644,13 @@ 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_else(|| build_build_dir.map(PathBuf::from));
+        let out = if cfg!(test) {
+            out.expect("--build-dir has to be specified in tests")
+        } else {
+            out.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.
@@ -653,6 +661,10 @@ impl Config {
             out
         };
 
+        let default_stage0_rustc_path = |dir: &Path| {
+            dir.join(host_target).join("stage0").join("bin").join(exe("rustc", host_target))
+        };
+
         if cfg!(test) {
             // When configuring bootstrap for tests, make sure to set the rustc and Cargo to the
             // same ones used to call the tests (if custom ones are not defined in the toml). If we
@@ -661,6 +673,22 @@ impl Config {
             // Cargo in their bootstrap.toml.
             build_rustc = build_rustc.take().or(std::env::var_os("RUSTC").map(|p| p.into()));
             build_cargo = build_cargo.take().or(std::env::var_os("CARGO").map(|p| p.into()));
+
+            // If we are running only `cargo test` (and not `x test bootstrap`), which is useful
+            // e.g. for debugging bootstrap itself, then we won't have RUSTC and CARGO set to the
+            // proper paths.
+            // We thus "guess" that the build directory is located at <src>/build, and try to load
+            // rustc and cargo from there
+            let is_test_outside_x = std::env::var("CARGO_TARGET_DIR").is_err();
+            if is_test_outside_x && build_rustc.is_none() {
+                let stage0_rustc = default_stage0_rustc_path(&default_src_dir.join("build"));
+                assert!(
+                    stage0_rustc.exists(),
+                    "Trying to run cargo test without having a stage0 rustc available in {}",
+                    stage0_rustc.display()
+                );
+                build_rustc = Some(stage0_rustc);
+            }
         }
 
         if !flags_skip_stage0_validation {
@@ -694,7 +722,7 @@ impl Config {
 
         let initial_rustc = build_rustc.unwrap_or_else(|| {
             download_beta_toolchain(&dwn_ctx, &out);
-            out.join(host_target).join("stage0").join("bin").join(exe("rustc", host_target))
+            default_stage0_rustc_path(&out)
         });
 
         let initial_sysroot = t!(PathBuf::from_str(
@@ -1534,11 +1562,11 @@ impl Config {
                                 println!("WARNING: CI rustc has some fields that are no longer supported in bootstrap; download-rustc will be disabled.");
                                 println!("HELP: Consider rebasing to a newer commit if available.");
                                 return None;
-                            },
+                            }
                             Err(e) => {
                                 eprintln!("ERROR: Failed to parse CI rustc bootstrap.toml: {e}");
                                 exit!(2);
-                            },
+                            }
                         };
 
                         let current_config_toml = Self::get_toml(config_path).unwrap();
@@ -1571,8 +1599,8 @@ impl Config {
     }
 
     /// Runs a function if verbosity is greater than 0
-    pub fn verbose(&self, f: impl Fn()) {
-        self.exec_ctx.verbose(f);
+    pub fn do_if_verbose(&self, f: impl Fn()) {
+        self.exec_ctx.do_if_verbose(f);
     }
 
     pub fn any_sanitizers_to_build(&self) -> bool {
@@ -2061,7 +2089,7 @@ pub fn download_ci_rustc_commit<'a>(
         // Look for a version to compare to based on the current commit.
         // Only commits merged by bors will have CI artifacts.
         let freshness = check_path_modifications_(dwn_ctx, RUSTC_IF_UNCHANGED_ALLOWED_PATHS);
-        dwn_ctx.exec_ctx.verbose(|| {
+        dwn_ctx.exec_ctx.do_if_verbose(|| {
             eprintln!("rustc freshness: {freshness:?}");
         });
         match freshness {
diff --git a/src/bootstrap/src/core/config/tests.rs b/src/bootstrap/src/core/config/tests.rs
index e93525fbd09..4f2df76a156 100644
--- a/src/bootstrap/src/core/config/tests.rs
+++ b/src/bootstrap/src/core/config/tests.rs
@@ -14,17 +14,15 @@ use super::toml::change_id::ChangeIdWrapper;
 use super::{Config, RUSTC_IF_UNCHANGED_ALLOWED_PATHS};
 use crate::ChangeId;
 use crate::core::build_steps::clippy::{LintConfig, get_clippy_rules_in_order};
-use crate::core::build_steps::llvm;
 use crate::core::build_steps::llvm::LLVM_INVALIDATION_PATHS;
+use crate::core::build_steps::{llvm, test};
 use crate::core::config::toml::TomlConfig;
 use crate::core::config::{CompilerBuiltins, LldMode, StringOrBool, Target, TargetSelection};
+use crate::utils::tests::TestCtx;
 use crate::utils::tests::git::git_test;
 
 pub(crate) fn parse(config: &str) -> Config {
-    Config::parse_inner(
-        Flags::parse(&["check".to_string(), "--config=/does/not/exist".to_string()]),
-        |&_| toml::from_str(&config),
-    )
+    TestCtx::new().config("check").with_default_toml_config(config).create_config()
 }
 
 fn get_toml(file: &Path) -> Result<TomlConfig, toml::de::Error> {
@@ -32,28 +30,16 @@ fn get_toml(file: &Path) -> Result<TomlConfig, toml::de::Error> {
     toml::from_str(&contents).and_then(|table: toml::Value| TomlConfig::deserialize(table))
 }
 
-/// Helps with debugging by using consistent test-specific directories instead of
-/// random temporary directories.
-fn prepare_test_specific_dir() -> PathBuf {
-    let current = std::thread::current();
-    // 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);
-
-    // clean up any old test files
-    let _ = fs::remove_dir_all(&testdir);
-    let _ = fs::create_dir_all(&testdir);
-
-    testdir
-}
-
 #[test]
 fn download_ci_llvm() {
-    let config = parse("llvm.download-ci-llvm = false");
+    let config = TestCtx::new().config("check").create_config();
     assert!(!config.llvm_from_ci);
 
-    let if_unchanged_config = parse("llvm.download-ci-llvm = \"if-unchanged\"");
+    // this doesn't make sense, as we are overriding it later.
+    let if_unchanged_config = TestCtx::new()
+        .config("check")
+        .with_default_toml_config("llvm.download-ci-llvm = \"if-unchanged\"")
+        .create_config();
     if if_unchanged_config.llvm_from_ci && if_unchanged_config.is_running_on_ci {
         let has_changes = if_unchanged_config.has_changes_from_upstream(LLVM_INVALIDATION_PATHS);
 
@@ -64,62 +50,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();
@@ -127,54 +57,54 @@ fn clap_verify() {
 
 #[test]
 fn override_toml() {
-    let config = Config::parse_inner(
-        Flags::parse(&[
-            "check".to_owned(),
-            "--config=/does/not/exist".to_owned(),
-            "--set=change-id=1".to_owned(),
-            "--set=rust.lto=fat".to_owned(),
-            "--set=rust.deny-warnings=false".to_owned(),
-            "--set=build.optimized-compiler-builtins=true".to_owned(),
-            "--set=build.gdb=\"bar\"".to_owned(),
-            "--set=build.tools=[\"cargo\"]".to_owned(),
-            "--set=llvm.build-config={\"foo\" = \"bar\"}".to_owned(),
-            "--set=target.x86_64-unknown-linux-gnu.runner=bar".to_owned(),
-            "--set=target.x86_64-unknown-linux-gnu.rpath=false".to_owned(),
-            "--set=target.aarch64-unknown-linux-gnu.sanitizers=false".to_owned(),
-            "--set=target.aarch64-apple-darwin.runner=apple".to_owned(),
-            "--set=target.aarch64-apple-darwin.optimized-compiler-builtins=false".to_owned(),
-        ]),
-        |&_| {
-            toml::from_str(
-                r#"
-change-id = 0
-[rust]
-lto = "off"
-deny-warnings = true
-download-rustc=false
-
-[build]
-gdb = "foo"
-tools = []
-
-[llvm]
-download-ci-llvm = false
-build-config = {}
-
-[target.aarch64-unknown-linux-gnu]
-sanitizers = true
-rpath = true
-runner = "aarch64-runner"
-
-[target.x86_64-unknown-linux-gnu]
-sanitizers = true
-rpath = true
-runner = "x86_64-runner"
-
-                "#,
-            )
-        },
-    );
+    let config_toml: &str = r#"
+    change-id = 0
+
+    [rust]
+    lto = "off"
+    deny-warnings = true
+    download-rustc = false
+
+    [build]
+    gdb = "foo"
+    tools = []
+
+    [llvm]
+    download-ci-llvm = false
+    build-config = {}
+
+    [target.aarch64-unknown-linux-gnu]
+    sanitizers = true
+    rpath = true
+    runner = "aarch64-runner"
+
+    [target.x86_64-unknown-linux-gnu]
+    sanitizers = true
+    rpath = true
+    runner = "x86_64-runner"
+    "#;
+
+    let args = [
+        "--set=change-id=1",
+        "--set=rust.lto=fat",
+        "--set=rust.deny-warnings=false",
+        "--set=build.optimized-compiler-builtins=true",
+        "--set=build.gdb=\"bar\"",
+        "--set=build.tools=[\"cargo\"]",
+        "--set=llvm.build-config={\"foo\" = \"bar\"}",
+        "--set=target.x86_64-unknown-linux-gnu.runner=bar",
+        "--set=target.x86_64-unknown-linux-gnu.rpath=false",
+        "--set=target.aarch64-unknown-linux-gnu.sanitizers=false",
+        "--set=target.aarch64-apple-darwin.runner=apple",
+        "--set=target.aarch64-apple-darwin.optimized-compiler-builtins=false",
+    ];
+
+    let config = TestCtx::new()
+        .config("check")
+        .with_default_toml_config(config_toml)
+        .args(&args)
+        .create_config();
+
     assert_eq!(config.change_id, Some(ChangeId::Id(1)), "setting top-level value");
     assert_eq!(
         config.rust_lto,
@@ -233,33 +163,26 @@ runner = "x86_64-runner"
 #[test]
 #[should_panic]
 fn override_toml_duplicate() {
-    Config::parse_inner(
-        Flags::parse(&[
-            "check".to_owned(),
-            "--config=/does/not/exist".to_string(),
-            "--set=change-id=1".to_owned(),
-            "--set=change-id=2".to_owned(),
-        ]),
-        |&_| toml::from_str("change-id = 0"),
-    );
+    TestCtx::new()
+        .config("check")
+        .with_default_toml_config("change-id = 0")
+        .arg("--set")
+        .arg("change-id=1")
+        .arg("--set")
+        .arg("change-id=2")
+        .create_config();
 }
 
 #[test]
 fn profile_user_dist() {
-    fn get_toml(file: &Path) -> Result<TomlConfig, toml::de::Error> {
-        let contents = if file.ends_with("bootstrap.toml")
-            || file.ends_with("config.toml")
-            || env::var_os("RUST_BOOTSTRAP_CONFIG").is_some()
-        {
-            "profile = \"user\"".to_owned()
-        } else {
-            assert!(file.ends_with("config.dist.toml") || file.ends_with("bootstrap.dist.toml"));
-            std::fs::read_to_string(file).unwrap()
-        };
-
-        toml::from_str(&contents).and_then(|table: toml::Value| TomlConfig::deserialize(table))
-    }
-    Config::parse_inner(Flags::parse(&["check".to_owned()]), get_toml);
+    TestCtx::new()
+        .config("check")
+        .with_default_toml_config(
+            r#"
+        profile = "user"
+    "#,
+        )
+        .create_config();
 }
 
 #[test]
@@ -277,12 +200,15 @@ fn rust_optimize() {
 #[test]
 #[should_panic]
 fn invalid_rust_optimize() {
-    parse("rust.optimize = \"a\"");
+    TestCtx::new()
+        .config("check")
+        .with_default_toml_config("rust.optimize = \"a\"")
+        .create_config();
 }
 
 #[test]
 fn verify_file_integrity() {
-    let config = parse("");
+    let config = TestCtx::new().config("check").no_dry_run().create_config();
 
     let tempfile = config.tempdir().join(".tmp-test-file");
     File::create(&tempfile).unwrap().write_all(b"dummy value").unwrap();
@@ -292,8 +218,6 @@ fn verify_file_integrity() {
         config
             .verify(&tempfile, "7e255dd9542648a8779268a0f268b891a198e9828e860ed23f826440e786eae5")
     );
-
-    remove_file(tempfile).unwrap();
 }
 
 #[test]
@@ -324,22 +248,23 @@ fn parse_change_id_with_unknown_field() {
 
 #[test]
 fn order_of_clippy_rules() {
-    let args = vec![
-        "clippy".to_string(),
-        "--fix".to_string(),
-        "--allow-dirty".to_string(),
-        "--allow-staged".to_string(),
-        "-Aclippy:all".to_string(),
-        "-Wclippy::style".to_string(),
-        "-Aclippy::foo1".to_string(),
-        "-Aclippy::foo2".to_string(),
+    let args = [
+        "clippy",
+        "--fix",
+        "--allow-dirty",
+        "--allow-staged",
+        "-Aclippy:all",
+        "-Wclippy::style",
+        "-Aclippy::foo1",
+        "-Aclippy::foo2",
     ];
-    let config = Config::parse(Flags::parse(&args));
+    let config = TestCtx::new().config(&args[0]).args(&args[1..]).create_config();
 
     let actual = match config.cmd.clone() {
         crate::Subcommand::Clippy { allow, deny, warn, forbid, .. } => {
             let cfg = LintConfig { allow, deny, warn, forbid };
-            get_clippy_rules_in_order(&args, &cfg)
+            let args_vec: Vec<String> = args.iter().map(|s| s.to_string()).collect();
+            get_clippy_rules_in_order(&args_vec, &cfg)
         }
         _ => panic!("invalid subcommand"),
     };
@@ -356,14 +281,14 @@ fn order_of_clippy_rules() {
 
 #[test]
 fn clippy_rule_separate_prefix() {
-    let args =
-        vec!["clippy".to_string(), "-A clippy:all".to_string(), "-W clippy::style".to_string()];
-    let config = Config::parse(Flags::parse(&args));
+    let args = ["clippy", "-A clippy:all", "-W clippy::style"];
+    let config = TestCtx::new().config(&args[0]).args(&args[1..]).create_config();
 
     let actual = match config.cmd.clone() {
         crate::Subcommand::Clippy { allow, deny, warn, forbid, .. } => {
             let cfg = LintConfig { allow, deny, warn, forbid };
-            get_clippy_rules_in_order(&args, &cfg)
+            let args_vec: Vec<String> = args.iter().map(|s| s.to_string()).collect();
+            get_clippy_rules_in_order(&args_vec, &cfg)
         }
         _ => panic!("invalid subcommand"),
     };
@@ -374,16 +299,20 @@ fn clippy_rule_separate_prefix() {
 
 #[test]
 fn verbose_tests_default_value() {
-    let config = Config::parse(Flags::parse(&["build".into(), "compiler".into()]));
+    let config = TestCtx::new().config("build").args(&["compiler".into()]).create_config();
     assert_eq!(config.verbose_tests, false);
 
-    let config = Config::parse(Flags::parse(&["build".into(), "compiler".into(), "-v".into()]));
+    let config =
+        TestCtx::new().config("build").args(&["compiler".into(), "-v".into()]).create_config();
     assert_eq!(config.verbose_tests, true);
 }
 
 #[test]
 fn parse_rust_std_features() {
-    let config = parse("rust.std-features = [\"panic-unwind\", \"backtrace\"]");
+    let config = TestCtx::new()
+        .config("check")
+        .with_default_toml_config("rust.std-features = [\"panic-unwind\", \"backtrace\"]")
+        .create_config();
     let expected_features: BTreeSet<String> =
         ["panic-unwind", "backtrace"].into_iter().map(|s| s.to_string()).collect();
     assert_eq!(config.rust_std_features, expected_features);
@@ -391,7 +320,10 @@ fn parse_rust_std_features() {
 
 #[test]
 fn parse_rust_std_features_empty() {
-    let config = parse("rust.std-features = []");
+    let config = TestCtx::new()
+        .config("check")
+        .with_default_toml_config("rust.std-features = []")
+        .create_config();
     let expected_features: BTreeSet<String> = BTreeSet::new();
     assert_eq!(config.rust_std_features, expected_features);
 }
@@ -399,70 +331,65 @@ fn parse_rust_std_features_empty() {
 #[test]
 #[should_panic]
 fn parse_rust_std_features_invalid() {
-    parse("rust.std-features = \"backtrace\"");
+    TestCtx::new()
+        .config("check")
+        .with_default_toml_config("rust.std-features = \"backtrace\"")
+        .create_config();
 }
 
 #[test]
 fn parse_jobs() {
-    assert_eq!(parse("build.jobs = 1").jobs, Some(1));
+    assert_eq!(
+        TestCtx::new()
+            .config("check")
+            .with_default_toml_config("build.jobs = 1")
+            .create_config()
+            .jobs,
+        Some(1)
+    );
 }
 
 #[test]
 fn jobs_precedence() {
     // `--jobs` should take precedence over using `--set build.jobs`.
 
-    let config = Config::parse_inner(
-        Flags::parse(&[
-            "check".to_owned(),
-            "--config=/does/not/exist".to_owned(),
-            "--jobs=67890".to_owned(),
-            "--set=build.jobs=12345".to_owned(),
-        ]),
-        |&_| toml::from_str(""),
-    );
+    let config = TestCtx::new()
+        .config("check")
+        .args(&["--jobs=67890", "--set=build.jobs=12345"])
+        .create_config();
     assert_eq!(config.jobs, Some(67890));
 
     // `--set build.jobs` should take precedence over `bootstrap.toml`.
-    let config = Config::parse_inner(
-        Flags::parse(&[
-            "check".to_owned(),
-            "--config=/does/not/exist".to_owned(),
-            "--set=build.jobs=12345".to_owned(),
-        ]),
-        |&_| {
-            toml::from_str(
-                r#"
-            [build]
-            jobs = 67890
-        "#,
-            )
-        },
-    );
+    let config = TestCtx::new()
+        .config("check")
+        .args(&["--set=build.jobs=12345"])
+        .with_default_toml_config(
+            r#"
+        [build]
+        jobs = 67890
+    "#,
+        )
+        .create_config();
+
     assert_eq!(config.jobs, Some(12345));
 
     // `--jobs` > `--set build.jobs` > `bootstrap.toml`
-    let config = Config::parse_inner(
-        Flags::parse(&[
-            "check".to_owned(),
-            "--jobs=123".to_owned(),
-            "--config=/does/not/exist".to_owned(),
-            "--set=build.jobs=456".to_owned(),
-        ]),
-        |&_| {
-            toml::from_str(
-                r#"
-            [build]
-            jobs = 789
-        "#,
-            )
-        },
-    );
+    let config = TestCtx::new()
+        .config("check")
+        .args(&["--jobs=123", "--set=build.jobs=456"])
+        .with_default_toml_config(
+            r#"
+        [build]
+        jobs = 789
+    "#,
+        )
+        .create_config();
     assert_eq!(config.jobs, Some(123));
 }
 
 #[test]
 fn check_rustc_if_unchanged_paths() {
-    let config = parse("");
+    let config = TestCtx::new().config("check").create_config();
     let normalised_allowed_paths: Vec<_> = RUSTC_IF_UNCHANGED_ALLOWED_PATHS
         .iter()
         .map(|t| {
@@ -477,59 +404,42 @@ fn check_rustc_if_unchanged_paths() {
 
 #[test]
 fn test_explicit_stage() {
-    let config = Config::parse_inner(
-        Flags::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]),
-        |&_| {
-            toml::from_str(
-                r#"
+    let config = TestCtx::new()
+        .config("check")
+        .with_default_toml_config(
+            r#"
             [build]
             test-stage = 1
         "#,
-            )
-        },
-    );
+        )
+        .create_config();
 
     assert!(!config.explicit_stage_from_cli);
     assert!(config.explicit_stage_from_config);
     assert!(config.is_explicit_stage());
 
-    let config = Config::parse_inner(
-        Flags::parse(&[
-            "check".to_owned(),
-            "--stage=2".to_owned(),
-            "--config=/does/not/exist".to_owned(),
-        ]),
-        |&_| toml::from_str(""),
-    );
+    let config = TestCtx::new().config("check").stage(2).create_config();
 
     assert!(config.explicit_stage_from_cli);
     assert!(!config.explicit_stage_from_config);
     assert!(config.is_explicit_stage());
 
-    let config = Config::parse_inner(
-        Flags::parse(&[
-            "check".to_owned(),
-            "--stage=2".to_owned(),
-            "--config=/does/not/exist".to_owned(),
-        ]),
-        |&_| {
-            toml::from_str(
-                r#"
+    let config = TestCtx::new()
+        .config("check")
+        .stage(2)
+        .with_default_toml_config(
+            r#"
             [build]
             test-stage = 1
         "#,
-            )
-        },
-    );
+        )
+        .create_config();
 
     assert!(config.explicit_stage_from_cli);
     assert!(config.explicit_stage_from_config);
     assert!(config.is_explicit_stage());
 
-    let config = Config::parse_inner(
-        Flags::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]),
-        |&_| toml::from_str(""),
-    );
+    let config = TestCtx::new().config("check").create_config();
 
     assert!(!config.explicit_stage_from_cli);
     assert!(!config.explicit_stage_from_config);
@@ -539,7 +449,10 @@ fn test_explicit_stage() {
 #[test]
 fn test_exclude() {
     let exclude_path = "compiler";
-    let config = parse(&format!("build.exclude=[\"{}\"]", exclude_path));
+    let config = TestCtx::new()
+        .config("check")
+        .with_default_toml_config(&format!("build.exclude=[\"{}\"]", exclude_path))
+        .create_config();
 
     let first_excluded = config
         .skip
@@ -553,32 +466,20 @@ fn test_exclude() {
 
 #[test]
 fn test_ci_flag() {
-    let config = Config::parse_inner(Flags::parse(&["check".into(), "--ci=false".into()]), |&_| {
-        toml::from_str("")
-    });
+    let config = TestCtx::new().config("check").arg("--ci").arg("false").create_config();
     assert!(!config.is_running_on_ci);
 
-    let config = Config::parse_inner(Flags::parse(&["check".into(), "--ci=true".into()]), |&_| {
-        toml::from_str("")
-    });
+    let config = TestCtx::new().config("check").arg("--ci").arg("true").create_config();
     assert!(config.is_running_on_ci);
 
-    let config = Config::parse_inner(Flags::parse(&["check".into()]), |&_| toml::from_str(""));
+    let config = TestCtx::new().config("check").create_config();
     assert_eq!(config.is_running_on_ci, CiEnv::is_ci());
 }
 
 #[test]
 fn test_precedence_of_includes() {
-    let testdir = prepare_test_specific_dir();
-
-    let root_config = testdir.join("config.toml");
-    let root_config_content = br#"
-        include = ["./extension.toml"]
-
-        [llvm]
-        link-jobs = 2
-    "#;
-    File::create(&root_config).unwrap().write_all(root_config_content).unwrap();
+    let test_ctx = TestCtx::new();
+    let testdir = test_ctx.dir();
 
     let extension = testdir.join("extension.toml");
     let extension_content = br#"
@@ -599,10 +500,17 @@ fn test_precedence_of_includes() {
     "#;
     File::create(extension).unwrap().write_all(extension_content).unwrap();
 
-    let config = Config::parse_inner(
-        Flags::parse(&["check".to_owned(), format!("--config={}", root_config.to_str().unwrap())]),
-        get_toml,
-    );
+    let config = test_ctx
+        .config("check")
+        .with_default_toml_config(
+            r#"
+        include = ["./extension.toml"]
+
+        [llvm]
+        link-jobs = 2
+    "#,
+        )
+        .create_config();
 
     assert_eq!(config.change_id.unwrap(), ChangeId::Id(543));
     assert_eq!(config.llvm_link_jobs.unwrap(), 2);
@@ -612,36 +520,29 @@ fn test_precedence_of_includes() {
 #[test]
 #[should_panic(expected = "Cyclic inclusion detected")]
 fn test_cyclic_include_direct() {
-    let testdir = prepare_test_specific_dir();
-
-    let root_config = testdir.join("config.toml");
-    let root_config_content = br#"
-        include = ["./extension.toml"]
-    "#;
-    File::create(&root_config).unwrap().write_all(root_config_content).unwrap();
-
+    let test_ctx = TestCtx::new();
+    let testdir = test_ctx.dir();
     let extension = testdir.join("extension.toml");
     let extension_content = br#"
-        include = ["./config.toml"]
+        include = ["./bootstrap.toml"]
     "#;
     File::create(extension).unwrap().write_all(extension_content).unwrap();
 
-    let config = Config::parse_inner(
-        Flags::parse(&["check".to_owned(), format!("--config={}", root_config.to_str().unwrap())]),
-        get_toml,
-    );
+    test_ctx
+        .config("check")
+        .with_default_toml_config(
+            r#"
+        include = ["./extension.toml"]
+    "#,
+        )
+        .create_config();
 }
 
 #[test]
 #[should_panic(expected = "Cyclic inclusion detected")]
 fn test_cyclic_include_indirect() {
-    let testdir = prepare_test_specific_dir();
-
-    let root_config = testdir.join("config.toml");
-    let root_config_content = br#"
-        include = ["./extension.toml"]
-    "#;
-    File::create(&root_config).unwrap().write_all(root_config_content).unwrap();
+    let test_ctx = TestCtx::new();
+    let testdir = test_ctx.dir();
 
     let extension = testdir.join("extension.toml");
     let extension_content = br#"
@@ -661,43 +562,37 @@ fn test_cyclic_include_indirect() {
     "#;
     File::create(extension).unwrap().write_all(extension_content).unwrap();
 
-    let config = Config::parse_inner(
-        Flags::parse(&["check".to_owned(), format!("--config={}", root_config.to_str().unwrap())]),
-        get_toml,
-    );
+    test_ctx
+        .config("check")
+        .with_default_toml_config(
+            r#"
+        include = ["./extension.toml"]
+    "#,
+        )
+        .create_config();
 }
 
 #[test]
 fn test_include_absolute_paths() {
-    let testdir = prepare_test_specific_dir();
+    let test_ctx = TestCtx::new();
+    let testdir = test_ctx.dir();
 
     let extension = testdir.join("extension.toml");
     File::create(&extension).unwrap().write_all(&[]).unwrap();
 
-    let root_config = testdir.join("config.toml");
     let extension_absolute_path =
         extension.canonicalize().unwrap().to_str().unwrap().replace('\\', r"\\");
     let root_config_content = format!(r#"include = ["{}"]"#, extension_absolute_path);
-    File::create(&root_config).unwrap().write_all(root_config_content.as_bytes()).unwrap();
-
-    let config = Config::parse_inner(
-        Flags::parse(&["check".to_owned(), format!("--config={}", root_config.to_str().unwrap())]),
-        get_toml,
-    );
+    test_ctx.config("check").with_default_toml_config(&root_config_content).create_config();
 }
 
 #[test]
 fn test_include_relative_paths() {
-    let testdir = prepare_test_specific_dir();
+    let test_ctx = TestCtx::new();
+    let testdir = test_ctx.dir();
 
     let _ = fs::create_dir_all(&testdir.join("subdir/another_subdir"));
 
-    let root_config = testdir.join("config.toml");
-    let root_config_content = br#"
-        include = ["./subdir/extension.toml"]
-    "#;
-    File::create(&root_config).unwrap().write_all(root_config_content).unwrap();
-
     let extension = testdir.join("subdir/extension.toml");
     let extension_content = br#"
         include = ["../extension2.toml"]
@@ -719,22 +614,20 @@ fn test_include_relative_paths() {
     let extension = testdir.join("extension4.toml");
     File::create(extension).unwrap().write_all(&[]).unwrap();
 
-    let config = Config::parse_inner(
-        Flags::parse(&["check".to_owned(), format!("--config={}", root_config.to_str().unwrap())]),
-        get_toml,
-    );
+    test_ctx
+        .config("check")
+        .with_default_toml_config(
+            r#"
+        include = ["./subdir/extension.toml"]
+    "#,
+        )
+        .create_config();
 }
 
 #[test]
 fn test_include_precedence_over_profile() {
-    let testdir = prepare_test_specific_dir();
-
-    let root_config = testdir.join("config.toml");
-    let root_config_content = br#"
-        profile = "dist"
-        include = ["./extension.toml"]
-    "#;
-    File::create(&root_config).unwrap().write_all(root_config_content).unwrap();
+    let test_ctx = TestCtx::new();
+    let testdir = test_ctx.dir();
 
     let extension = testdir.join("extension.toml");
     let extension_content = br#"
@@ -743,10 +636,15 @@ fn test_include_precedence_over_profile() {
     "#;
     File::create(extension).unwrap().write_all(extension_content).unwrap();
 
-    let config = Config::parse_inner(
-        Flags::parse(&["check".to_owned(), format!("--config={}", root_config.to_str().unwrap())]),
-        get_toml,
-    );
+    let config = test_ctx
+        .config("check")
+        .with_default_toml_config(
+            r#"
+        profile = "dist"
+        include = ["./extension.toml"]
+    "#,
+        )
+        .create_config();
 
     // "dist" profile would normally set the channel to "auto-detect", but includes should
     // override profile settings, so we expect this to be "dev" here.
diff --git a/src/bootstrap/src/core/config/toml/mod.rs b/src/bootstrap/src/core/config/toml/mod.rs
index 7af22432ef8..f6dc5b67e10 100644
--- a/src/bootstrap/src/core/config/toml/mod.rs
+++ b/src/bootstrap/src/core/config/toml/mod.rs
@@ -152,10 +152,6 @@ impl Config {
     }
 
     pub(crate) fn get_toml(file: &Path) -> Result<TomlConfig, toml::de::Error> {
-        #[cfg(test)]
-        return Ok(TomlConfig::default());
-
-        #[cfg(not(test))]
         Self::get_toml_inner(file)
     }
 
diff --git a/src/bootstrap/src/core/download.rs b/src/bootstrap/src/core/download.rs
index 2f3c80559c0..37871f0fe1e 100644
--- a/src/bootstrap/src/core/download.rs
+++ b/src/bootstrap/src/core/download.rs
@@ -106,7 +106,7 @@ enum DownloadSource {
 /// Functions that are only ever called once, but named for clarity and to avoid thousand-line functions.
 impl Config {
     pub(crate) fn download_clippy(&self) -> PathBuf {
-        self.verbose(|| println!("downloading stage0 clippy artifacts"));
+        self.do_if_verbose(|| println!("downloading stage0 clippy artifacts"));
 
         let date = &self.stage0_metadata.compiler.date;
         let version = &self.stage0_metadata.compiler.version;
@@ -151,7 +151,9 @@ impl Config {
     }
 
     pub(crate) fn download_ci_rustc(&self, commit: &str) {
-        self.verbose(|| println!("using downloaded stage2 artifacts from CI (commit {commit})"));
+        self.do_if_verbose(|| {
+            println!("using downloaded stage2 artifacts from CI (commit {commit})")
+        });
 
         let version = self.artifact_version_part(commit);
         // download-rustc doesn't need its own cargo, it can just use beta's. But it does need the
@@ -258,7 +260,7 @@ impl Config {
         let llvm_root = self.ci_llvm_root();
         let llvm_freshness =
             detect_llvm_freshness(self, self.rust_info.is_managed_git_subrepository());
-        self.verbose(|| {
+        self.do_if_verbose(|| {
             eprintln!("LLVM freshness: {llvm_freshness:?}");
         });
         let llvm_sha = match llvm_freshness {
@@ -557,7 +559,7 @@ pub(crate) fn download_beta_toolchain<'a>(dwn_ctx: impl AsRef<DownloadContext<'a
 #[cfg(not(test))]
 pub(crate) fn download_beta_toolchain<'a>(dwn_ctx: impl AsRef<DownloadContext<'a>>, out: &Path) {
     let dwn_ctx = dwn_ctx.as_ref();
-    dwn_ctx.exec_ctx.verbose(|| {
+    dwn_ctx.exec_ctx.do_if_verbose(|| {
         println!("downloading stage0 beta artifacts");
     });
 
@@ -812,7 +814,7 @@ fn download_component<'a>(
                 unpack(dwn_ctx.exec_ctx, &tarball, &bin_root, prefix);
                 return;
             } else {
-                dwn_ctx.exec_ctx.verbose(|| {
+                dwn_ctx.exec_ctx.do_if_verbose(|| {
                     println!(
                         "ignoring cached file {} due to failed verification",
                         tarball.display()
@@ -853,7 +855,7 @@ download-rustc = false
 pub(crate) fn verify(exec_ctx: &ExecutionContext, path: &Path, expected: &str) -> bool {
     use sha2::Digest;
 
-    exec_ctx.verbose(|| {
+    exec_ctx.do_if_verbose(|| {
         println!("verifying {}", path.display());
     });
 
@@ -934,7 +936,7 @@ fn unpack(exec_ctx: &ExecutionContext, tarball: &Path, dst: &Path, pattern: &str
         short_path = short_path.strip_prefix(pattern).unwrap_or(short_path);
         let dst_path = dst.join(short_path);
 
-        exec_ctx.verbose(|| {
+        exec_ctx.do_if_verbose(|| {
             println!("extracting {} to {}", original_path.display(), dst.display());
         });
 
@@ -965,7 +967,7 @@ fn download_file<'a>(
 ) {
     let dwn_ctx = dwn_ctx.as_ref();
 
-    dwn_ctx.exec_ctx.verbose(|| {
+    dwn_ctx.exec_ctx.do_if_verbose(|| {
         println!("download {url}");
     });
     // Use a temporary file in case we crash while downloading, to avoid a corrupt download in cache/.
diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs
index 68202500d97..91d80c96e42 100644
--- a/src/bootstrap/src/core/sanity.rs
+++ b/src/bootstrap/src/core/sanity.rs
@@ -38,6 +38,7 @@ const STAGE0_MISSING_TARGETS: &[&str] = &[
     // just a dummy comment so the list doesn't get onelined
     "aarch64_be-unknown-hermit",
     "aarch64_be-unknown-none-softfloat",
+    "x86_64-unknown-motor",
 ];
 
 /// Minimum version threshold for libstdc++ required when using prebuilt LLVM
@@ -239,6 +240,10 @@ than building it.
             continue;
         }
 
+        if target.contains("motor") {
+            continue;
+        }
+
         // skip check for cross-targets
         if skip_target_sanity && target != &build.host_target {
             continue;
diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs
index e953fe2945e..4f4d35673d5 100644
--- a/src/bootstrap/src/lib.rs
+++ b/src/bootstrap/src/lib.rs
@@ -415,7 +415,7 @@ macro_rules! forward {
 }
 
 forward! {
-    verbose(f: impl Fn()),
+    do_if_verbose(f: impl Fn()),
     is_verbose() -> bool,
     create(path: &Path, s: &str),
     remove(f: &Path),
@@ -601,11 +601,11 @@ impl Build {
             .unwrap()
             .trim();
         if local_release.split('.').take(2).eq(version.split('.').take(2)) {
-            build.verbose(|| println!("auto-detected local-rebuild {local_release}"));
+            build.do_if_verbose(|| println!("auto-detected local-rebuild {local_release}"));
             build.local_rebuild = true;
         }
 
-        build.verbose(|| println!("finding compilers"));
+        build.do_if_verbose(|| println!("finding compilers"));
         utils::cc_detect::fill_compilers(&mut build);
         // When running `setup`, the profile is about to change, so any requirements we have now may
         // be different on the next invocation. Don't check for them until the next time x.py is
@@ -613,7 +613,7 @@ impl Build {
         //
         // Similarly, for `setup` we don't actually need submodules or cargo metadata.
         if !matches!(build.config.cmd, Subcommand::Setup { .. }) {
-            build.verbose(|| println!("running sanity check"));
+            build.do_if_verbose(|| println!("running sanity check"));
             crate::core::sanity::check(&mut build);
 
             // Make sure we update these before gathering metadata so we don't get an error about missing
@@ -631,7 +631,7 @@ impl Build {
             // Now, update all existing submodules.
             build.update_existing_submodules();
 
-            build.verbose(|| println!("learning about cargo"));
+            build.do_if_verbose(|| println!("learning about cargo"));
             crate::core::metadata::build(&mut build);
         }
 
@@ -1087,18 +1087,6 @@ impl Build {
         })
     }
 
-    /// Check if verbosity is greater than the `level`
-    pub fn is_verbose_than(&self, level: usize) -> bool {
-        self.verbosity > level
-    }
-
-    /// Runs a function if verbosity is greater than `level`.
-    fn verbose_than(&self, level: usize, f: impl Fn()) {
-        if self.is_verbose_than(level) {
-            f()
-        }
-    }
-
     fn info(&self, msg: &str) {
         match self.config.get_dry_run() {
             DryRun::SelfCheck => (),
@@ -1816,7 +1804,6 @@ impl Build {
         if self.config.dry_run() {
             return;
         }
-        self.verbose_than(1, || println!("Copy/Link {src:?} to {dst:?}"));
         if src == dst {
             return;
         }
@@ -1933,7 +1920,10 @@ impl Build {
             return;
         }
         let dst = dstdir.join(src.file_name().unwrap());
-        self.verbose_than(1, || println!("Install {src:?} to {dst:?}"));
+
+        #[cfg(feature = "tracing")]
+        let _span = trace_io!("install", ?src, ?dst);
+
         t!(fs::create_dir_all(dstdir));
         if !src.exists() {
             panic!("ERROR: File \"{}\" not found!", src.display());
diff --git a/src/bootstrap/src/utils/build_stamp.rs b/src/bootstrap/src/utils/build_stamp.rs
index 4c35388a181..5cd68f6d4fe 100644
--- a/src/bootstrap/src/utils/build_stamp.rs
+++ b/src/bootstrap/src/utils/build_stamp.rs
@@ -112,7 +112,7 @@ pub fn clear_if_dirty(builder: &Builder<'_>, dir: &Path, input: &Path) -> bool {
     let stamp = BuildStamp::new(dir);
     let mut cleared = false;
     if mtime(stamp.path()) < mtime(input) {
-        builder.verbose(|| println!("Dirty - {}", dir.display()));
+        builder.do_if_verbose(|| println!("Dirty - {}", dir.display()));
         let _ = fs::remove_dir_all(dir);
         cleared = true;
     } else if stamp.path().exists() {
diff --git a/src/bootstrap/src/utils/cc_detect.rs b/src/bootstrap/src/utils/cc_detect.rs
index d3926df9650..0662ae304ac 100644
--- a/src/bootstrap/src/utils/cc_detect.rs
+++ b/src/bootstrap/src/utils/cc_detect.rs
@@ -137,16 +137,16 @@ pub fn fill_target_compiler(build: &mut Build, target: TargetSelection) {
         build.cxx.insert(target, compiler);
     }
 
-    build.verbose(|| println!("CC_{} = {:?}", target.triple, build.cc(target)));
-    build.verbose(|| println!("CFLAGS_{} = {cflags:?}", target.triple));
+    build.do_if_verbose(|| println!("CC_{} = {:?}", target.triple, build.cc(target)));
+    build.do_if_verbose(|| println!("CFLAGS_{} = {cflags:?}", target.triple));
     if let Ok(cxx) = build.cxx(target) {
         let mut cxxflags = build.cc_handled_clags(target, CLang::Cxx);
         cxxflags.extend(build.cc_unhandled_cflags(target, GitRepo::Rustc, CLang::Cxx));
-        build.verbose(|| println!("CXX_{} = {cxx:?}", target.triple));
-        build.verbose(|| println!("CXXFLAGS_{} = {cxxflags:?}", target.triple));
+        build.do_if_verbose(|| println!("CXX_{} = {cxx:?}", target.triple));
+        build.do_if_verbose(|| println!("CXXFLAGS_{} = {cxxflags:?}", target.triple));
     }
     if let Some(ar) = ar {
-        build.verbose(|| println!("AR_{} = {ar:?}", target.triple));
+        build.do_if_verbose(|| println!("AR_{} = {ar:?}", target.triple));
         build.ar.insert(target, ar);
     }
 
diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs
index e09f3086b77..f875e6e1af7 100644
--- a/src/bootstrap/src/utils/exec.rs
+++ b/src/bootstrap/src/utils/exec.rs
@@ -630,7 +630,7 @@ impl ExecutionContext {
         &self.dry_run
     }
 
-    pub fn verbose(&self, f: impl Fn()) {
+    pub fn do_if_verbose(&self, f: impl Fn()) {
         if self.is_verbose() {
             f()
         }
@@ -686,7 +686,7 @@ impl ExecutionContext {
 
         if let Some(cached_output) = self.command_cache.get(&fingerprint) {
             command.mark_as_executed();
-            self.verbose(|| println!("Cache hit: {command:?}"));
+            self.do_if_verbose(|| println!("Cache hit: {command:?}"));
             self.profiler.record_cache_hit(fingerprint);
             return DeferredCommand { state: CommandState::Cached(cached_output) };
         }
@@ -713,7 +713,7 @@ impl ExecutionContext {
             };
         }
 
-        self.verbose(|| {
+        self.do_if_verbose(|| {
             println!("running: {command:?} (created at {created_at}, executed at {executed_at})")
         });
 
diff --git a/src/bootstrap/src/utils/helpers/tests.rs b/src/bootstrap/src/utils/helpers/tests.rs
index 9030ca2820a..676fe6cbd5f 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]
@@ -59,8 +60,7 @@ fn test_check_cfg_arg() {
 
 #[test]
 fn test_symlink_dir() {
-    let config =
-        Config::parse(Flags::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]));
+    let config = TestCtx::new().config("check").no_dry_run().create_config();
     let tempdir = config.tempdir().join(".tmp-dir");
     let link_path = config.tempdir().join(".tmp-link");
 
@@ -80,8 +80,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");
 
     {
@@ -102,9 +101,7 @@ fn test_set_file_times_sanity_check() {
 
 #[test]
 fn test_submodule_path_of() {
-    let config = Config::parse_inner(Flags::parse(&["build".into(), "--dry-run".into()]), |&_| {
-        Ok(Default::default())
-    });
+    let config = TestCtx::new().config("build").create_config();
 
     let build = crate::Build::new(config.clone());
     let builder = crate::core::builder::Builder::new(&build);
diff --git a/src/bootstrap/src/utils/render_tests.rs b/src/bootstrap/src/utils/render_tests.rs
index 90fd57d976d..e90a7ef4232 100644
--- a/src/bootstrap/src/utils/render_tests.rs
+++ b/src/bootstrap/src/utils/render_tests.rs
@@ -48,7 +48,7 @@ pub(crate) fn try_run_tests(
 }
 
 fn run_tests(builder: &Builder<'_>, cmd: &mut BootstrapCommand, stream: bool) -> bool {
-    builder.verbose(|| println!("running: {cmd:?}"));
+    builder.do_if_verbose(|| println!("running: {cmd:?}"));
 
     let Some(mut streaming_command) = cmd.stream_capture_stdout(&builder.config.exec_ctx) else {
         return true;
diff --git a/src/bootstrap/src/utils/tarball.rs b/src/bootstrap/src/utils/tarball.rs
index 7b77b212934..079afb7a005 100644
--- a/src/bootstrap/src/utils/tarball.rs
+++ b/src/bootstrap/src/utils/tarball.rs
@@ -356,7 +356,7 @@ impl<'a> Tarball<'a> {
 
         // For `x install` tarball files aren't needed, so we can speed up the process by not producing them.
         let compression_profile = if self.builder.kind == Kind::Install {
-            self.builder.verbose(|| {
+            self.builder.do_if_verbose(|| {
                 println!("Forcing dist.compression-profile = 'no-op' for `x install`.")
             });
             // "no-op" indicates that the rust-installer won't produce compressed tarball sources.
diff --git a/src/bootstrap/src/utils/tests/mod.rs b/src/bootstrap/src/utils/tests/mod.rs
index 3332187e2a8..764b89086cf 100644
--- a/src/bootstrap/src/utils/tests/mod.rs
+++ b/src/bootstrap/src/utils/tests/mod.rs
@@ -48,11 +48,20 @@ impl TestCtx {
 pub struct ConfigBuilder {
     args: Vec<String>,
     directory: PathBuf,
+    override_download_ci_llvm: bool,
+    dry_run: bool,
+    explicit_config: bool,
 }
 
 impl ConfigBuilder {
     fn from_args(args: &[&str], directory: PathBuf) -> Self {
-        Self { args: args.iter().copied().map(String::from).collect(), directory }
+        Self {
+            args: args.iter().copied().map(String::from).collect(),
+            directory,
+            override_download_ci_llvm: true,
+            dry_run: true,
+            explicit_config: true,
+        }
     }
 
     pub fn path(mut self, path: &str) -> Self {
@@ -98,18 +107,46 @@ impl ConfigBuilder {
         self
     }
 
-    pub fn create_config(mut self) -> Config {
-        // Run in dry-check, otherwise the test would be too slow
-        self.args.push("--dry-run".to_string());
+    pub fn with_default_toml_config(mut self, config_toml: &str) -> Self {
+        let toml_path = self.directory.join("bootstrap.toml");
+        std::fs::write(&toml_path, config_toml).unwrap();
+        self.explicit_config = false;
+        self.args.push("--config".to_string());
+        self.args.push(toml_path.display().to_string());
+        self
+    }
+
+    pub fn no_override_download_ci_llvm(mut self) -> Self {
+        self.override_download_ci_llvm = false;
+        self
+    }
+
+    pub fn no_dry_run(mut self) -> Self {
+        self.dry_run = false;
+        self
+    }
 
+    pub fn create_config(mut self) -> Config {
+        if self.dry_run {
+            // Run in dry-check, otherwise the test would be too slow
+            self.args.push("--dry-run".to_string());
+        }
         // Ignore submodules
         self.args.push("--set".to_string());
         self.args.push("build.submodules=false".to_string());
 
-        // Override any external LLVM set and inhibit CI LLVM; pretend that we're always building
-        // in-tree LLVM from sources.
-        self.args.push("--set".to_string());
-        self.args.push("llvm.download-ci-llvm=false".to_string());
+        if self.override_download_ci_llvm {
+            // Override any external LLVM set and inhibit CI LLVM; pretend that we're always building
+            // in-tree LLVM from sources.
+            self.args.push("--set".to_string());
+            self.args.push("llvm.download-ci-llvm=false".to_string());
+        }
+
+        // always use the bootstrap toml created in the
+        // temporary directory and not from the <src>
+        if self.explicit_config {
+            self = self.with_default_toml_config("");
+        }
 
         // Do not mess with the local rustc checkout build directory
         self.args.push("--build-dir".to_string());