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

Start shipping the Cargo book #45692

Merged
merged 2 commits into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 46 additions & 45 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,52 @@ impl Step for UnstableBook {
}
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct CargoBook {
target: Interned<String>,
name: Interned<String>,
}

impl Step for CargoBook {
type Output = ();
const DEFAULT: bool = true;

fn should_run(run: ShouldRun) -> ShouldRun {
let builder = run.builder;
run.path("src/tools/cargo/src/doc/book").default_condition(builder.build.config.docs)
}

fn make_run(run: RunConfig) {
run.builder.ensure(CargoBook {
target: run.target,
name: INTERNER.intern_str("cargo"),
});
}

fn run(self, builder: &Builder) {
let build = builder.build;

let target = self.target;
let name = self.name;
let src = PathBuf::from("src/tools/cargo/src/doc/book");

let out = build.doc_out(target);
t!(fs::create_dir_all(&out));

let out = out.join(name);

println!("Cargo Book ({}) - {}", target, name);

let _ = fs::remove_dir_all(&out);

build.run(builder.tool_cmd(Tool::Rustbook)
.arg("build")
.arg(&src)
.arg("-d")
.arg(out));
}
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
struct RustbookSrc {
target: Interned<String>,
Expand Down Expand Up @@ -240,51 +286,6 @@ impl Step for TheBook {
}
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct CargoBook {
target: Interned<String>,
}

impl Step for CargoBook {
type Output = ();
const DEFAULT: bool = true;

fn should_run(run: ShouldRun) -> ShouldRun {
let builder = run.builder;
run.path("src/doc/cargo").default_condition(builder.build.config.docs)
}

fn make_run(run: RunConfig) {
run.builder.ensure(CargoBook {
target: run.target,
});
}

/// Create a placeholder for the cargo documentation so that doc.rust-lang.org/cargo will
/// redirect to doc.crates.io. We want to publish doc.rust-lang.org/cargo in the paper
/// version of the book, but we don't want to rush the process of switching cargo's docs
/// over to mdbook and deploying them. When the cargo book is ready, this implementation
/// should build the mdbook instead of this redirect page.
fn run(self, builder: &Builder) {
let build = builder.build;
let out = build.doc_out(self.target);

let cargo_dir = out.join("cargo");
t!(fs::create_dir_all(&cargo_dir));

let index = cargo_dir.join("index.html");
let redirect_html = r#"
<html>
<head>
<meta http-equiv="refresh" content="0; URL='http://doc.crates.io'" />
</head>
</html>"#;

println!("Creating cargo book redirect page");
t!(t!(File::create(&index)).write_all(redirect_html.as_bytes()));
}
}

fn invoke_rustdoc(builder: &Builder, compiler: Compiler, target: Interned<String>, markdown: &str) {
let build = builder.build;
let out = build.doc_out(target);
Expand Down
2 changes: 2 additions & 0 deletions src/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Rust provides a number of book-length sets of documentation, collectively
nicknamed 'The Rust Bookshelf.'

* [The Rust Programming Language][book] teaches you how to program in Rust.
* [The Cargo Book][cargo-book] is a guide to Cargo, Rust's build tool and dependency manager.
Copy link
Contributor

Choose a reason for hiding this comment

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

We're calling it "The Cargo Manual" in the cargo repo. Should we update that to say "The Cargo Book"?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm okay with either, but the rest are almost all called "Book". I'll defer to @rust-lang/cargo here

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with "The Cargo Book", it jives better with me with "bookshelf"

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool! Let's go with what you have here and I'll submit a PR for cargo to update the title there.

Copy link
Contributor

Choose a reason for hiding this comment

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

PR to update cargo: rust-lang/cargo#4695

* [The Unstable Book][unstable-book] has documentation for unstable features.
* [The Rustonomicon][nomicon] is your guidebook to the dark arts of unsafe Rust.
* [The Reference][ref] is not a formal spec, but is more detailed and comprehensive than the book.
Expand All @@ -53,4 +54,5 @@ before this policy was put into place. That work is being tracked
[nomicon]: nomicon/index.html
[unstable-book]: unstable-book/index.html
[rustdoc-book]: rustdoc/index.html
[cargo-book]: cargo/index.html