diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index 8321f93c90f..0d334219b4f 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -15,6 +15,10 @@ path = "main.rs" name = "rustc" path = "rustc.rs" +[[bin]] +name = "rustdoc" +path = "rustdoc.rs" + [dependencies] build_helper = { path = "../build_helper" } cmake = "0.1.10" diff --git a/src/bootstrap/build/compile.rs b/src/bootstrap/build/compile.rs index db8c3e50907..c4d6e66b878 100644 --- a/src/bootstrap/build/compile.rs +++ b/src/bootstrap/build/compile.rs @@ -325,4 +325,3 @@ pub fn tool(build: &Build, stage: u32, host: &str, tool: &str) { .arg(build.src.join(format!("src/tools/{}/Cargo.toml", tool))); build.run(&mut cargo); } - diff --git a/src/bootstrap/build/doc.rs b/src/bootstrap/build/doc.rs index 5107b4e1353..917860962c9 100644 --- a/src/bootstrap/build/doc.rs +++ b/src/bootstrap/build/doc.rs @@ -8,9 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::path::Path; use std::fs::{self, File}; use std::io::prelude::*; +use std::path::Path; +use std::process::Command; use build::{Build, Compiler, Mode}; use build::util::{up_to_date, cp_r}; @@ -69,7 +70,7 @@ pub fn standalone(build: &Build, stage: u32, host: &str, out: &Path) { } let html = out.join(filename).with_extension("html"); - let rustdoc = build.tool(&compiler, "rustdoc"); + let rustdoc = build.rustdoc(&compiler); if up_to_date(&path, &html) && up_to_date(&footer, &html) && up_to_date(&favicon, &html) && @@ -79,7 +80,7 @@ pub fn standalone(build: &Build, stage: u32, host: &str, out: &Path) { continue } - let mut cmd = build.tool_cmd(&compiler, "rustdoc"); + let mut cmd = Command::new(&rustdoc); cmd.arg("--html-after-content").arg(&footer) .arg("--html-before-content").arg(&version_info) .arg("--html-in-header").arg(&favicon) @@ -108,10 +109,9 @@ pub fn std(build: &Build, stage: u32, host: &str, out: &Path) { let compiler = Compiler::new(stage, host); let out_dir = build.stage_out(stage, host, Mode::Libstd) .join(host).join("doc"); - let rustdoc = build.tool(&compiler, "rustdoc"); - if !up_to_date(&rustdoc, &out_dir.join("std/index.html")) { - t!(fs::remove_dir_all(&out_dir)); - } + let rustdoc = build.rustdoc(&compiler); + + build.clear_if_dirty(&out_dir, &rustdoc); let mut cargo = build.cargo(stage, &compiler, Mode::Libstd, Some(host), "doc"); @@ -127,7 +127,7 @@ pub fn rustc(build: &Build, stage: u32, host: &str, out: &Path) { let compiler = Compiler::new(stage, host); let out_dir = build.stage_out(stage, host, Mode::Librustc) .join(host).join("doc"); - let rustdoc = build.tool(&compiler, "rustdoc"); + let rustdoc = build.rustdoc(&compiler); if !up_to_date(&rustdoc, &out_dir.join("rustc/index.html")) { t!(fs::remove_dir_all(&out_dir)); } diff --git a/src/bootstrap/build/mod.rs b/src/bootstrap/build/mod.rs index 3acd34b4e94..825cca6563c 100644 --- a/src/bootstrap/build/mod.rs +++ b/src/bootstrap/build/mod.rs @@ -275,7 +275,8 @@ impl Build { .env("RUSTC_SYSROOT", self.sysroot(stage, host)) .env("RUSTC_SNAPSHOT_LIBDIR", self.rustc_snapshot_libdir()) .env("RUSTC_RPATH", self.config.rust_rpath.to_string()) - .env("RUSTDOC", self.tool(compiler, "rustdoc")); + .env("RUSTDOC", self.out.join("bootstrap/debug/rustdoc")) + .env("RUSTDOC_REAL", self.rustdoc(compiler)); if let Some(target) = target { cargo.env("RUSTC_FLAGS", self.rustc_flags(target).join(" ")); @@ -317,13 +318,26 @@ impl Build { } } - /// Get the specified tool next to the specified compiler + /// Get the specified tool built by the specified compiler fn tool(&self, compiler: &Compiler, tool: &str) -> PathBuf { self.stage_out(compiler.stage, compiler.host, Mode::Tool) .join(self.cargo_dir()) .join(exe(tool, compiler.host)) } + /// Get the `rustdoc` executable next to the specified compiler + fn rustdoc(&self, compiler: &Compiler) -> PathBuf { + let root = if compiler.is_snapshot(self) { + let mut rustdoc = self.rustc.clone(); + rustdoc.pop(); + rustdoc + } else { + let (stage, host) = (compiler.stage, compiler.host); + self.cargo_out(stage - 1, host, Mode::Librustc, host) + }; + root.join(exe("rustdoc", compiler.host)) + } + /// Get a `Command` which is ready to run `tool` in `stage` built for /// `host`. #[allow(dead_code)] // this will be used soon diff --git a/src/bootstrap/rustc.rs b/src/bootstrap/rustc.rs index 4e9d6da9157..d403d76bb14 100644 --- a/src/bootstrap/rustc.rs +++ b/src/bootstrap/rustc.rs @@ -8,6 +8,23 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +//! Shim which is passed to Cargo as "rustc" when running the bootstrap. +//! +//! This shim will take care of some various tasks that our build process +//! requires that Cargo can't quite do through normal configuration: +//! +//! 1. When compiling build scripts and build dependencies, we need a guaranteed +//! full standard library available. The only compiler which actually has +//! this is the snapshot, so we detect this situation and always compile with +//! the snapshot compiler. +//! 2. We pass a bunch of `--cfg` and other flags based on what we're compiling +//! (and this slightly differs based on a whether we're using a snapshot or +//! not), so we do that all here. +//! +//! This may one day be replaced by RUSTFLAGS, but the dynamic nature of +//! switching compilers for the bootstrap and for build scripts will probably +//! never get replaced. + extern crate bootstrap; use std::env; diff --git a/src/bootstrap/rustdoc.rs b/src/bootstrap/rustdoc.rs new file mode 100644 index 00000000000..8c618196113 --- /dev/null +++ b/src/bootstrap/rustdoc.rs @@ -0,0 +1,31 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Shim which is passed to Cargo as "rustdoc" when running the bootstrap. +//! +//! See comments in `src/bootstrap/rustc.rs` for more information. + +use std::env; +use std::process::Command; + +fn main() { + let args = env::args_os().skip(1).collect::>(); + let rustdoc = env::var_os("RUSTDOC_REAL").unwrap(); + + let mut cmd = Command::new(rustdoc); + cmd.args(&args) + .arg("--cfg").arg(format!("stage{}", env::var("RUSTC_STAGE").unwrap())) + .arg("--cfg").arg("dox"); + std::process::exit(match cmd.status() { + Ok(s) => s.code().unwrap_or(1), + Err(e) => panic!("\n\nfailed to run {:?}: {}\n\n", cmd, e), + }) +} +