Skip to content

Commit f722ee0

Browse files
authored
Rollup merge of rust-lang#40332 - steveklabnik:extract-book, r=alexcrichton
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
2 parents 0aeb9c1 + a26162e commit f722ee0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+118
-17539
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@
2727
[submodule "reference"]
2828
path = src/doc/reference
2929
url = https://github.com/rust-lang-nursery/reference.git
30+
[submodule "book"]
31+
path = src/doc/book
32+
url = https://github.com/rust-lang/book

src/bootstrap/check.rs

+10
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,16 @@ pub fn docs(build: &Build, compiler: &Compiler) {
285285
continue
286286
}
287287

288+
// The nostarch directory in the book is for no starch, and so isn't guaranteed to build.
289+
// we don't care if it doesn't build, so skip it.
290+
use std::ffi::OsStr;
291+
let path: &OsStr = p.as_ref();
292+
if let Some(path) = path.to_str() {
293+
if path.contains("nostarch") {
294+
continue;
295+
}
296+
}
297+
288298
println!("doc tests for: {}", p.display());
289299
markdown_test(build, compiler, &p);
290300
}

src/bootstrap/doc.rs

+76
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,82 @@ pub fn rustbook(build: &Build, target: &str, name: &str) {
5353
.arg(out));
5454
}
5555

56+
/// Build the book and associated stuff.
57+
///
58+
/// We need to build:
59+
///
60+
/// * Book (first edition)
61+
/// * Book (second edition)
62+
/// * Index page
63+
/// * Redirect pages
64+
pub fn book(build: &Build, target: &str, name: &str) {
65+
// build book first edition
66+
rustbook(build, target, &format!("{}/first-edition", name));
67+
68+
// build book second edition
69+
rustbook(build, target, &format!("{}/second-edition", name));
70+
71+
// build the index page
72+
let index = format!("{}/index.md", name);
73+
println!("Documenting book index ({})", target);
74+
invoke_rustdoc(build, target, &index);
75+
76+
// build the redirect pages
77+
println!("Documenting book redirect pages ({})", target);
78+
for file in t!(fs::read_dir(build.src.join("src/doc/book/redirects"))) {
79+
let file = t!(file);
80+
let path = file.path();
81+
let path = path.to_str().unwrap();
82+
83+
invoke_rustdoc(build, target, path);
84+
}
85+
}
86+
87+
fn invoke_rustdoc(build: &Build, target: &str, markdown: &str) {
88+
let out = build.doc_out(target);
89+
90+
let compiler = Compiler::new(0, &build.config.build);
91+
92+
let path = build.src.join("src/doc").join(markdown);
93+
94+
let rustdoc = build.rustdoc(&compiler);
95+
96+
let favicon = build.src.join("src/doc/favicon.inc");
97+
let footer = build.src.join("src/doc/footer.inc");
98+
99+
let version_input = build.src.join("src/doc/version_info.html.template");
100+
let version_info = out.join("version_info.html");
101+
102+
if !up_to_date(&version_input, &version_info) {
103+
let mut info = String::new();
104+
t!(t!(File::open(&version_input)).read_to_string(&mut info));
105+
let info = info.replace("VERSION", &build.rust_release())
106+
.replace("SHORT_HASH", build.rust_info.sha_short().unwrap_or(""))
107+
.replace("STAMP", build.rust_info.sha().unwrap_or(""));
108+
t!(t!(File::create(&version_info)).write_all(info.as_bytes()));
109+
}
110+
111+
let mut cmd = Command::new(&rustdoc);
112+
113+
build.add_rustc_lib_path(&compiler, &mut cmd);
114+
115+
let out = out.join("book");
116+
117+
t!(fs::copy(build.src.join("src/doc/rust.css"), out.join("rust.css")));
118+
119+
cmd.arg("--html-after-content").arg(&footer)
120+
.arg("--html-before-content").arg(&version_info)
121+
.arg("--html-in-header").arg(&favicon)
122+
.arg("--markdown-playground-url")
123+
.arg("https://play.rust-lang.org/")
124+
.arg("-o").arg(&out)
125+
.arg(&path)
126+
.arg("--markdown-css")
127+
.arg("rust.css");
128+
129+
build.run(&mut cmd);
130+
}
131+
56132
/// Generates all standalone documentation as compiled by the rustdoc in `stage`
57133
/// for the `target` into `out`.
58134
///

src/bootstrap/step.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
581581
.stage(0)
582582
})
583583
.default(build.config.docs)
584-
.run(move |s| doc::rustbook(build, s.target, "book"));
584+
.run(move |s| doc::book(build, s.target, "book"));
585585
rules.doc("doc-nomicon", "src/doc/nomicon")
586586
.dep(move |s| {
587587
s.name("tool-rustbook")

src/doc/book

Submodule book added at e6d6caa

src/doc/book/src/README.md

-39
This file was deleted.

src/doc/book/src/SUMMARY.md

-60
This file was deleted.

0 commit comments

Comments
 (0)