From f6611d34f13be7b105a6eda384aa25e30f3c733b Mon Sep 17 00:00:00 2001 From: jyn Date: Sat, 3 Jun 2023 14:14:54 -0500 Subject: [PATCH 1/4] Don't compile rustc to self-test compiletest This was changed from stage 0 to 1 in https://github.com/rust-lang/rust/pull/108905, but I'm not sure why. Change it to `top_stage` instead to allow people to choose the stage. This should save quite a bit of time in the `mingw-check` builder, which explicitly runs `x test --stage 0 compiletest`. --- src/bootstrap/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index eec8c4ad69f23..6a1e4556de85d 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -700,7 +700,7 @@ impl Step for CompiletestTest { /// Runs `cargo test` for compiletest. fn run(self, builder: &Builder<'_>) { let host = self.host; - let compiler = builder.compiler(1, host); + let compiler = builder.compiler(builder.top_stage, host); // We need `ToolStd` for the locally-built sysroot because // compiletest uses unstable features of the `test` crate. From c57eb1bb6e8284b141f715d83c4572559652586e Mon Sep 17 00:00:00 2001 From: jyn Date: Sat, 3 Jun 2023 14:31:36 -0500 Subject: [PATCH 2/4] rename src/dst to original/link this is consistent with std and makes it much easier to understand what's actually happening --- src/bootstrap/doc.rs | 10 +++++----- src/bootstrap/util.rs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index d6210ed59c4d1..15337a4f8d672 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -959,21 +959,21 @@ impl Step for UnstableBookGen { } } -fn symlink_dir_force(config: &Config, src: &Path, dst: &Path) -> io::Result<()> { +fn symlink_dir_force(config: &Config, original: &Path, link: &Path) -> io::Result<()> { if config.dry_run() { return Ok(()); } - if let Ok(m) = fs::symlink_metadata(dst) { + if let Ok(m) = fs::symlink_metadata(link) { if m.file_type().is_dir() { - fs::remove_dir_all(dst)?; + fs::remove_dir_all(link)?; } else { // handle directory junctions on windows by falling back to // `remove_dir`. - fs::remove_file(dst).or_else(|_| fs::remove_dir(dst))?; + fs::remove_file(link).or_else(|_| fs::remove_dir(link))?; } } - symlink_dir(config, src, dst) + symlink_dir(config, original, link) } #[derive(Ord, PartialOrd, Debug, Copy, Clone, Hash, PartialEq, Eq)] diff --git a/src/bootstrap/util.rs b/src/bootstrap/util.rs index e4bbccdb067c2..7e29f671f028b 100644 --- a/src/bootstrap/util.rs +++ b/src/bootstrap/util.rs @@ -134,17 +134,17 @@ pub(crate) fn program_out_of_date(stamp: &Path, key: &str) -> bool { /// Symlinks two directories, using junctions on Windows and normal symlinks on /// Unix. -pub fn symlink_dir(config: &Config, src: &Path, dest: &Path) -> io::Result<()> { +pub fn symlink_dir(config: &Config, original: &Path, link: &Path) -> io::Result<()> { if config.dry_run() { return Ok(()); } - let _ = fs::remove_dir(dest); - return symlink_dir_inner(src, dest); + let _ = fs::remove_dir(link); + return symlink_dir_inner(original, link); #[cfg(not(windows))] - fn symlink_dir_inner(src: &Path, dest: &Path) -> io::Result<()> { + fn symlink_dir_inner(original: &Path, link: &Path) -> io::Result<()> { use std::os::unix::fs; - fs::symlink(src, dest) + fs::symlink(original, link) } #[cfg(windows)] From 3f05b1fb2c90c88bbd5853928653247ad79b7047 Mon Sep 17 00:00:00 2001 From: jyn Date: Sat, 3 Jun 2023 14:45:43 -0500 Subject: [PATCH 3/4] don't return a `Result` from symlink_dir_force this gives a more helpful backtrace if it fails before: ``` thread 'main' panicked at 'symlink_dir_force(&builder.config, &out, &out_dir) failed with No such file or directory (os error 2)', doc.rs:697:9 ``` after: ``` thread 'main' panicked at 'symlink_dir(config, original, link) failed with No such file or directory (os error 2) ("failed to create link from /home/jyn/src/rust2/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/doc -> /home/jyn/src/rust2/build/x86_64-unknown-linux-gnu/compiler-doc")', doc.rs:975:5 ``` --- src/bootstrap/doc.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 15337a4f8d672..be3d7aacafdd8 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -8,7 +8,6 @@ //! `rustdoc`. use std::fs; -use std::io; use std::path::{Path, PathBuf}; use crate::builder::crate_description; @@ -694,11 +693,11 @@ impl Step for Rustc { // rustc. rustdoc needs to be able to see everything, for example when // merging the search index, or generating local (relative) links. let out_dir = builder.stage_out(compiler, Mode::Rustc).join(target.triple).join("doc"); - t!(symlink_dir_force(&builder.config, &out, &out_dir)); + symlink_dir_force(&builder.config, &out, &out_dir); // Cargo puts proc macros in `target/doc` even if you pass `--target` // explicitly (https://github.com/rust-lang/cargo/issues/7677). let proc_macro_out_dir = builder.stage_out(compiler, Mode::Rustc).join("doc"); - t!(symlink_dir_force(&builder.config, &out, &proc_macro_out_dir)); + symlink_dir_force(&builder.config, &out, &proc_macro_out_dir); // Build cargo command. let mut cargo = builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "doc"); @@ -816,7 +815,7 @@ macro_rules! tool_doc { ]; for out_dir in out_dirs { t!(fs::create_dir_all(&out_dir)); - t!(symlink_dir_force(&builder.config, &out, &out_dir)); + symlink_dir_force(&builder.config, &out, &out_dir); } // Build cargo command. @@ -959,21 +958,24 @@ impl Step for UnstableBookGen { } } -fn symlink_dir_force(config: &Config, original: &Path, link: &Path) -> io::Result<()> { +fn symlink_dir_force(config: &Config, original: &Path, link: &Path) { if config.dry_run() { - return Ok(()); + return; } if let Ok(m) = fs::symlink_metadata(link) { if m.file_type().is_dir() { - fs::remove_dir_all(link)?; + t!(fs::remove_dir_all(link)); } else { // handle directory junctions on windows by falling back to // `remove_dir`. - fs::remove_file(link).or_else(|_| fs::remove_dir(link))?; + t!(fs::remove_file(link).or_else(|_| fs::remove_dir(link))); } } - symlink_dir(config, original, link) + t!( + symlink_dir(config, original, link), + format!("failed to create link from {} -> {}", link.display(), original.display()) + ); } #[derive(Ord, PartialOrd, Debug, Copy, Clone, Hash, PartialEq, Eq)] From d613134623d1659ece542a02b585b70cbf36c2b5 Mon Sep 17 00:00:00 2001 From: jyn Date: Sat, 3 Jun 2023 14:46:22 -0500 Subject: [PATCH 4/4] fix `x doc --stage 0 compiler` if the compiler hasn't yet been built --- src/bootstrap/doc.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index be3d7aacafdd8..f3716c81e11ec 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -693,6 +693,7 @@ impl Step for Rustc { // rustc. rustdoc needs to be able to see everything, for example when // merging the search index, or generating local (relative) links. let out_dir = builder.stage_out(compiler, Mode::Rustc).join(target.triple).join("doc"); + t!(fs::create_dir_all(out_dir.parent().unwrap())); symlink_dir_force(&builder.config, &out, &out_dir); // Cargo puts proc macros in `target/doc` even if you pass `--target` // explicitly (https://github.com/rust-lang/cargo/issues/7677).