Skip to content

Commit 623886f

Browse files
committed
Start shipping the Cargo book
Fixes #44910 Fixes #39588 See both of those bugs for more details.
1 parent 24840da commit 623886f

File tree

1 file changed

+43
-45
lines changed

1 file changed

+43
-45
lines changed

src/bootstrap/doc.rs

+43-45
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,49 @@ impl Step for UnstableBook {
132132
}
133133
}
134134

135+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
136+
pub struct CargoBook {
137+
target: Interned<String>,
138+
name: Interned<String>,
139+
src: Interned<PathBuf>,
140+
}
141+
142+
impl Step for CargoBook {
143+
type Output = ();
144+
const DEFAULT: bool = true;
145+
146+
fn should_run(run: ShouldRun) -> ShouldRun {
147+
let builder = run.builder;
148+
run.path("src/tools/cargo/src/doc/book").default_condition(builder.build.config.docs)
149+
}
150+
151+
fn make_run(run: RunConfig) {
152+
run.builder.ensure(CargoBook {
153+
target: run.target,
154+
name: INTERNER.intern_str("cargo"),
155+
src: INTERNER.intern_path(PathBuf::from("src/tools/cargo/src/doc/book")),
156+
});
157+
}
158+
159+
fn run(self, builder: &Builder) {
160+
let build = builder.build;
161+
let target = self.target;
162+
let name = self.name;
163+
let src = self.src;
164+
let out = build.doc_out(target);
165+
t!(fs::create_dir_all(&out));
166+
167+
let out = out.join(name);
168+
println!("Cargo Book ({}) - {}", target, name);
169+
let _ = fs::remove_dir_all(&out);
170+
build.run(builder.tool_cmd(Tool::Rustbook)
171+
.arg("build")
172+
.arg(&src)
173+
.arg("-d")
174+
.arg(out));
175+
}
176+
}
177+
135178
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
136179
struct RustbookSrc {
137180
target: Interned<String>,
@@ -240,51 +283,6 @@ impl Step for TheBook {
240283
}
241284
}
242285

243-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
244-
pub struct CargoBook {
245-
target: Interned<String>,
246-
}
247-
248-
impl Step for CargoBook {
249-
type Output = ();
250-
const DEFAULT: bool = true;
251-
252-
fn should_run(run: ShouldRun) -> ShouldRun {
253-
let builder = run.builder;
254-
run.path("src/doc/cargo").default_condition(builder.build.config.docs)
255-
}
256-
257-
fn make_run(run: RunConfig) {
258-
run.builder.ensure(CargoBook {
259-
target: run.target,
260-
});
261-
}
262-
263-
/// Create a placeholder for the cargo documentation so that doc.rust-lang.org/cargo will
264-
/// redirect to doc.crates.io. We want to publish doc.rust-lang.org/cargo in the paper
265-
/// version of the book, but we don't want to rush the process of switching cargo's docs
266-
/// over to mdbook and deploying them. When the cargo book is ready, this implementation
267-
/// should build the mdbook instead of this redirect page.
268-
fn run(self, builder: &Builder) {
269-
let build = builder.build;
270-
let out = build.doc_out(self.target);
271-
272-
let cargo_dir = out.join("cargo");
273-
t!(fs::create_dir_all(&cargo_dir));
274-
275-
let index = cargo_dir.join("index.html");
276-
let redirect_html = r#"
277-
<html>
278-
<head>
279-
<meta http-equiv="refresh" content="0; URL='http://doc.crates.io'" />
280-
</head>
281-
</html>"#;
282-
283-
println!("Creating cargo book redirect page");
284-
t!(t!(File::create(&index)).write_all(redirect_html.as_bytes()));
285-
}
286-
}
287-
288286
fn invoke_rustdoc(builder: &Builder, compiler: Compiler, target: Interned<String>, markdown: &str) {
289287
let build = builder.build;
290288
let out = build.doc_out(target);

0 commit comments

Comments
 (0)