2016-02-16 18:26:43 +00:00
|
|
|
// 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.
|
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
//! Documentation generation for rustbuilder.
|
2016-05-02 22:16:15 +00:00
|
|
|
//!
|
|
|
|
//! This module implements generation for all bits and pieces of documentation
|
|
|
|
//! for the Rust project. This notably includes suites like the rust book, the
|
2017-12-02 02:29:12 +00:00
|
|
|
//! nomicon, rust by example, standalone documentation, etc.
|
2016-05-02 22:16:15 +00:00
|
|
|
//!
|
|
|
|
//! Everything here is basically just a shim around calling either `rustbook` or
|
|
|
|
//! `rustdoc`.
|
|
|
|
|
2018-03-22 14:57:28 +00:00
|
|
|
use std::collections::HashSet;
|
2016-02-16 18:26:43 +00:00
|
|
|
use std::fs::{self, File};
|
|
|
|
use std::io::prelude::*;
|
2017-03-01 23:34:54 +00:00
|
|
|
use std::io;
|
2017-07-14 00:48:44 +00:00
|
|
|
use std::path::{PathBuf, Path};
|
2016-02-16 18:26:43 +00:00
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
use Mode;
|
2017-01-31 21:27:51 +00:00
|
|
|
use build_helper::up_to_date;
|
2016-02-16 18:26:43 +00:00
|
|
|
|
2018-03-27 14:06:47 +00:00
|
|
|
use util::symlink_dir;
|
2017-07-25 23:56:06 +00:00
|
|
|
use builder::{Builder, Compiler, RunConfig, ShouldRun, Step};
|
2018-07-26 03:36:58 +00:00
|
|
|
use tool::{self, prepare_tool_cargo, Tool, SourceType};
|
2017-07-05 16:46:41 +00:00
|
|
|
use compile;
|
2017-07-14 00:48:44 +00:00
|
|
|
use cache::{INTERNER, Interned};
|
2018-03-27 14:06:47 +00:00
|
|
|
use config::Config;
|
2017-07-05 16:46:41 +00:00
|
|
|
|
2017-07-05 12:41:27 +00:00
|
|
|
macro_rules! book {
|
|
|
|
($($name:ident, $path:expr, $book_name:expr;)+) => {
|
|
|
|
$(
|
2017-07-14 00:48:44 +00:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct $name {
|
|
|
|
target: Interned<String>,
|
2017-07-05 12:41:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
impl Step for $name {
|
2017-07-05 12:41:27 +00:00
|
|
|
type Output = ();
|
|
|
|
const DEFAULT: bool = true;
|
|
|
|
|
2017-07-19 00:03:38 +00:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
2017-07-20 23:24:11 +00:00
|
|
|
let builder = run.builder;
|
2018-04-14 23:27:57 +00:00
|
|
|
run.path($path).default_condition(builder.config.docs)
|
2017-07-05 12:41:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 23:51:07 +00:00
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure($name {
|
|
|
|
target: run.target,
|
2017-07-05 12:41:27 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(self, builder: &Builder) {
|
|
|
|
builder.ensure(Rustbook {
|
|
|
|
target: self.target,
|
2017-07-14 00:48:44 +00:00
|
|
|
name: INTERNER.intern_str($book_name),
|
2017-07-05 12:41:27 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
book!(
|
2017-10-21 16:16:46 +00:00
|
|
|
Nomicon, "src/doc/nomicon", "nomicon";
|
2017-07-05 12:41:27 +00:00
|
|
|
Reference, "src/doc/reference", "reference";
|
2018-05-19 15:21:17 +00:00
|
|
|
RustdocBook, "src/doc/rustdoc", "rustdoc";
|
2018-04-05 18:41:48 +00:00
|
|
|
RustcBook, "src/doc/rustc", "rustc";
|
2017-12-02 02:29:12 +00:00
|
|
|
RustByExample, "src/doc/rust-by-example", "rust-by-example";
|
2017-07-05 12:41:27 +00:00
|
|
|
);
|
2017-07-05 01:41:43 +00:00
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
2017-07-19 00:03:38 +00:00
|
|
|
struct Rustbook {
|
2017-07-14 00:48:44 +00:00
|
|
|
target: Interned<String>,
|
|
|
|
name: Interned<String>,
|
2017-07-05 01:41:43 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
impl Step for Rustbook {
|
2017-07-05 01:41:43 +00:00
|
|
|
type Output = ();
|
|
|
|
|
2017-07-14 12:30:16 +00:00
|
|
|
// rustbook is never directly called, and only serves as a shim for the nomicon and the
|
|
|
|
// reference.
|
2017-07-19 00:03:38 +00:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
|
|
|
run.never()
|
2017-07-14 12:30:16 +00:00
|
|
|
}
|
|
|
|
|
2017-07-05 01:41:43 +00:00
|
|
|
/// Invoke `rustbook` for `target` for the doc book `name`.
|
|
|
|
///
|
|
|
|
/// This will not actually generate any documentation if the documentation has
|
|
|
|
/// already been generated.
|
|
|
|
fn run(self, builder: &Builder) {
|
2018-04-14 23:27:57 +00:00
|
|
|
let src = builder.src.join("src/doc");
|
2017-07-05 12:41:27 +00:00
|
|
|
builder.ensure(RustbookSrc {
|
|
|
|
target: self.target,
|
|
|
|
name: self.name,
|
2017-07-14 00:48:44 +00:00
|
|
|
src: INTERNER.intern_path(src),
|
2017-07-05 12:41:27 +00:00
|
|
|
});
|
2017-07-05 01:41:43 +00:00
|
|
|
}
|
2017-06-12 19:35:47 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct UnstableBook {
|
|
|
|
target: Interned<String>,
|
2017-07-05 12:41:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
impl Step for UnstableBook {
|
2017-07-05 12:41:27 +00:00
|
|
|
type Output = ();
|
|
|
|
const DEFAULT: bool = true;
|
|
|
|
|
2017-07-19 00:03:38 +00:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
2017-07-20 23:24:11 +00:00
|
|
|
let builder = run.builder;
|
2018-04-14 23:27:57 +00:00
|
|
|
run.path("src/doc/unstable-book").default_condition(builder.config.docs)
|
2017-07-05 12:41:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 23:51:07 +00:00
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(UnstableBook {
|
|
|
|
target: run.target,
|
2017-07-05 12:41:27 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(self, builder: &Builder) {
|
|
|
|
builder.ensure(UnstableBookGen {
|
|
|
|
target: self.target,
|
|
|
|
});
|
|
|
|
builder.ensure(RustbookSrc {
|
|
|
|
target: self.target,
|
2017-07-14 00:48:44 +00:00
|
|
|
name: INTERNER.intern_str("unstable-book"),
|
2018-04-14 23:27:57 +00:00
|
|
|
src: builder.md_doc_out(self.target),
|
2017-07-05 12:41:27 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2017-07-04 23:53:53 +00:00
|
|
|
|
2017-11-01 19:21:55 +00:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct CargoBook {
|
|
|
|
target: Interned<String>,
|
|
|
|
name: Interned<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Step for CargoBook {
|
|
|
|
type Output = ();
|
|
|
|
const DEFAULT: bool = true;
|
|
|
|
|
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
|
|
|
let builder = run.builder;
|
2018-04-14 23:27:57 +00:00
|
|
|
run.path("src/tools/cargo/src/doc/book").default_condition(builder.config.docs)
|
2017-11-01 19:21:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(CargoBook {
|
|
|
|
target: run.target,
|
|
|
|
name: INTERNER.intern_str("cargo"),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn run(self, builder: &Builder) {
|
|
|
|
let target = self.target;
|
|
|
|
let name = self.name;
|
2018-04-14 23:27:57 +00:00
|
|
|
let src = builder.src.join("src/tools/cargo/src/doc");
|
2017-11-01 19:24:35 +00:00
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
let out = builder.doc_out(target);
|
2017-11-01 19:21:55 +00:00
|
|
|
t!(fs::create_dir_all(&out));
|
|
|
|
|
|
|
|
let out = out.join(name);
|
2017-11-01 19:24:35 +00:00
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.info(&format!("Cargo Book ({}) - {}", target, name));
|
2017-11-01 19:24:35 +00:00
|
|
|
|
2017-11-01 19:21:55 +00:00
|
|
|
let _ = fs::remove_dir_all(&out);
|
2017-11-01 19:24:35 +00:00
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.run(builder.tool_cmd(Tool::Rustbook)
|
2017-11-01 19:21:55 +00:00
|
|
|
.arg("build")
|
|
|
|
.arg(&src)
|
|
|
|
.arg("-d")
|
|
|
|
.arg(out));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
2017-07-19 00:03:38 +00:00
|
|
|
struct RustbookSrc {
|
2017-07-14 00:48:44 +00:00
|
|
|
target: Interned<String>,
|
|
|
|
name: Interned<String>,
|
|
|
|
src: Interned<PathBuf>,
|
2017-07-05 01:41:43 +00:00
|
|
|
}
|
2017-07-04 23:53:53 +00:00
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
impl Step for RustbookSrc {
|
2017-07-05 01:41:43 +00:00
|
|
|
type Output = ();
|
|
|
|
|
2017-07-19 00:03:38 +00:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
|
|
|
run.never()
|
2017-07-14 12:30:16 +00:00
|
|
|
}
|
|
|
|
|
2017-07-05 01:41:43 +00:00
|
|
|
/// Invoke `rustbook` for `target` for the doc book `name` from the `src` path.
|
|
|
|
///
|
|
|
|
/// This will not actually generate any documentation if the documentation has
|
|
|
|
/// already been generated.
|
|
|
|
fn run(self, builder: &Builder) {
|
|
|
|
let target = self.target;
|
|
|
|
let name = self.name;
|
|
|
|
let src = self.src;
|
2018-04-14 23:27:57 +00:00
|
|
|
let out = builder.doc_out(target);
|
2017-07-05 01:41:43 +00:00
|
|
|
t!(fs::create_dir_all(&out));
|
|
|
|
|
|
|
|
let out = out.join(name);
|
|
|
|
let src = src.join(name);
|
|
|
|
let index = out.join("index.html");
|
2017-07-05 12:41:27 +00:00
|
|
|
let rustbook = builder.tool_exe(Tool::Rustbook);
|
2018-03-27 14:06:47 +00:00
|
|
|
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
|
2017-07-05 01:41:43 +00:00
|
|
|
if up_to_date(&src, &index) && up_to_date(&rustbook, &index) {
|
|
|
|
return
|
|
|
|
}
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.info(&format!("Rustbook ({}) - {}", target, name));
|
2017-07-05 01:41:43 +00:00
|
|
|
let _ = fs::remove_dir_all(&out);
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.run(rustbook_cmd
|
2017-07-05 01:41:43 +00:00
|
|
|
.arg("build")
|
|
|
|
.arg(&src)
|
|
|
|
.arg("-d")
|
|
|
|
.arg(out));
|
2016-02-16 18:26:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct TheBook {
|
2017-07-25 23:56:06 +00:00
|
|
|
compiler: Compiler,
|
2017-07-14 00:48:44 +00:00
|
|
|
target: Interned<String>,
|
|
|
|
name: &'static str,
|
2017-07-05 01:41:43 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
impl Step for TheBook {
|
2017-07-05 01:41:43 +00:00
|
|
|
type Output = ();
|
2017-07-14 04:37:33 +00:00
|
|
|
const DEFAULT: bool = true;
|
2017-07-05 01:41:43 +00:00
|
|
|
|
2017-07-19 00:03:38 +00:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
2017-07-20 23:24:11 +00:00
|
|
|
let builder = run.builder;
|
2018-04-14 23:27:57 +00:00
|
|
|
run.path("src/doc/book").default_condition(builder.config.docs)
|
2017-07-13 00:52:31 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 23:51:07 +00:00
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(TheBook {
|
2018-04-14 23:27:57 +00:00
|
|
|
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
|
2017-07-20 23:51:07 +00:00
|
|
|
target: run.target,
|
2017-07-13 00:52:31 +00:00
|
|
|
name: "book",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-07-05 01:41:43 +00:00
|
|
|
/// Build the book and associated stuff.
|
|
|
|
///
|
|
|
|
/// We need to build:
|
|
|
|
///
|
|
|
|
/// * Book (first edition)
|
|
|
|
/// * Book (second edition)
|
2017-11-15 02:57:03 +00:00
|
|
|
/// * Version info and CSS
|
2017-07-05 01:41:43 +00:00
|
|
|
/// * Index page
|
|
|
|
/// * Redirect pages
|
|
|
|
fn run(self, builder: &Builder) {
|
2017-11-15 02:57:03 +00:00
|
|
|
let compiler = self.compiler;
|
2017-07-05 01:41:43 +00:00
|
|
|
let target = self.target;
|
|
|
|
let name = self.name;
|
2018-11-20 19:57:56 +00:00
|
|
|
|
|
|
|
// build book
|
2017-07-05 12:41:27 +00:00
|
|
|
builder.ensure(Rustbook {
|
2017-08-07 05:54:09 +00:00
|
|
|
target,
|
2018-11-20 19:57:56 +00:00
|
|
|
name: INTERNER.intern_string(name.to_string()),
|
2017-07-05 12:41:27 +00:00
|
|
|
});
|
2017-07-05 01:41:43 +00:00
|
|
|
|
2018-11-20 19:57:56 +00:00
|
|
|
// building older edition redirects
|
|
|
|
|
|
|
|
let source_name = format!("{}/first-edition", name);
|
2017-07-05 12:41:27 +00:00
|
|
|
builder.ensure(Rustbook {
|
2017-08-07 05:54:09 +00:00
|
|
|
target,
|
2018-11-20 19:57:56 +00:00
|
|
|
name: INTERNER.intern_string(source_name),
|
2017-07-05 12:41:27 +00:00
|
|
|
});
|
2017-07-05 01:41:43 +00:00
|
|
|
|
2018-11-20 19:57:56 +00:00
|
|
|
let source_name = format!("{}/second-edition", name);
|
2018-05-21 19:31:12 +00:00
|
|
|
builder.ensure(Rustbook {
|
|
|
|
target,
|
2018-11-20 19:57:56 +00:00
|
|
|
name: INTERNER.intern_string(source_name),
|
|
|
|
});
|
|
|
|
|
|
|
|
let source_name = format!("{}/2018-edition", name);
|
|
|
|
builder.ensure(Rustbook {
|
|
|
|
target,
|
|
|
|
name: INTERNER.intern_string(source_name),
|
2018-05-21 19:31:12 +00:00
|
|
|
});
|
|
|
|
|
2017-11-15 02:57:03 +00:00
|
|
|
// build the version info page and CSS
|
|
|
|
builder.ensure(Standalone {
|
|
|
|
compiler,
|
|
|
|
target,
|
|
|
|
});
|
|
|
|
|
2017-07-05 01:41:43 +00:00
|
|
|
// build the redirect pages
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.info(&format!("Documenting book redirect pages ({})", target));
|
|
|
|
for file in t!(fs::read_dir(builder.src.join("src/doc/book/redirects"))) {
|
2017-07-05 01:41:43 +00:00
|
|
|
let file = t!(file);
|
|
|
|
let path = file.path();
|
|
|
|
let path = path.to_str().unwrap();
|
|
|
|
|
2017-11-15 02:57:03 +00:00
|
|
|
invoke_rustdoc(builder, compiler, target, path);
|
2017-07-05 01:41:43 +00:00
|
|
|
}
|
2017-03-07 21:07:55 +00:00
|
|
|
}
|
2017-03-07 20:31:41 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 23:56:06 +00:00
|
|
|
fn invoke_rustdoc(builder: &Builder, compiler: Compiler, target: Interned<String>, markdown: &str) {
|
2018-04-14 23:27:57 +00:00
|
|
|
let out = builder.doc_out(target);
|
2017-03-07 20:31:41 +00:00
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
let path = builder.src.join("src/doc").join(markdown);
|
2017-03-07 20:31:41 +00:00
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
let favicon = builder.src.join("src/doc/favicon.inc");
|
|
|
|
let footer = builder.src.join("src/doc/footer.inc");
|
2017-03-07 20:31:41 +00:00
|
|
|
let version_info = out.join("version_info.html");
|
|
|
|
|
2017-08-04 22:13:01 +00:00
|
|
|
let mut cmd = builder.rustdoc_cmd(compiler.host);
|
2017-03-07 20:31:41 +00:00
|
|
|
|
|
|
|
let out = out.join("book");
|
|
|
|
|
|
|
|
cmd.arg("--html-after-content").arg(&footer)
|
|
|
|
.arg("--html-before-content").arg(&version_info)
|
|
|
|
.arg("--html-in-header").arg(&favicon)
|
2018-03-02 18:52:13 +00:00
|
|
|
.arg("--markdown-no-toc")
|
2017-03-07 20:31:41 +00:00
|
|
|
.arg("--markdown-playground-url")
|
|
|
|
.arg("https://play.rust-lang.org/")
|
|
|
|
.arg("-o").arg(&out)
|
|
|
|
.arg(&path)
|
|
|
|
.arg("--markdown-css")
|
2017-11-15 02:57:03 +00:00
|
|
|
.arg("../rust.css");
|
2017-03-07 20:31:41 +00:00
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.run(&mut cmd);
|
2017-03-07 19:49:50 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct Standalone {
|
2017-07-25 23:56:06 +00:00
|
|
|
compiler: Compiler,
|
2017-07-14 00:48:44 +00:00
|
|
|
target: Interned<String>,
|
2017-07-05 01:41:43 +00:00
|
|
|
}
|
2016-02-16 18:26:43 +00:00
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
impl Step for Standalone {
|
2017-07-05 01:41:43 +00:00
|
|
|
type Output = ();
|
2017-07-05 12:41:27 +00:00
|
|
|
const DEFAULT: bool = true;
|
|
|
|
|
2017-07-19 00:03:38 +00:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
2017-07-20 23:51:07 +00:00
|
|
|
let builder = run.builder;
|
2018-04-14 23:27:57 +00:00
|
|
|
run.path("src/doc").default_condition(builder.config.docs)
|
2017-07-05 12:41:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 23:51:07 +00:00
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(Standalone {
|
2018-04-14 23:27:57 +00:00
|
|
|
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
|
2017-07-20 23:51:07 +00:00
|
|
|
target: run.target,
|
2017-07-05 12:41:27 +00:00
|
|
|
});
|
|
|
|
}
|
2017-07-05 01:41:43 +00:00
|
|
|
|
|
|
|
/// Generates all standalone documentation as compiled by the rustdoc in `stage`
|
|
|
|
/// for the `target` into `out`.
|
|
|
|
///
|
|
|
|
/// This will list all of `src/doc` looking for markdown files and appropriately
|
|
|
|
/// perform transformations like substituting `VERSION`, `SHORT_HASH`, and
|
2017-08-11 18:34:14 +00:00
|
|
|
/// `STAMP` along with providing the various header/footer HTML we've customized.
|
2017-07-05 01:41:43 +00:00
|
|
|
///
|
|
|
|
/// In the end, this is just a glorified wrapper around rustdoc!
|
|
|
|
fn run(self, builder: &Builder) {
|
|
|
|
let target = self.target;
|
2017-07-25 23:56:06 +00:00
|
|
|
let compiler = self.compiler;
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.info(&format!("Documenting standalone ({})", target));
|
|
|
|
let out = builder.doc_out(target);
|
2017-07-05 01:41:43 +00:00
|
|
|
t!(fs::create_dir_all(&out));
|
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
let favicon = builder.src.join("src/doc/favicon.inc");
|
|
|
|
let footer = builder.src.join("src/doc/footer.inc");
|
|
|
|
let full_toc = builder.src.join("src/doc/full-toc.inc");
|
|
|
|
t!(fs::copy(builder.src.join("src/doc/rust.css"), out.join("rust.css")));
|
2017-07-05 01:41:43 +00:00
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
let version_input = builder.src.join("src/doc/version_info.html.template");
|
2017-07-05 01:41:43 +00:00
|
|
|
let version_info = out.join("version_info.html");
|
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
if !builder.config.dry_run && !up_to_date(&version_input, &version_info) {
|
2017-07-05 01:41:43 +00:00
|
|
|
let mut info = String::new();
|
|
|
|
t!(t!(File::open(&version_input)).read_to_string(&mut info));
|
2018-04-14 23:27:57 +00:00
|
|
|
let info = info.replace("VERSION", &builder.rust_release())
|
|
|
|
.replace("SHORT_HASH", builder.rust_info.sha_short().unwrap_or(""))
|
|
|
|
.replace("STAMP", builder.rust_info.sha().unwrap_or(""));
|
2017-07-05 01:41:43 +00:00
|
|
|
t!(t!(File::create(&version_info)).write_all(info.as_bytes()));
|
2016-02-16 18:26:43 +00:00
|
|
|
}
|
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
for file in t!(fs::read_dir(builder.src.join("src/doc"))) {
|
2017-07-05 01:41:43 +00:00
|
|
|
let file = t!(file);
|
|
|
|
let path = file.path();
|
|
|
|
let filename = path.file_name().unwrap().to_str().unwrap();
|
|
|
|
if !filename.ends_with(".md") || filename == "README.md" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
let html = out.join(filename).with_extension("html");
|
2017-08-04 22:13:01 +00:00
|
|
|
let rustdoc = builder.rustdoc(compiler.host);
|
2017-07-05 01:41:43 +00:00
|
|
|
if up_to_date(&path, &html) &&
|
|
|
|
up_to_date(&footer, &html) &&
|
|
|
|
up_to_date(&favicon, &html) &&
|
|
|
|
up_to_date(&full_toc, &html) &&
|
|
|
|
up_to_date(&version_info, &html) &&
|
2018-04-14 23:27:57 +00:00
|
|
|
(builder.config.dry_run || up_to_date(&rustdoc, &html)) {
|
2017-07-05 01:41:43 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-08-04 22:13:01 +00:00
|
|
|
let mut cmd = builder.rustdoc_cmd(compiler.host);
|
2017-07-05 01:41:43 +00:00
|
|
|
cmd.arg("--html-after-content").arg(&footer)
|
|
|
|
.arg("--html-before-content").arg(&version_info)
|
|
|
|
.arg("--html-in-header").arg(&favicon)
|
2018-09-29 14:40:37 +00:00
|
|
|
.arg("--markdown-no-toc")
|
2018-09-25 21:20:33 +00:00
|
|
|
.arg("--index-page").arg(&builder.src.join("src/doc/index.md"))
|
2017-07-05 01:41:43 +00:00
|
|
|
.arg("--markdown-playground-url")
|
|
|
|
.arg("https://play.rust-lang.org/")
|
|
|
|
.arg("-o").arg(&out)
|
|
|
|
.arg(&path);
|
|
|
|
|
|
|
|
if filename == "not_found.md" {
|
2018-09-29 14:40:37 +00:00
|
|
|
cmd.arg("--markdown-css")
|
2017-07-05 01:41:43 +00:00
|
|
|
.arg("https://doc.rust-lang.org/rust.css");
|
|
|
|
} else {
|
|
|
|
cmd.arg("--markdown-css").arg("rust.css");
|
|
|
|
}
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.run(&mut cmd);
|
2016-02-16 18:26:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-08 06:36:21 +00:00
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct Std {
|
2018-01-12 22:40:00 +00:00
|
|
|
pub stage: u32,
|
|
|
|
pub target: Interned<String>,
|
2017-07-05 01:41:43 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
impl Step for Std {
|
2017-07-05 01:41:43 +00:00
|
|
|
type Output = ();
|
2017-07-05 12:41:27 +00:00
|
|
|
const DEFAULT: bool = true;
|
|
|
|
|
2017-07-19 00:03:38 +00:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
2017-07-20 23:24:11 +00:00
|
|
|
let builder = run.builder;
|
2018-04-14 23:27:57 +00:00
|
|
|
run.all_krates("std").default_condition(builder.config.docs)
|
2017-07-05 12:41:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 23:51:07 +00:00
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(Std {
|
|
|
|
stage: run.builder.top_stage,
|
|
|
|
target: run.target
|
2017-07-20 23:24:11 +00:00
|
|
|
});
|
2017-07-05 12:41:27 +00:00
|
|
|
}
|
2017-07-05 01:41:43 +00:00
|
|
|
|
|
|
|
/// Compile all standard library documentation.
|
|
|
|
///
|
|
|
|
/// This will generate all documentation for the standard library and its
|
|
|
|
/// dependencies. This is largely just a wrapper around `cargo doc`.
|
|
|
|
fn run(self, builder: &Builder) {
|
|
|
|
let stage = self.stage;
|
|
|
|
let target = self.target;
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.info(&format!("Documenting stage{} std ({})", stage, target));
|
|
|
|
let out = builder.doc_out(target);
|
2017-07-05 01:41:43 +00:00
|
|
|
t!(fs::create_dir_all(&out));
|
2018-04-14 23:27:57 +00:00
|
|
|
let compiler = builder.compiler(stage, builder.config.build);
|
|
|
|
let compiler = if builder.force_use_stage1(compiler, target) {
|
2017-07-05 12:41:27 +00:00
|
|
|
builder.compiler(1, compiler.host)
|
2017-07-05 01:41:43 +00:00
|
|
|
} else {
|
|
|
|
compiler
|
|
|
|
};
|
2017-07-05 12:41:27 +00:00
|
|
|
|
|
|
|
builder.ensure(compile::Std { compiler, target });
|
2018-05-19 20:04:41 +00:00
|
|
|
let out_dir = builder.stage_out(compiler, Mode::Std)
|
2017-07-05 01:41:43 +00:00
|
|
|
.join(target).join("doc");
|
|
|
|
|
|
|
|
// Here what we're doing is creating a *symlink* (directory junction on
|
|
|
|
// Windows) to the final output location. This is not done as an
|
|
|
|
// optimization but rather for correctness. We've got three trees of
|
|
|
|
// documentation, one for std, one for test, and one for rustc. It's then
|
|
|
|
// our job to merge them all together.
|
|
|
|
//
|
|
|
|
// Unfortunately rustbuild doesn't know nearly as well how to merge doc
|
|
|
|
// trees as rustdoc does itself, so instead of actually having three
|
|
|
|
// separate trees we just have rustdoc output to the same location across
|
|
|
|
// all of them.
|
|
|
|
//
|
|
|
|
// This way rustdoc generates output directly into the output, and rustdoc
|
|
|
|
// will also directly handle merging.
|
2018-04-14 23:27:57 +00:00
|
|
|
let my_out = builder.crate_doc_out(target);
|
|
|
|
t!(symlink_dir_force(&builder.config, &my_out, &out_dir));
|
2018-09-29 14:40:37 +00:00
|
|
|
t!(fs::copy(builder.src.join("src/doc/rust.css"), out.join("rust.css")));
|
2017-07-05 01:41:43 +00:00
|
|
|
|
2018-09-25 21:20:33 +00:00
|
|
|
let run_cargo_rustdoc_for = |package: &str| {
|
|
|
|
let mut cargo = builder.cargo(compiler, Mode::Std, target, "rustdoc");
|
|
|
|
compile::std_cargo(builder, &compiler, target, &mut cargo);
|
2017-07-05 01:41:43 +00:00
|
|
|
|
2018-09-25 21:20:33 +00:00
|
|
|
// Keep a whitelist so we do not build internal stdlib crates, these will be
|
|
|
|
// build by the rustc step later if enabled.
|
|
|
|
cargo.arg("-Z").arg("unstable-options")
|
|
|
|
.arg("-p").arg(package);
|
2018-03-20 02:06:38 +00:00
|
|
|
// Create all crate output directories first to make sure rustdoc uses
|
|
|
|
// relative links.
|
|
|
|
// FIXME: Cargo should probably do this itself.
|
2018-09-25 21:20:33 +00:00
|
|
|
t!(fs::create_dir_all(out_dir.join(package)));
|
|
|
|
cargo.arg("--")
|
2018-09-29 14:40:37 +00:00
|
|
|
.arg("--markdown-css").arg("rust.css")
|
|
|
|
.arg("--markdown-no-toc")
|
|
|
|
.arg("--index-page").arg(&builder.src.join("src/doc/index.md"));
|
2017-01-05 22:26:04 +00:00
|
|
|
|
2018-09-25 21:20:33 +00:00
|
|
|
builder.run(&mut cargo);
|
|
|
|
builder.cp_r(&my_out, &out);
|
|
|
|
};
|
|
|
|
for krate in &["alloc", "core", "std"] {
|
|
|
|
run_cargo_rustdoc_for(krate);
|
2017-01-08 19:37:52 +00:00
|
|
|
}
|
2017-07-05 01:41:43 +00:00
|
|
|
}
|
2016-03-08 06:36:21 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct Test {
|
2017-07-05 01:41:43 +00:00
|
|
|
stage: u32,
|
2017-07-14 00:48:44 +00:00
|
|
|
target: Interned<String>,
|
rustbuild: Fix dist for non-host targets
The `rust-std` package that we produce is expected to have not only the standard
library but also libtest for compiling unit tests. Unfortunately this does not
currently happen due to the way rustbuild is structured.
There are currently two main stages of compilation in rustbuild, one for the
standard library and one for the compiler. This is primarily done to allow us to
fill in the sysroot right after the standard library has finished compiling to
continue compiling the rest of the crates. Consequently the entire compiler does
not have to explicitly depend on the standard library, and this also should
allow us to pull in crates.io dependencies into the build in the future because
they'll just naturally build against the std we just produced.
These phases, however, do not represent a cross-compiled build. Target-only
builds also require libtest, and libtest is currently part of the
all-encompassing "compiler build". There's unfortunately no way to learn about
just libtest and its dependencies (in a great and robust fashion) so to ensure
that we can copy the right artifacts over this commit introduces a new build
step, libtest.
The new libtest build step has documentation, dist, and link steps as std/rustc
already do. The compiler now depends on libtest instead of libstd, and all
compiler crates can now assume that test and its dependencies are implicitly
part of the sysroot (hence explicit dependencies being removed). This makes the
build a tad less parallel as in theory many rustc crates can be compiled in
parallel with libtest, but this likely isn't where we really need parallelism
either (all the time is still spent in the compiler).
All in all this allows the `dist-std` step to depend on both libstd and libtest,
so `rust-std` packages produced by rustbuild should start having both the
standard library and libtest.
Closes #32523
2016-03-28 05:28:10 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
impl Step for Test {
|
2017-07-05 01:41:43 +00:00
|
|
|
type Output = ();
|
2017-07-05 12:41:27 +00:00
|
|
|
const DEFAULT: bool = true;
|
|
|
|
|
2017-07-19 00:03:38 +00:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
2017-07-20 23:24:11 +00:00
|
|
|
let builder = run.builder;
|
2018-04-14 23:27:57 +00:00
|
|
|
run.krate("test").default_condition(builder.config.docs)
|
2017-07-05 12:41:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 23:51:07 +00:00
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(Test {
|
|
|
|
stage: run.builder.top_stage,
|
|
|
|
target: run.target,
|
2017-07-20 23:24:11 +00:00
|
|
|
});
|
2017-07-05 12:41:27 +00:00
|
|
|
}
|
2017-07-05 01:41:43 +00:00
|
|
|
|
|
|
|
/// Compile all libtest documentation.
|
|
|
|
///
|
|
|
|
/// This will generate all documentation for libtest and its dependencies. This
|
|
|
|
/// is largely just a wrapper around `cargo doc`.
|
|
|
|
fn run(self, builder: &Builder) {
|
|
|
|
let stage = self.stage;
|
|
|
|
let target = self.target;
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.info(&format!("Documenting stage{} test ({})", stage, target));
|
|
|
|
let out = builder.doc_out(target);
|
2017-07-05 01:41:43 +00:00
|
|
|
t!(fs::create_dir_all(&out));
|
2018-04-14 23:27:57 +00:00
|
|
|
let compiler = builder.compiler(stage, builder.config.build);
|
|
|
|
let compiler = if builder.force_use_stage1(compiler, target) {
|
2017-07-05 12:41:27 +00:00
|
|
|
builder.compiler(1, compiler.host)
|
2017-07-05 01:41:43 +00:00
|
|
|
} else {
|
|
|
|
compiler
|
|
|
|
};
|
2017-07-05 12:41:27 +00:00
|
|
|
|
|
|
|
// Build libstd docs so that we generate relative links
|
|
|
|
builder.ensure(Std { stage, target });
|
|
|
|
|
|
|
|
builder.ensure(compile::Test { compiler, target });
|
2018-05-19 20:04:41 +00:00
|
|
|
let out_dir = builder.stage_out(compiler, Mode::Test)
|
2017-07-05 01:41:43 +00:00
|
|
|
.join(target).join("doc");
|
|
|
|
|
|
|
|
// See docs in std above for why we symlink
|
2018-04-14 23:27:57 +00:00
|
|
|
let my_out = builder.crate_doc_out(target);
|
2018-03-27 14:06:47 +00:00
|
|
|
t!(symlink_dir_force(&builder.config, &my_out, &out_dir));
|
2017-07-05 01:41:43 +00:00
|
|
|
|
2018-05-19 20:04:41 +00:00
|
|
|
let mut cargo = builder.cargo(compiler, Mode::Test, target, "doc");
|
2018-04-14 23:27:57 +00:00
|
|
|
compile::test_cargo(builder, &compiler, target, &mut cargo);
|
2018-03-28 21:49:56 +00:00
|
|
|
|
|
|
|
cargo.arg("--no-deps").arg("-p").arg("test");
|
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.run(&mut cargo);
|
|
|
|
builder.cp_r(&my_out, &out);
|
2017-07-05 01:41:43 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-04 23:53:53 +00:00
|
|
|
|
2018-03-20 02:06:38 +00:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct WhitelistedRustc {
|
|
|
|
stage: u32,
|
|
|
|
target: Interned<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Step for WhitelistedRustc {
|
|
|
|
type Output = ();
|
|
|
|
const DEFAULT: bool = true;
|
|
|
|
const ONLY_HOSTS: bool = true;
|
|
|
|
|
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
|
|
|
let builder = run.builder;
|
2018-04-14 23:27:57 +00:00
|
|
|
run.krate("rustc-main").default_condition(builder.config.docs)
|
2018-03-20 02:06:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(WhitelistedRustc {
|
|
|
|
stage: run.builder.top_stage,
|
|
|
|
target: run.target,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Generate whitelisted compiler crate documentation.
|
|
|
|
///
|
|
|
|
/// This will generate all documentation for crates that are whitelisted
|
|
|
|
/// to be included in the standard documentation. This documentation is
|
|
|
|
/// included in the standard Rust documentation, so we should always
|
|
|
|
/// document it and symlink to merge with the rest of the std and test
|
|
|
|
/// documentation. We don't build other compiler documentation
|
|
|
|
/// here as we want to be able to keep it separate from the standard
|
|
|
|
/// documentation. This is largely just a wrapper around `cargo doc`.
|
|
|
|
fn run(self, builder: &Builder) {
|
|
|
|
let stage = self.stage;
|
|
|
|
let target = self.target;
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.info(&format!("Documenting stage{} whitelisted compiler ({})", stage, target));
|
|
|
|
let out = builder.doc_out(target);
|
2018-03-20 02:06:38 +00:00
|
|
|
t!(fs::create_dir_all(&out));
|
2018-04-14 23:27:57 +00:00
|
|
|
let compiler = builder.compiler(stage, builder.config.build);
|
|
|
|
let compiler = if builder.force_use_stage1(compiler, target) {
|
2018-03-20 02:06:38 +00:00
|
|
|
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 });
|
2018-05-19 20:04:41 +00:00
|
|
|
let out_dir = builder.stage_out(compiler, Mode::Rustc)
|
2018-03-20 02:06:38 +00:00
|
|
|
.join(target).join("doc");
|
|
|
|
|
|
|
|
// See docs in std above for why we symlink
|
2018-04-14 23:27:57 +00:00
|
|
|
let my_out = builder.crate_doc_out(target);
|
2018-03-27 14:06:47 +00:00
|
|
|
t!(symlink_dir_force(&builder.config, &my_out, &out_dir));
|
2018-03-20 02:06:38 +00:00
|
|
|
|
2018-05-19 20:04:41 +00:00
|
|
|
let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "doc");
|
2018-04-14 23:27:57 +00:00
|
|
|
compile::rustc_cargo(builder, &mut cargo);
|
2018-03-20 02:06:38 +00:00
|
|
|
|
|
|
|
// We don't want to build docs for internal compiler dependencies in this
|
|
|
|
// step (there is another step for that). Therefore, we whitelist the crates
|
|
|
|
// for which docs must be built.
|
|
|
|
cargo.arg("--no-deps");
|
|
|
|
for krate in &["proc_macro"] {
|
|
|
|
cargo.arg("-p").arg(krate);
|
|
|
|
}
|
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.run(&mut cargo);
|
|
|
|
builder.cp_r(&my_out, &out);
|
2018-03-20 02:06:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct Rustc {
|
2017-07-05 01:41:43 +00:00
|
|
|
stage: u32,
|
2017-07-14 00:48:44 +00:00
|
|
|
target: Interned<String>,
|
2017-07-05 01:41:43 +00:00
|
|
|
}
|
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
impl Step for Rustc {
|
2017-07-05 01:41:43 +00:00
|
|
|
type Output = ();
|
2017-07-05 12:41:27 +00:00
|
|
|
const DEFAULT: bool = true;
|
|
|
|
const ONLY_HOSTS: bool = true;
|
|
|
|
|
2017-07-19 00:03:38 +00:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
2017-07-20 23:24:11 +00:00
|
|
|
let builder = run.builder;
|
2018-04-14 23:27:57 +00:00
|
|
|
run.krate("rustc-main").default_condition(builder.config.docs)
|
2017-07-05 12:41:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 23:51:07 +00:00
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(Rustc {
|
|
|
|
stage: run.builder.top_stage,
|
|
|
|
target: run.target,
|
2017-07-20 23:24:11 +00:00
|
|
|
});
|
2017-07-05 12:41:27 +00:00
|
|
|
}
|
2017-07-05 01:41:43 +00:00
|
|
|
|
2018-03-20 02:06:38 +00:00
|
|
|
/// Generate compiler documentation.
|
2017-07-05 01:41:43 +00:00
|
|
|
///
|
2018-03-20 02:06:38 +00:00
|
|
|
/// This will generate all documentation for compiler and dependencies.
|
|
|
|
/// Compiler documentation is distributed separately, so we make sure
|
|
|
|
/// we do not merge it with the other documentation from std, test and
|
|
|
|
/// proc_macros. This is largely just a wrapper around `cargo doc`.
|
2017-07-05 01:41:43 +00:00
|
|
|
fn run(self, builder: &Builder) {
|
|
|
|
let stage = self.stage;
|
|
|
|
let target = self.target;
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.info(&format!("Documenting stage{} compiler ({})", stage, target));
|
2018-05-19 15:21:17 +00:00
|
|
|
|
|
|
|
// This is the intended out directory for compiler documentation.
|
2018-04-14 23:27:57 +00:00
|
|
|
let out = builder.compiler_doc_out(target);
|
2017-07-05 01:41:43 +00:00
|
|
|
t!(fs::create_dir_all(&out));
|
2018-05-19 15:21:17 +00:00
|
|
|
|
|
|
|
// Get the correct compiler for this stage.
|
2018-04-14 23:27:57 +00:00
|
|
|
let compiler = builder.compiler(stage, builder.config.build);
|
|
|
|
let compiler = if builder.force_use_stage1(compiler, target) {
|
2017-07-05 12:41:27 +00:00
|
|
|
builder.compiler(1, compiler.host)
|
2017-07-05 01:41:43 +00:00
|
|
|
} else {
|
|
|
|
compiler
|
|
|
|
};
|
2017-07-05 12:41:27 +00:00
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
if !builder.config.compiler_docs {
|
2018-07-28 12:40:32 +00:00
|
|
|
builder.info("\tskipping - compiler/librustdoc docs disabled");
|
2018-03-20 02:06:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-19 15:21:17 +00:00
|
|
|
// Build libstd docs so that we generate relative links.
|
2017-07-05 12:41:27 +00:00
|
|
|
builder.ensure(Std { stage, target });
|
|
|
|
|
2018-05-19 15:21:17 +00:00
|
|
|
// Build rustc.
|
2017-07-05 12:41:27 +00:00
|
|
|
builder.ensure(compile::Rustc { compiler, target });
|
2018-05-19 15:21:17 +00:00
|
|
|
|
2018-03-22 20:49:05 +00:00
|
|
|
// 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.
|
2018-05-19 20:04:41 +00:00
|
|
|
let out_dir = builder.stage_out(compiler, Mode::Rustc).join(target).join("doc");
|
2018-03-27 14:06:47 +00:00
|
|
|
t!(symlink_dir_force(&builder.config, &out, &out_dir));
|
2017-07-05 01:41:43 +00:00
|
|
|
|
2018-05-19 15:21:17 +00:00
|
|
|
// Build cargo command.
|
2018-05-19 20:04:41 +00:00
|
|
|
let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "doc");
|
2018-04-04 15:09:01 +00:00
|
|
|
cargo.env("RUSTDOCFLAGS", "--document-private-items");
|
2018-04-14 23:27:57 +00:00
|
|
|
compile::rustc_cargo(builder, &mut cargo);
|
2017-07-05 01:41:43 +00:00
|
|
|
|
2018-03-22 14:57:28 +00:00
|
|
|
// Only include compiler crates, no dependencies of those, such as `libc`.
|
|
|
|
cargo.arg("--no-deps");
|
|
|
|
|
|
|
|
// Find dependencies for top level crates.
|
|
|
|
let mut compiler_crates = HashSet::new();
|
2018-08-24 11:09:34 +00:00
|
|
|
for root_crate in &["rustc", "rustc_driver", "rustc_codegen_llvm"] {
|
2018-03-22 14:57:28 +00:00
|
|
|
let interned_root_crate = INTERNER.intern_str(root_crate);
|
2018-04-14 23:27:57 +00:00
|
|
|
find_compiler_crates(builder, &interned_root_crate, &mut compiler_crates);
|
2018-03-22 14:57:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for krate in &compiler_crates {
|
|
|
|
cargo.arg("-p").arg(krate);
|
|
|
|
}
|
2017-03-01 23:34:54 +00:00
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.run(&mut cargo);
|
2017-07-05 01:41:43 +00:00
|
|
|
}
|
2016-03-08 06:36:21 +00:00
|
|
|
}
|
2016-03-08 21:42:32 +00:00
|
|
|
|
2018-03-22 14:57:28 +00:00
|
|
|
fn find_compiler_crates(
|
2018-04-14 23:27:57 +00:00
|
|
|
builder: &Builder,
|
2018-03-22 14:57:28 +00:00
|
|
|
name: &Interned<String>,
|
|
|
|
crates: &mut HashSet<Interned<String>>
|
|
|
|
) {
|
|
|
|
// Add current crate.
|
|
|
|
crates.insert(*name);
|
|
|
|
|
|
|
|
// Look for dependencies.
|
2018-04-14 23:27:57 +00:00
|
|
|
for dep in builder.crates.get(name).unwrap().deps.iter() {
|
|
|
|
if builder.crates.get(dep).unwrap().is_local(builder) {
|
|
|
|
find_compiler_crates(builder, dep, crates);
|
2018-03-22 14:57:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-19 15:21:17 +00:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct Rustdoc {
|
|
|
|
stage: u32,
|
|
|
|
target: Interned<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Step for Rustdoc {
|
|
|
|
type Output = ();
|
|
|
|
const DEFAULT: bool = true;
|
|
|
|
const ONLY_HOSTS: bool = true;
|
|
|
|
|
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
|
|
|
run.krate("rustdoc-tool")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(Rustdoc {
|
|
|
|
stage: run.builder.top_stage,
|
|
|
|
target: run.target,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Generate compiler documentation.
|
|
|
|
///
|
|
|
|
/// This will generate all documentation for compiler and dependencies.
|
|
|
|
/// Compiler documentation is distributed separately, so we make sure
|
|
|
|
/// we do not merge it with the other documentation from std, test and
|
|
|
|
/// proc_macros. This is largely just a wrapper around `cargo doc`.
|
|
|
|
fn run(self, builder: &Builder) {
|
|
|
|
let stage = self.stage;
|
|
|
|
let target = self.target;
|
|
|
|
builder.info(&format!("Documenting stage{} rustdoc ({})", stage, target));
|
|
|
|
|
|
|
|
// This is the intended out directory for compiler documentation.
|
|
|
|
let out = builder.compiler_doc_out(target);
|
|
|
|
t!(fs::create_dir_all(&out));
|
|
|
|
|
|
|
|
// 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 {
|
2018-07-28 12:40:32 +00:00
|
|
|
builder.info("\tskipping - compiler/librustdoc docs disabled");
|
2018-05-19 15:21:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build libstd docs so that we generate relative links.
|
|
|
|
builder.ensure(Std { stage, target });
|
|
|
|
|
|
|
|
// Build rustdoc.
|
|
|
|
builder.ensure(tool::Rustdoc { host: compiler.host });
|
|
|
|
|
|
|
|
// Symlink compiler docs to the output directory of rustdoc documentation.
|
2018-06-29 21:35:10 +00:00
|
|
|
let out_dir = builder.stage_out(compiler, Mode::ToolRustc)
|
|
|
|
.join(target)
|
|
|
|
.join("doc");
|
2018-05-19 15:21:17 +00:00
|
|
|
t!(fs::create_dir_all(&out_dir));
|
|
|
|
t!(symlink_dir_force(&builder.config, &out, &out_dir));
|
|
|
|
|
|
|
|
// Build cargo command.
|
2018-05-27 23:56:33 +00:00
|
|
|
let mut cargo = prepare_tool_cargo(
|
2018-06-29 21:35:10 +00:00
|
|
|
builder,
|
|
|
|
compiler,
|
|
|
|
Mode::ToolRustc,
|
|
|
|
target,
|
|
|
|
"doc",
|
|
|
|
"src/tools/rustdoc",
|
2018-07-26 03:36:58 +00:00
|
|
|
SourceType::InTree,
|
2018-10-08 17:39:09 +00:00
|
|
|
&[]
|
2018-06-29 21:35:10 +00:00
|
|
|
);
|
2018-05-27 23:56:33 +00:00
|
|
|
|
2018-05-19 15:21:17 +00:00
|
|
|
cargo.env("RUSTDOCFLAGS", "--document-private-items");
|
|
|
|
builder.run(&mut cargo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct ErrorIndex {
|
|
|
|
target: Interned<String>,
|
2017-07-05 01:41:43 +00:00
|
|
|
}
|
2016-03-08 21:42:32 +00:00
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
impl Step for ErrorIndex {
|
2017-07-05 01:41:43 +00:00
|
|
|
type Output = ();
|
2017-07-05 12:41:27 +00:00
|
|
|
const DEFAULT: bool = true;
|
|
|
|
const ONLY_HOSTS: bool = true;
|
|
|
|
|
2017-07-19 00:03:38 +00:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
2017-07-20 23:24:11 +00:00
|
|
|
let builder = run.builder;
|
2018-04-14 23:27:57 +00:00
|
|
|
run.path("src/tools/error_index_generator").default_condition(builder.config.docs)
|
2017-07-05 12:41:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 23:51:07 +00:00
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(ErrorIndex {
|
|
|
|
target: run.target,
|
2017-07-05 12:41:27 +00:00
|
|
|
});
|
|
|
|
}
|
2017-07-05 01:41:43 +00:00
|
|
|
|
|
|
|
/// Generates the HTML rendered error-index by running the
|
|
|
|
/// `error_index_generator` tool.
|
|
|
|
fn run(self, builder: &Builder) {
|
|
|
|
let target = self.target;
|
2017-07-05 12:41:27 +00:00
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.info(&format!("Documenting error index ({})", target));
|
|
|
|
let out = builder.doc_out(target);
|
2017-07-05 01:41:43 +00:00
|
|
|
t!(fs::create_dir_all(&out));
|
2017-07-05 12:41:27 +00:00
|
|
|
let mut index = builder.tool_cmd(Tool::ErrorIndex);
|
2017-07-05 01:41:43 +00:00
|
|
|
index.arg("html");
|
|
|
|
index.arg(out.join("error-index.html"));
|
|
|
|
|
|
|
|
// FIXME: shouldn't have to pass this env var
|
2018-04-14 23:27:57 +00:00
|
|
|
index.env("CFG_BUILD", &builder.config.build)
|
|
|
|
.env("RUSTC_ERROR_METADATA_DST", builder.extended_error_dir());
|
2017-07-05 01:41:43 +00:00
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.run(&mut index);
|
2017-07-05 01:41:43 +00:00
|
|
|
}
|
2016-03-08 21:42:32 +00:00
|
|
|
}
|
2017-03-01 23:34:54 +00:00
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
|
|
|
|
pub struct UnstableBookGen {
|
|
|
|
target: Interned<String>,
|
2017-07-05 01:41:43 +00:00
|
|
|
}
|
2017-06-12 19:35:47 +00:00
|
|
|
|
2017-07-14 00:48:44 +00:00
|
|
|
impl Step for UnstableBookGen {
|
2017-07-05 01:41:43 +00:00
|
|
|
type Output = ();
|
2017-07-05 12:41:27 +00:00
|
|
|
const DEFAULT: bool = true;
|
|
|
|
const ONLY_HOSTS: bool = true;
|
|
|
|
|
2017-07-19 00:03:38 +00:00
|
|
|
fn should_run(run: ShouldRun) -> ShouldRun {
|
2017-07-20 23:24:11 +00:00
|
|
|
let builder = run.builder;
|
2018-04-14 23:27:57 +00:00
|
|
|
run.path("src/tools/unstable-book-gen").default_condition(builder.config.docs)
|
2017-07-05 12:41:27 +00:00
|
|
|
}
|
|
|
|
|
2017-07-20 23:51:07 +00:00
|
|
|
fn make_run(run: RunConfig) {
|
|
|
|
run.builder.ensure(UnstableBookGen {
|
|
|
|
target: run.target,
|
2017-07-05 12:41:27 +00:00
|
|
|
});
|
|
|
|
}
|
2017-07-05 01:41:43 +00:00
|
|
|
|
|
|
|
fn run(self, builder: &Builder) {
|
|
|
|
let target = self.target;
|
2017-07-05 12:41:27 +00:00
|
|
|
|
|
|
|
builder.ensure(compile::Std {
|
2018-04-14 23:27:57 +00:00
|
|
|
compiler: builder.compiler(builder.top_stage, builder.config.build),
|
2017-07-05 12:41:27 +00:00
|
|
|
target,
|
|
|
|
});
|
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.info(&format!("Generating unstable book md files ({})", target));
|
|
|
|
let out = builder.md_doc_out(target).join("unstable-book");
|
|
|
|
builder.create_dir(&out);
|
|
|
|
builder.remove_dir(&out);
|
2017-07-05 16:46:41 +00:00
|
|
|
let mut cmd = builder.tool_cmd(Tool::UnstableBookGen);
|
2018-04-14 23:27:57 +00:00
|
|
|
cmd.arg(builder.src.join("src"));
|
2017-07-05 01:41:43 +00:00
|
|
|
cmd.arg(out);
|
|
|
|
|
2018-04-14 23:27:57 +00:00
|
|
|
builder.run(&mut cmd);
|
2017-07-05 01:41:43 +00:00
|
|
|
}
|
2017-06-12 19:35:47 +00:00
|
|
|
}
|
|
|
|
|
2018-03-27 14:06:47 +00:00
|
|
|
fn symlink_dir_force(config: &Config, src: &Path, dst: &Path) -> io::Result<()> {
|
|
|
|
if config.dry_run {
|
|
|
|
return Ok(());
|
|
|
|
}
|
2017-03-01 23:34:54 +00:00
|
|
|
if let Ok(m) = fs::symlink_metadata(dst) {
|
|
|
|
if m.file_type().is_dir() {
|
|
|
|
try!(fs::remove_dir_all(dst));
|
|
|
|
} else {
|
|
|
|
// handle directory junctions on windows by falling back to
|
|
|
|
// `remove_dir`.
|
|
|
|
try!(fs::remove_file(dst).or_else(|_| {
|
|
|
|
fs::remove_dir(dst)
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-27 14:06:47 +00:00
|
|
|
symlink_dir(config, src, dst)
|
2017-03-01 23:34:54 +00:00
|
|
|
}
|