diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 330f66c1df0df..fd2a41f13ba80 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -22,6 +22,20 @@ use crate::compile; use crate::cache::{INTERNER, Interned}; use crate::config::Config; +fn doc_dir( + builder: &Builder<'_>, + compiler: Compiler, + target: Interned, + mode: Mode, +) -> PathBuf { + let compiler = if builder.force_use_stage1(compiler, target) { + builder.compiler(1, compiler.host) + } else { + compiler + }; + builder.stage_out(compiler, mode).join(target).join("doc") +} + macro_rules! book { ($($name:ident, $path:expr, $book_name:expr, $book_ver:expr;)+) => { $( @@ -476,15 +490,9 @@ impl Step for Std { let out = builder.doc_out(target); t!(fs::create_dir_all(&out)); let compiler = builder.compiler(stage, builder.config.build); - let compiler = if builder.force_use_stage1(compiler, target) { - builder.compiler(1, compiler.host) - } else { - compiler - }; builder.ensure(compile::Std { compiler, target }); - let out_dir = builder.stage_out(compiler, Mode::Std) - .join(target).join("doc"); + let out_dir = doc_dir(builder, compiler, target, Mode::Std); // Here what we're doing is creating a *symlink* (directory junction on // Windows) to the final output location. This is not done as an @@ -564,18 +572,12 @@ impl Step for Test { let out = builder.doc_out(target); t!(fs::create_dir_all(&out)); let compiler = builder.compiler(stage, builder.config.build); - let compiler = if builder.force_use_stage1(compiler, target) { - builder.compiler(1, compiler.host) - } else { - compiler - }; // Build libstd docs so that we generate relative links builder.ensure(Std { stage, target }); builder.ensure(compile::Test { compiler, target }); - let out_dir = builder.stage_out(compiler, Mode::Test) - .join(target).join("doc"); + let out_dir = doc_dir(builder, compiler, target, Mode::Test); // See docs in std above for why we symlink let my_out = builder.crate_doc_out(target); @@ -633,18 +635,12 @@ impl Step for WhitelistedRustc { let out = builder.doc_out(target); t!(fs::create_dir_all(&out)); let compiler = builder.compiler(stage, builder.config.build); - let compiler = if builder.force_use_stage1(compiler, target) { - builder.compiler(1, compiler.host) - } else { - compiler - }; // Build libstd docs so that we generate relative links builder.ensure(Std { stage, target }); builder.ensure(compile::Rustc { compiler, target }); - let out_dir = builder.stage_out(compiler, Mode::Rustc) - .join(target).join("doc"); + let out_dir = doc_dir(builder, compiler, target, Mode::Rustc); // See docs in std above for why we symlink let my_out = builder.crate_doc_out(target); @@ -707,11 +703,6 @@ impl Step for Rustc { // Get the correct compiler for this stage. let compiler = builder.compiler(stage, builder.config.build); - let compiler = if builder.force_use_stage1(compiler, target) { - builder.compiler(1, compiler.host) - } else { - compiler - }; if !builder.config.compiler_docs { builder.info("\tskipping - compiler/librustdoc docs disabled"); @@ -723,7 +714,7 @@ impl Step for Rustc { // We do not symlink to the same shared folder that already contains std library // documentation from previous steps as we do not want to include that. - let out_dir = builder.stage_out(compiler, Mode::Rustc).join(target).join("doc"); + let out_dir = doc_dir(builder, compiler, target, Mode::Rustc); t!(symlink_dir_force(&builder.config, &out, &out_dir)); // Build cargo command. @@ -808,11 +799,6 @@ impl Step for Rustdoc { // Get the correct compiler for this stage. let compiler = builder.compiler(stage, builder.config.build); - let compiler = if builder.force_use_stage1(compiler, target) { - builder.compiler(1, compiler.host) - } else { - compiler - }; if !builder.config.compiler_docs { builder.info("\tskipping - compiler/librustdoc docs disabled"); @@ -826,9 +812,7 @@ impl Step for Rustdoc { builder.ensure(tool::Rustdoc { compiler: compiler }); // Symlink compiler docs to the output directory of rustdoc documentation. - let out_dir = builder.stage_out(compiler, Mode::ToolRustc) - .join(target) - .join("doc"); + let out_dir = doc_dir(builder, compiler, target, Mode::ToolRustc); t!(fs::create_dir_all(&out_dir)); t!(symlink_dir_force(&builder.config, &out, &out_dir)); diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index c552f607960b4..7a09c1e14392c 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1678,16 +1678,6 @@ impl Step for Crate { builder.ensure(compile::Test { compiler, target }); builder.ensure(RemoteCopyLibs { compiler, target }); - // If we're not doing a full bootstrap but we're testing a stage2 version of - // libstd, then what we're actually testing is the libstd produced in - // stage1. Reflect that here by updating the compiler that we're working - // with automatically. - let compiler = if builder.force_use_stage1(compiler, target) { - builder.compiler(1, compiler.host) - } else { - compiler.clone() - }; - let mut cargo = builder.cargo(compiler, mode, target, test_kind.subcommand()); match mode { Mode::Std => { diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index 23775a91e4ce0..3a69919b63a77 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -3,6 +3,7 @@ use std::env; use std::path::PathBuf; use std::process::{Command, exit}; use std::collections::HashSet; +use std::sync::Mutex; use crate::Mode; use crate::Compiler; @@ -436,6 +437,7 @@ pub struct Rustdoc { pub compiler: Compiler, } + impl Step for Rustdoc { type Output = PathBuf; const DEFAULT: bool = true; @@ -452,6 +454,21 @@ impl Step for Rustdoc { } fn run(self, builder: &Builder<'_>) -> PathBuf { + lazy_static! { + static ref BUILT_RUSTDOC_IN: Mutex> = Mutex::new(Vec::new()); + } + { + let mut built = BUILT_RUSTDOC_IN.lock().unwrap(); + if !built.contains(&self.compiler.stage) { + built.push(self.compiler.stage); + assert_eq!( + built.len(), + 1, + "Only ever build one copy of rustdoc per run, currently built in stages {:?}", + built, + ); + } + } let target_compiler = self.compiler; if target_compiler.stage == 0 { if !target_compiler.is_snapshot(builder) {