Only the compatibility items from the embedded book PR

PR: https://github.com/rust-lang/rust/pull/56291
This commit is contained in:
James Munns 2019-01-10 20:37:51 +01:00 committed by Steve Klabnik
parent 43b4c4a36b
commit 7389f97cde
3 changed files with 104 additions and 29 deletions

View File

@ -23,7 +23,7 @@ use crate::cache::{INTERNER, Interned};
use crate::config::Config;
macro_rules! book {
($($name:ident, $path:expr, $book_name:expr;)+) => {
($($name:ident, $path:expr, $book_name:expr, $book_ver:expr;)+) => {
$(
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct $name {
@ -49,6 +49,7 @@ macro_rules! book {
builder.ensure(Rustbook {
target: self.target,
name: INTERNER.intern_str($book_name),
version: $book_ver,
})
}
}
@ -56,19 +57,28 @@ macro_rules! book {
}
}
// NOTE: When adding a book here, make sure to ALSO build the book by
// adding a build step in `src/bootstrap/builder.rs`!
book!(
Nomicon, "src/doc/nomicon", "nomicon";
Reference, "src/doc/reference", "reference";
EditionGuide, "src/doc/edition-guide", "edition-guide";
RustdocBook, "src/doc/rustdoc", "rustdoc";
RustcBook, "src/doc/rustc", "rustc";
RustByExample, "src/doc/rust-by-example", "rust-by-example";
EditionGuide, "src/doc/edition-guide", "edition-guide", RustbookVersion::MdBook1;
Nomicon, "src/doc/nomicon", "nomicon", RustbookVersion::MdBook1;
Reference, "src/doc/reference", "reference", RustbookVersion::MdBook1;
RustByExample, "src/doc/rust-by-example", "rust-by-example", RustbookVersion::MdBook1;
RustcBook, "src/doc/rustc", "rustc", RustbookVersion::MdBook1;
RustdocBook, "src/doc/rustdoc", "rustdoc", RustbookVersion::MdBook1;
);
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
enum RustbookVersion {
MdBook1,
MdBook2,
}
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
struct Rustbook {
target: Interned<String>,
name: Interned<String>,
version: RustbookVersion,
}
impl Step for Rustbook {
@ -90,6 +100,7 @@ impl Step for Rustbook {
target: self.target,
name: self.name,
src: INTERNER.intern_path(src),
version: self.version,
});
}
}
@ -122,6 +133,7 @@ impl Step for UnstableBook {
target: self.target,
name: INTERNER.intern_str("unstable-book"),
src: builder.md_doc_out(self.target),
version: RustbookVersion::MdBook1,
})
}
}
@ -175,6 +187,7 @@ struct RustbookSrc {
target: Interned<String>,
name: Interned<String>,
src: Interned<PathBuf>,
version: RustbookVersion,
}
impl Step for RustbookSrc {
@ -205,11 +218,19 @@ impl Step for RustbookSrc {
}
builder.info(&format!("Rustbook ({}) - {}", target, name));
let _ = fs::remove_dir_all(&out);
let vers = match self.version {
RustbookVersion::MdBook1 => "1",
RustbookVersion::MdBook2 => "2",
};
builder.run(rustbook_cmd
.arg("build")
.arg(&src)
.arg("-d")
.arg(out));
.arg(out)
.arg("-m")
.arg(vers));
}
}
@ -255,6 +276,7 @@ impl Step for TheBook {
builder.ensure(Rustbook {
target,
name: INTERNER.intern_string(name.to_string()),
version: RustbookVersion::MdBook1,
});
// building older edition redirects
@ -263,18 +285,21 @@ impl Step for TheBook {
builder.ensure(Rustbook {
target,
name: INTERNER.intern_string(source_name),
version: RustbookVersion::MdBook1,
});
let source_name = format!("{}/second-edition", name);
builder.ensure(Rustbook {
target,
name: INTERNER.intern_string(source_name),
version: RustbookVersion::MdBook1,
});
let source_name = format!("{}/2018-edition", name);
builder.ensure(Rustbook {
target,
name: INTERNER.intern_string(source_name),
version: RustbookVersion::MdBook1,
});
// build the version info page and CSS

View File

@ -1,13 +1,23 @@
cargo-features = ["rename-dependency"]
[package]
authors = ["The Rust Project Developers"]
name = "rustbook"
version = "0.1.0"
license = "MIT/Apache-2.0"
edition = "2018"
[dependencies]
clap = "2.25.0"
[dependencies.mdbook]
[dependencies.mdbook_2]
package = "mdbook"
version = "0.2.2"
default-features = false
features = ["search"]
[dependencies.mdbook_1]
package = "mdbook"
version = "0.1.7"
default-features = false
features = ["search"]

View File

@ -1,21 +1,24 @@
//
extern crate mdbook;
#[macro_use]
extern crate clap;
use clap::{crate_version};
use std::env;
use std::path::{Path, PathBuf};
use clap::{App, ArgMatches, SubCommand, AppSettings};
use mdbook::MDBook;
use mdbook::errors::Result;
use mdbook_1::{MDBook as MDBook1};
use mdbook_1::errors::{Result as Result1};
use mdbook_2::{MDBook as MDBook2};
use mdbook_2::errors::{Result as Result2};
fn main() {
let d_message = "-d, --dest-dir=[dest-dir]
'The output directory for your book{n}(Defaults to ./book when omitted)'";
let dir_message = "[dir]
'A directory for your book{n}(Defaults to Current Directory when omitted)'";
let vers_message = "-m, --mdbook-vers=[md-version]
'The version of mdbook to use for your book{n}(Defaults to 1 when omitted)'";
let matches = App::new("rustbook")
.about("Build a book with mdBook")
@ -25,29 +28,66 @@ fn main() {
.subcommand(SubCommand::with_name("build")
.about("Build the book from the markdown files")
.arg_from_usage(d_message)
.arg_from_usage(dir_message))
.arg_from_usage(dir_message)
.arg_from_usage(vers_message))
.get_matches();
// Check which subcomamnd the user ran...
let res = match matches.subcommand() {
("build", Some(sub_matches)) => build(sub_matches),
match matches.subcommand() {
("build", Some(sub_matches)) => {
match sub_matches.value_of("mdbook-vers") {
None | Some("1") => {
if let Err(e) = build_1(sub_matches) {
eprintln!("Error: {}", e);
for cause in e.iter().skip(1) {
eprintln!("\tCaused By: {}", cause);
}
::std::process::exit(101);
}
}
Some("2") => {
if let Err(e) = build_2(sub_matches) {
eprintln!("Error: {}", e);
for cause in e.iter().skip(1) {
eprintln!("\tCaused By: {}", cause);
}
::std::process::exit(101);
}
}
_ => {
panic!("Invalid mdBook version! Select '1' or '2'");
}
};
},
(_, _) => unreachable!(),
};
if let Err(e) = res {
eprintln!("Error: {}", e);
for cause in e.iter().skip(1) {
eprintln!("\tCaused By: {}", cause);
}
::std::process::exit(101);
}
}
// Build command implementation
pub fn build(args: &ArgMatches) -> Result<()> {
pub fn build_1(args: &ArgMatches) -> Result1<()> {
let book_dir = get_book_dir(args);
let mut book = MDBook::load(&book_dir)?;
let mut book = MDBook1::load(&book_dir)?;
// Set this to allow us to catch bugs in advance.
book.config.build.create_missing = false;
if let Some(dest_dir) = args.value_of("dest-dir") {
book.config.build.build_dir = PathBuf::from(dest_dir);
}
book.build()?;
Ok(())
}
// Build command implementation
pub fn build_2(args: &ArgMatches) -> Result2<()> {
let book_dir = get_book_dir(args);
let mut book = MDBook2::load(&book_dir)?;
// Set this to allow us to catch bugs in advance.
book.config.build.create_missing = false;