diff options
| author | Mark Simulacrum <mark.simulacrum@gmail.com> | 2017-07-22 20:01:58 -0600 |
|---|---|---|
| committer | Mark Simulacrum <mark.simulacrum@gmail.com> | 2017-07-27 05:51:22 -0600 |
| commit | e2e9b40e9aff842928c65606e47d9203a848a4e9 (patch) | |
| tree | e66fc893468c1041a1abfb8ee00021f995d70379 /src/bootstrap | |
| parent | fe0eca0d3f028affeccbc4c422d54c80b5837157 (diff) | |
| download | rust-e2e9b40e9aff842928c65606e47d9203a848a4e9.tar.gz rust-e2e9b40e9aff842928c65606e47d9203a848a4e9.zip | |
Build rustdoc on-demand.
Rustdoc is no longer compiled in every stage, alongside rustc, instead it is only compiled when requested, and generally only for the last stage.
Diffstat (limited to 'src/bootstrap')
| -rw-r--r-- | src/bootstrap/builder.rs | 28 | ||||
| -rw-r--r-- | src/bootstrap/check.rs | 3 | ||||
| -rw-r--r-- | src/bootstrap/compile.rs | 9 | ||||
| -rw-r--r-- | src/bootstrap/dist.rs | 3 | ||||
| -rw-r--r-- | src/bootstrap/doc.rs | 12 | ||||
| -rw-r--r-- | src/bootstrap/tool.rs | 53 |
6 files changed, 79 insertions, 29 deletions
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 7be391e5420..04730081e58 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -256,7 +256,7 @@ impl<'a> Builder<'a> { compile::StartupObjects, tool::BuildManifest, tool::Rustbook, tool::ErrorIndex, tool::UnstableBookGen, tool::Tidy, tool::Linkchecker, tool::CargoTest, tool::Compiletest, tool::RemoteTestServer, tool::RemoteTestClient, - tool::RustInstaller, tool::Cargo, tool::Rls), + tool::RustInstaller, tool::Cargo, tool::Rls, tool::Rustdoc), Kind::Test => describe!(check::Tidy, check::Bootstrap, check::DefaultCompiletest, check::HostCompiletest, check::Crate, check::CrateLibrustc, check::Linkcheck, check::Cargotest, check::Cargo, check::Rls, check::Docs, check::ErrorIndex, @@ -412,12 +412,22 @@ impl<'a> Builder<'a> { } } - /// Get the `rustdoc` executable next to the specified compiler pub fn rustdoc(&self, compiler: Compiler) -> PathBuf { - let mut rustdoc = self.rustc(compiler); - rustdoc.pop(); - rustdoc.push(exe("rustdoc", &compiler.host)); - rustdoc + self.ensure(tool::Rustdoc { target_compiler: compiler }) + } + + pub fn rustdoc_cmd(&self, compiler: Compiler) -> Command { + let mut cmd = Command::new(&self.out.join("bootstrap/debug/rustdoc")); + cmd + .env("RUSTC_STAGE", compiler.stage.to_string()) + .env("RUSTC_SYSROOT", if compiler.is_snapshot(&self.build) { + INTERNER.intern_path(self.build.rustc_snapshot_libdir()) + } else { + self.sysroot(compiler) + }) + .env("RUSTC_LIBDIR", self.sysroot_libdir(compiler, self.build.build)) + .env("RUSTDOC_REAL", self.rustdoc(compiler)); + cmd } /// Prepares an invocation of `cargo` to be run. @@ -469,7 +479,11 @@ impl<'a> Builder<'a> { .env("RUSTC_LIBDIR", self.rustc_libdir(compiler)) .env("RUSTC_RPATH", self.config.rust_rpath.to_string()) .env("RUSTDOC", self.out.join("bootstrap/debug/rustdoc")) - .env("RUSTDOC_REAL", self.rustdoc(compiler)) + .env("RUSTDOC_REAL", if cmd == "doc" || cmd == "test" { + self.rustdoc(compiler) + } else { + PathBuf::from("/path/to/nowhere/rustdoc/not/required") + }) .env("RUSTC_FLAGS", self.rustc_flags(target).join(" ")); if mode != Mode::Tool { diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index 07b027ce5ab..3b3b062b151 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -809,8 +809,7 @@ fn markdown_test(builder: &Builder, compiler: Compiler, markdown: &Path) { } println!("doc tests for: {}", markdown.display()); - let mut cmd = Command::new(builder.rustdoc(compiler)); - builder.add_rustc_lib_path(compiler, &mut cmd); + let mut cmd = builder.rustdoc_cmd(compiler); build.add_rust_test_threads(&mut cmd); cmd.arg("--test"); cmd.arg(markdown); diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 2e808c65684..92a42b59212 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -719,15 +719,6 @@ impl Step for Assemble { let _ = fs::remove_file(&compiler); copy(&rustc, &compiler); - // See if rustdoc exists to link it into place - let rustdoc = exe("rustdoc", &*host); - let rustdoc_src = out_dir.join(&rustdoc); - let rustdoc_dst = bindir.join(&rustdoc); - if fs::metadata(&rustdoc_src).is_ok() { - let _ = fs::remove_file(&rustdoc_dst); - copy(&rustdoc_src, &rustdoc_dst); - } - target_compiler } } diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index e5ededbfec7..c322d75dd5b 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -413,6 +413,9 @@ impl Step for Rustc { t!(fs::create_dir_all(image.join("bin"))); cp_r(&src.join("bin"), &image.join("bin")); + install(&builder.ensure(tool::Rustdoc { target_compiler: compiler }), + &image.join("bin"), 0o755); + // Copy runtime DLLs needed by the compiler if libdir != "bin" { for entry in t!(src.join(libdir).read_dir()).map(|e| t!(e)) { diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 249ed2a2223..88612db0d3a 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -21,7 +21,6 @@ use std::fs::{self, File}; use std::io::prelude::*; use std::io; use std::path::{PathBuf, Path}; -use std::process::Command; use Mode; use build_helper::up_to_date; @@ -242,12 +241,8 @@ fn invoke_rustdoc(builder: &Builder, target: Interned<String>, markdown: &str) { let build = builder.build; let out = build.doc_out(target); - let compiler = builder.compiler(0, build.build); - let path = build.src.join("src/doc").join(markdown); - let rustdoc = builder.rustdoc(compiler); - let favicon = build.src.join("src/doc/favicon.inc"); let footer = build.src.join("src/doc/footer.inc"); @@ -263,9 +258,7 @@ fn invoke_rustdoc(builder: &Builder, target: Interned<String>, markdown: &str) { t!(t!(File::create(&version_info)).write_all(info.as_bytes())); } - let mut cmd = Command::new(&rustdoc); - - builder.add_rustc_lib_path(compiler, &mut cmd); + let mut cmd = builder.rustdoc_cmd(builder.compiler(0, build.build)); let out = out.join("book"); @@ -357,8 +350,7 @@ impl Step for Standalone { continue } - let mut cmd = Command::new(&rustdoc); - builder.add_rustc_lib_path(compiler, &mut cmd); + let mut cmd = builder.rustdoc_cmd(compiler); cmd.arg("--html-after-content").arg(&footer) .arg("--html-before-content").arg(&version_info) .arg("--html-in-header").arg(&favicon) diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index f78792fc9b5..cbb312e2e4c 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::fs; use std::env; use std::path::PathBuf; use std::process::Command; @@ -15,7 +16,7 @@ use std::process::Command; use Mode; use Compiler; use builder::{Step, RunConfig, ShouldRun, Builder}; -use util::{exe, add_lib_path}; +use util::{copy, exe, add_lib_path}; use compile::{self, libtest_stamp, libstd_stamp, librustc_stamp}; use native; use channel::GitInfo; @@ -224,6 +225,56 @@ impl Step for RemoteTestServer { } #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub struct Rustdoc { + pub target_compiler: Compiler, +} + +impl Step for Rustdoc { + type Output = PathBuf; + const DEFAULT: bool = true; + const ONLY_HOSTS: bool = true; + + fn should_run(run: ShouldRun) -> ShouldRun { + run.path("src/tools/rustdoc") + } + + fn make_run(run: RunConfig) { + run.builder.ensure(Rustdoc { + target_compiler: run.builder.compiler(run.builder.top_stage, run.host), + }); + } + + fn run(self, builder: &Builder) -> PathBuf { + let target_compiler = self.target_compiler; + let build_compiler = if target_compiler.stage == 0 { + target_compiler + } else { + builder.compiler(target_compiler.stage - 1, target_compiler.host) + }; + + let tool_rustdoc = builder.ensure(ToolBuild { + compiler: build_compiler, + target: build_compiler.host, + tool: "rustdoc", + mode: Mode::Librustc, + }); + + // don't create a stage0-sysroot/bin directory. + if target_compiler.stage > 0 { + let sysroot = builder.sysroot(target_compiler); + let bindir = sysroot.join("bin"); + t!(fs::create_dir_all(&bindir)); + let bin_rustdoc = bindir.join(exe("rustdoc", &*target_compiler.host)); + let _ = fs::remove_file(&bin_rustdoc); + copy(&tool_rustdoc, &bin_rustdoc); + bin_rustdoc + } else { + tool_rustdoc + } + } +} + +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Cargo { pub compiler: Compiler, pub target: Interned<String>, |
