Skip to content

Commit 5be97be

Browse files
committed
Implement a temp redirect for cargo docs
As discussed in rust-lang/cargo#4040 (comment) This is a redirect meant to be replaced once cargo docs have been converted to mdbook. We just want *a* URL to ride the trains for now so that we can print doc.rust-lang.org/cargo in the paper book and guarantee that it will go *somewhere* useful by the time the book is printed. Implemented as a meta redirect in HTML because we don't currently have any google juice at doc.rust-lang.org/cargo to lose.
1 parent 3f94b71 commit 5be97be

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl<'a> Builder<'a> {
257257
Kind::Bench => describe!(check::Crate, check::CrateLibrustc),
258258
Kind::Doc => describe!(doc::UnstableBook, doc::UnstableBookGen, doc::TheBook,
259259
doc::Standalone, doc::Std, doc::Test, doc::Rustc, doc::ErrorIndex, doc::Nomicon,
260-
doc::Reference, doc::Rustdoc),
260+
doc::Reference, doc::Rustdoc, doc::CargoBook),
261261
Kind::Dist => describe!(dist::Docs, dist::Mingw, dist::Rustc, dist::DebuggerScripts,
262262
dist::Std, dist::Analysis, dist::Src, dist::PlainSourceTarball, dist::Cargo,
263263
dist::Rls, dist::Extended, dist::HashSign),

src/bootstrap/doc.rs

+45
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,51 @@ impl Step for TheBook {
240240
}
241241
}
242242

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+
243288
fn invoke_rustdoc(builder: &Builder, compiler: Compiler, target: Interned<String>, markdown: &str) {
244289
let build = builder.build;
245290
let out = build.doc_out(target);

0 commit comments

Comments
 (0)