2016-02-16 12:26:43 -06: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.
|
|
|
|
|
|
|
|
use std::fs::{self, File};
|
|
|
|
use std::io::prelude::*;
|
2016-03-08 01:11:05 -06:00
|
|
|
use std::path::Path;
|
|
|
|
use std::process::Command;
|
2016-02-16 12:26:43 -06:00
|
|
|
|
2016-03-08 00:58:59 -06:00
|
|
|
use build::{Build, Compiler, Mode};
|
2016-03-08 00:36:21 -06:00
|
|
|
use build::util::{up_to_date, cp_r};
|
2016-02-16 12:26:43 -06:00
|
|
|
|
|
|
|
pub fn rustbook(build: &Build, stage: u32, host: &str, name: &str, out: &Path) {
|
|
|
|
t!(fs::create_dir_all(out));
|
|
|
|
|
|
|
|
let out = out.join(name);
|
|
|
|
let compiler = Compiler::new(stage, host);
|
|
|
|
let src = build.src.join("src/doc").join(name);
|
|
|
|
let index = out.join("index.html");
|
|
|
|
let rustbook = build.tool(&compiler, "rustbook");
|
|
|
|
if up_to_date(&src, &index) && up_to_date(&rustbook, &index) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
println!("Rustbook stage{} ({}) - {}", stage, host, name);
|
|
|
|
let _ = fs::remove_dir_all(&out);
|
|
|
|
build.run(build.tool_cmd(&compiler, "rustbook")
|
|
|
|
.arg("build")
|
|
|
|
.arg(&src)
|
|
|
|
.arg(out));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn standalone(build: &Build, stage: u32, host: &str, out: &Path) {
|
|
|
|
println!("Documenting stage{} standalone ({})", stage, host);
|
|
|
|
t!(fs::create_dir_all(out));
|
|
|
|
|
|
|
|
let compiler = Compiler::new(stage, host);
|
|
|
|
|
|
|
|
let favicon = build.src.join("src/doc/favicon.inc");
|
|
|
|
let footer = build.src.join("src/doc/footer.inc");
|
|
|
|
let full_toc = build.src.join("src/doc/full-toc.inc");
|
|
|
|
t!(fs::copy(build.src.join("src/doc/rust.css"), out.join("rust.css")));
|
|
|
|
|
|
|
|
let version_input = build.src.join("src/doc/version_info.html.template");
|
|
|
|
let version_info = out.join("version_info.html");
|
|
|
|
|
|
|
|
if !up_to_date(&version_input, &version_info) {
|
|
|
|
let mut info = String::new();
|
|
|
|
t!(t!(File::open(&version_input)).read_to_string(&mut info));
|
|
|
|
let blank = String::new();
|
|
|
|
let short = build.short_ver_hash.as_ref().unwrap_or(&blank);
|
|
|
|
let hash = build.ver_hash.as_ref().unwrap_or(&blank);
|
|
|
|
let info = info.replace("VERSION", &build.release)
|
|
|
|
.replace("SHORT_HASH", short)
|
|
|
|
.replace("STAMP", hash);
|
|
|
|
t!(t!(File::create(&version_info)).write_all(info.as_bytes()));
|
|
|
|
}
|
|
|
|
|
|
|
|
for file in t!(fs::read_dir(build.src.join("src/doc"))) {
|
|
|
|
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");
|
2016-03-08 01:11:05 -06:00
|
|
|
let rustdoc = build.rustdoc(&compiler);
|
2016-02-16 12:26:43 -06: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) &&
|
|
|
|
up_to_date(&rustdoc, &html) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2016-03-08 01:11:05 -06:00
|
|
|
let mut cmd = Command::new(&rustdoc);
|
2016-03-11 19:30:16 -06:00
|
|
|
build.add_rustc_lib_path(&compiler, &mut cmd);
|
2016-02-16 12:26:43 -06:00
|
|
|
cmd.arg("--html-after-content").arg(&footer)
|
|
|
|
.arg("--html-before-content").arg(&version_info)
|
|
|
|
.arg("--html-in-header").arg(&favicon)
|
|
|
|
.arg("--markdown-playground-url")
|
|
|
|
.arg("https://play.rust-lang.org/")
|
|
|
|
.arg("-o").arg(out)
|
|
|
|
.arg(&path);
|
|
|
|
|
|
|
|
if filename == "reference.md" {
|
|
|
|
cmd.arg("--html-in-header").arg(&full_toc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if filename == "not_found.md" {
|
|
|
|
cmd.arg("--markdown-no-toc")
|
|
|
|
.arg("--markdown-css")
|
|
|
|
.arg("https://doc.rust-lang.org/rust.css");
|
|
|
|
} else {
|
|
|
|
cmd.arg("--markdown-css").arg("rust.css");
|
|
|
|
}
|
|
|
|
build.run(&mut cmd);
|
|
|
|
}
|
|
|
|
}
|
2016-03-08 00:36:21 -06:00
|
|
|
|
|
|
|
pub fn std(build: &Build, stage: u32, host: &str, out: &Path) {
|
|
|
|
println!("Documenting stage{} std ({})", stage, host);
|
|
|
|
let compiler = Compiler::new(stage, host);
|
2016-03-11 19:30:16 -06:00
|
|
|
let out_dir = build.stage_out(&compiler, Mode::Libstd)
|
2016-03-08 00:36:21 -06:00
|
|
|
.join(host).join("doc");
|
2016-03-08 01:11:05 -06:00
|
|
|
let rustdoc = build.rustdoc(&compiler);
|
|
|
|
|
|
|
|
build.clear_if_dirty(&out_dir, &rustdoc);
|
2016-03-08 00:36:21 -06:00
|
|
|
|
2016-03-11 19:30:16 -06:00
|
|
|
let mut cargo = build.cargo(&compiler, Mode::Libstd, host, "doc");
|
2016-03-08 00:36:21 -06:00
|
|
|
cargo.arg("--manifest-path")
|
|
|
|
.arg(build.src.join("src/rustc/std_shim/Cargo.toml"))
|
|
|
|
.arg("--features").arg(build.std_features());
|
|
|
|
build.run(&mut cargo);
|
|
|
|
cp_r(&out_dir, out)
|
|
|
|
}
|
|
|
|
|
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 00:28:10 -05:00
|
|
|
pub fn test(build: &Build, stage: u32, host: &str, out: &Path) {
|
|
|
|
println!("Documenting stage{} test ({})", stage, host);
|
|
|
|
let compiler = Compiler::new(stage, host);
|
|
|
|
let out_dir = build.stage_out(&compiler, Mode::Libtest)
|
|
|
|
.join(host).join("doc");
|
|
|
|
let rustdoc = build.rustdoc(&compiler);
|
|
|
|
|
|
|
|
build.clear_if_dirty(&out_dir, &rustdoc);
|
|
|
|
|
|
|
|
let mut cargo = build.cargo(&compiler, Mode::Libtest, host, "doc");
|
|
|
|
cargo.arg("--manifest-path")
|
|
|
|
.arg(build.src.join("src/rustc/test_shim/Cargo.toml"));
|
|
|
|
build.run(&mut cargo);
|
|
|
|
cp_r(&out_dir, out)
|
|
|
|
}
|
|
|
|
|
2016-03-08 00:36:21 -06:00
|
|
|
pub fn rustc(build: &Build, stage: u32, host: &str, out: &Path) {
|
|
|
|
println!("Documenting stage{} compiler ({})", stage, host);
|
|
|
|
let compiler = Compiler::new(stage, host);
|
2016-03-11 19:30:16 -06:00
|
|
|
let out_dir = build.stage_out(&compiler, Mode::Librustc)
|
2016-03-08 00:36:21 -06:00
|
|
|
.join(host).join("doc");
|
2016-03-08 01:11:05 -06:00
|
|
|
let rustdoc = build.rustdoc(&compiler);
|
2016-03-08 00:36:21 -06:00
|
|
|
if !up_to_date(&rustdoc, &out_dir.join("rustc/index.html")) {
|
|
|
|
t!(fs::remove_dir_all(&out_dir));
|
|
|
|
}
|
2016-03-11 19:30:16 -06:00
|
|
|
let mut cargo = build.cargo(&compiler, Mode::Librustc, host, "doc");
|
2016-03-08 00:36:21 -06:00
|
|
|
cargo.arg("--manifest-path")
|
|
|
|
.arg(build.src.join("src/rustc/Cargo.toml"))
|
2016-03-08 01:21:05 -06:00
|
|
|
.arg("--features").arg(build.rustc_features());
|
2016-03-08 00:36:21 -06:00
|
|
|
build.run(&mut cargo);
|
|
|
|
cp_r(&out_dir, out)
|
|
|
|
}
|
2016-03-08 15:42:32 -06:00
|
|
|
|
|
|
|
pub fn error_index(build: &Build, stage: u32, host: &str, out: &Path) {
|
|
|
|
println!("Documenting stage{} error index ({})", stage, host);
|
|
|
|
let compiler = Compiler::new(stage, host);
|
2016-03-11 18:21:05 -06:00
|
|
|
let mut index = build.tool_cmd(&compiler, "error_index_generator");
|
2016-03-08 15:42:32 -06:00
|
|
|
index.arg("html");
|
|
|
|
index.arg(out.join("error-index.html"));
|
|
|
|
|
|
|
|
// FIXME: shouldn't have to pass this env var
|
|
|
|
index.env("CFG_BUILD", &build.config.build);
|
|
|
|
|
|
|
|
build.run(&mut index);
|
|
|
|
}
|