rustbuild: Fixup calling rustdoc in various stages

The stage0 rustdoc comes from the snapshot, and we need a shim like with `rustc`
to pass `--cfg` for now.
This commit is contained in:
Alex Crichton 2016-03-07 23:11:05 -08:00
parent 0788cd23ea
commit f7b7535fd7
6 changed files with 76 additions and 11 deletions

View File

@ -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"

View File

@ -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);
}

View File

@ -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));
}

View File

@ -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

View File

@ -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;

31
src/bootstrap/rustdoc.rs Normal file
View File

@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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::<Vec<_>>();
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),
})
}