Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract book into a submodule #40332

Merged
merged 12 commits into from
Mar 21, 2017
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(""));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all seems pretty familiar, perhaps copied from elsewhere in this file? Could that be deduplicated?

Copy link
Member Author

@steveklabnik steveklabnik Mar 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah; I wasn't sure about it. There's just enough that's different.... I bet I can make it work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's at least refactor out what we can, especially these bits about version/short_hash/stamp/etc

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