Skip to content

Commit

Permalink
Rollup merge of rust-lang#40332 - steveklabnik:extract-book, r=alexcr…
Browse files Browse the repository at this point in the history
…ichton

Extract book into a submodule

Part of rust-lang#39588

We probably don't want to land this till after the beta branches on friday, but would still ❤️ a review from @alexcrichton , since I am a rustbuild noob.

This pr:

1. removes the book
2. adds it back in as a submodule
3. the submodule includes both the old book and the new book
4. it also includes an index page explaining the difference in editions
5. it also includes redirect pages for the old book URLs.
6. so we build all that stuff too.

r? @alexcrichton
  • Loading branch information
frewsxcv authored Mar 21, 2017
2 parents 42cfdc1 + 96d3594 commit 14b5d56
Show file tree
Hide file tree
Showing 76 changed files with 118 additions and 17,522 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@
[submodule "reference"]
path = src/doc/reference
url = https://github.com/rust-lang-nursery/reference.git
[submodule "book"]
path = src/doc/book
url = https://github.com/rust-lang/book
10 changes: 10 additions & 0 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ pub fn docs(build: &Build, compiler: &Compiler) {
continue
}

// The nostarch directory in the book is for no starch, and so isn't guaranteed to build.
// we don't care if it doesn't build, so skip it.
use std::ffi::OsStr;
let path: &OsStr = p.as_ref();
if let Some(path) = path.to_str() {
if path.contains("nostarch") {
continue;
}
}

println!("doc tests for: {}", p.display());
markdown_test(build, compiler, &p);
}
Expand Down
76 changes: 76 additions & 0 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,82 @@ pub fn rustbook(build: &Build, target: &str, name: &str) {
.arg(out));
}

/// Build the book and associated stuff.
///
/// We need to build:
///
/// * Book (first edition)
/// * Book (second edition)
/// * Index page
/// * Redirect pages
pub fn book(build: &Build, target: &str, name: &str) {
// build book first edition
rustbook(build, target, &format!("{}/first-edition", name));

// build book second edition
rustbook(build, target, &format!("{}/second-edition", name));

// build the index page
let index = format!("{}/index.md", name);
println!("Documenting book index ({})", target);
invoke_rustdoc(build, target, &index);

// build the redirect pages
println!("Documenting book redirect pages ({})", target);
for file in t!(fs::read_dir(build.src.join("src/doc/book/redirects"))) {
let file = t!(file);
let path = file.path();
let path = path.to_str().unwrap();

invoke_rustdoc(build, target, path);
}
}

fn invoke_rustdoc(build: &Build, target: &str, markdown: &str) {
let out = build.doc_out(target);

let compiler = Compiler::new(0, &build.config.build);

let path = build.src.join("src/doc").join(markdown);

let rustdoc = build.rustdoc(&compiler);

let favicon = build.src.join("src/doc/favicon.inc");
let footer = build.src.join("src/doc/footer.inc");

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 info = info.replace("VERSION", &build.rust_release())
.replace("SHORT_HASH", build.rust_info.sha_short().unwrap_or(""))
.replace("STAMP", build.rust_info.sha().unwrap_or(""));
t!(t!(File::create(&version_info)).write_all(info.as_bytes()));
}

let mut cmd = Command::new(&rustdoc);

build.add_rustc_lib_path(&compiler, &mut cmd);

let out = out.join("book");

t!(fs::copy(build.src.join("src/doc/rust.css"), out.join("rust.css")));

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)
.arg("--markdown-css")
.arg("rust.css");

build.run(&mut cmd);
}

/// Generates all standalone documentation as compiled by the rustdoc in `stage`
/// for the `target` into `out`.
///
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
.stage(0)
})
.default(build.config.docs)
.run(move |s| doc::rustbook(build, s.target, "book"));
.run(move |s| doc::book(build, s.target, "book"));
rules.doc("doc-nomicon", "src/doc/nomicon")
.dep(move |s| {
s.name("tool-rustbook")
Expand Down
1 change: 1 addition & 0 deletions src/doc/book
Submodule book added at e6d6ca
39 changes: 0 additions & 39 deletions src/doc/book/src/README.md

This file was deleted.

60 changes: 0 additions & 60 deletions src/doc/book/src/SUMMARY.md

This file was deleted.

Loading

0 comments on commit 14b5d56

Please sign in to comment.