1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Documentation generation for rustbuilder.
13 //! This module implements generation for all bits and pieces of documentation
14 //! for the Rust project. This notably includes suites like the rust book, the
15 //! nomicon, rust by example, standalone documentation, etc.
17 //! Everything here is basically just a shim around calling either `rustbook` or
20 use std::collections::HashSet;
21 use std::fs::{self, File};
22 use std::io::prelude::*;
24 use std::path::{PathBuf, Path};
27 use build_helper::up_to_date;
29 use util::symlink_dir;
30 use builder::{Builder, Compiler, RunConfig, ShouldRun, Step};
31 use tool::{self, prepare_tool_cargo, Tool, SourceType};
33 use cache::{INTERNER, Interned};
37 ($($name:ident, $path:expr, $book_name:expr;)+) => {
39 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
41 target: Interned<String>,
46 const DEFAULT: bool = true;
48 fn should_run(run: ShouldRun) -> ShouldRun {
49 let builder = run.builder;
50 run.path($path).default_condition(builder.config.docs)
53 fn make_run(run: RunConfig) {
54 run.builder.ensure($name {
59 fn run(self, builder: &Builder) {
60 builder.ensure(Rustbook {
62 name: INTERNER.intern_str($book_name),
71 Nomicon, "src/doc/nomicon", "nomicon";
72 Reference, "src/doc/reference", "reference";
73 EditionGuide, "src/doc/edition-guide", "edition-guide";
74 RustdocBook, "src/doc/rustdoc", "rustdoc";
75 RustcBook, "src/doc/rustc", "rustc";
76 RustByExample, "src/doc/rust-by-example", "rust-by-example";
79 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
81 target: Interned<String>,
82 name: Interned<String>,
85 impl Step for Rustbook {
88 // rustbook is never directly called, and only serves as a shim for the nomicon and the
90 fn should_run(run: ShouldRun) -> ShouldRun {
94 /// Invoke `rustbook` for `target` for the doc book `name`.
96 /// This will not actually generate any documentation if the documentation has
97 /// already been generated.
98 fn run(self, builder: &Builder) {
99 let src = builder.src.join("src/doc");
100 builder.ensure(RustbookSrc {
103 src: INTERNER.intern_path(src),
108 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
109 pub struct UnstableBook {
110 target: Interned<String>,
113 impl Step for UnstableBook {
115 const DEFAULT: bool = true;
117 fn should_run(run: ShouldRun) -> ShouldRun {
118 let builder = run.builder;
119 run.path("src/doc/unstable-book").default_condition(builder.config.docs)
122 fn make_run(run: RunConfig) {
123 run.builder.ensure(UnstableBook {
128 fn run(self, builder: &Builder) {
129 builder.ensure(UnstableBookGen {
132 builder.ensure(RustbookSrc {
134 name: INTERNER.intern_str("unstable-book"),
135 src: builder.md_doc_out(self.target),
140 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
141 pub struct CargoBook {
142 target: Interned<String>,
143 name: Interned<String>,
146 impl Step for CargoBook {
148 const DEFAULT: bool = true;
150 fn should_run(run: ShouldRun) -> ShouldRun {
151 let builder = run.builder;
152 run.path("src/tools/cargo/src/doc/book").default_condition(builder.config.docs)
155 fn make_run(run: RunConfig) {
156 run.builder.ensure(CargoBook {
158 name: INTERNER.intern_str("cargo"),
162 fn run(self, builder: &Builder) {
163 let target = self.target;
164 let name = self.name;
165 let src = builder.src.join("src/tools/cargo/src/doc");
167 let out = builder.doc_out(target);
168 t!(fs::create_dir_all(&out));
170 let out = out.join(name);
172 builder.info(&format!("Cargo Book ({}) - {}", target, name));
174 let _ = fs::remove_dir_all(&out);
176 builder.run(builder.tool_cmd(Tool::Rustbook)
184 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
186 target: Interned<String>,
187 name: Interned<String>,
188 src: Interned<PathBuf>,
191 impl Step for RustbookSrc {
194 fn should_run(run: ShouldRun) -> ShouldRun {
198 /// Invoke `rustbook` for `target` for the doc book `name` from the `src` path.
200 /// This will not actually generate any documentation if the documentation has
201 /// already been generated.
202 fn run(self, builder: &Builder) {
203 let target = self.target;
204 let name = self.name;
206 let out = builder.doc_out(target);
207 t!(fs::create_dir_all(&out));
209 let out = out.join(name);
210 let src = src.join(name);
211 let index = out.join("index.html");
212 let rustbook = builder.tool_exe(Tool::Rustbook);
213 let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
214 if up_to_date(&src, &index) && up_to_date(&rustbook, &index) {
217 builder.info(&format!("Rustbook ({}) - {}", target, name));
218 let _ = fs::remove_dir_all(&out);
219 builder.run(rustbook_cmd
227 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
230 target: Interned<String>,
234 impl Step for TheBook {
236 const DEFAULT: bool = true;
238 fn should_run(run: ShouldRun) -> ShouldRun {
239 let builder = run.builder;
240 run.path("src/doc/book").default_condition(builder.config.docs)
243 fn make_run(run: RunConfig) {
244 run.builder.ensure(TheBook {
245 compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
251 /// Build the book and associated stuff.
253 /// We need to build:
255 /// * Book (first edition)
256 /// * Book (second edition)
257 /// * Version info and CSS
260 fn run(self, builder: &Builder) {
261 let compiler = self.compiler;
262 let target = self.target;
263 let name = self.name;
266 builder.ensure(Rustbook {
268 name: INTERNER.intern_string(name.to_string()),
271 // building older edition redirects
273 let source_name = format!("{}/first-edition", name);
274 builder.ensure(Rustbook {
276 name: INTERNER.intern_string(source_name),
279 let source_name = format!("{}/second-edition", name);
280 builder.ensure(Rustbook {
282 name: INTERNER.intern_string(source_name),
285 let source_name = format!("{}/2018-edition", name);
286 builder.ensure(Rustbook {
288 name: INTERNER.intern_string(source_name),
291 // build the version info page and CSS
292 builder.ensure(Standalone {
297 // build the redirect pages
298 builder.info(&format!("Documenting book redirect pages ({})", target));
299 for file in t!(fs::read_dir(builder.src.join("src/doc/book/redirects"))) {
301 let path = file.path();
302 let path = path.to_str().unwrap();
304 invoke_rustdoc(builder, compiler, target, path);
309 fn invoke_rustdoc(builder: &Builder, compiler: Compiler, target: Interned<String>, markdown: &str) {
310 let out = builder.doc_out(target);
312 let path = builder.src.join("src/doc").join(markdown);
314 let favicon = builder.src.join("src/doc/favicon.inc");
315 let footer = builder.src.join("src/doc/footer.inc");
316 let version_info = out.join("version_info.html");
318 let mut cmd = builder.rustdoc_cmd(compiler.host);
320 let out = out.join("book");
322 cmd.arg("--html-after-content").arg(&footer)
323 .arg("--html-before-content").arg(&version_info)
324 .arg("--html-in-header").arg(&favicon)
325 .arg("--markdown-no-toc")
326 .arg("--markdown-playground-url")
327 .arg("https://play.rust-lang.org/")
330 .arg("--markdown-css")
333 builder.run(&mut cmd);
336 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
337 pub struct Standalone {
339 target: Interned<String>,
342 impl Step for Standalone {
344 const DEFAULT: bool = true;
346 fn should_run(run: ShouldRun) -> ShouldRun {
347 let builder = run.builder;
348 run.path("src/doc").default_condition(builder.config.docs)
351 fn make_run(run: RunConfig) {
352 run.builder.ensure(Standalone {
353 compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
358 /// Generates all standalone documentation as compiled by the rustdoc in `stage`
359 /// for the `target` into `out`.
361 /// This will list all of `src/doc` looking for markdown files and appropriately
362 /// perform transformations like substituting `VERSION`, `SHORT_HASH`, and
363 /// `STAMP` along with providing the various header/footer HTML we've customized.
365 /// In the end, this is just a glorified wrapper around rustdoc!
366 fn run(self, builder: &Builder) {
367 let target = self.target;
368 let compiler = self.compiler;
369 builder.info(&format!("Documenting standalone ({})", target));
370 let out = builder.doc_out(target);
371 t!(fs::create_dir_all(&out));
373 let favicon = builder.src.join("src/doc/favicon.inc");
374 let footer = builder.src.join("src/doc/footer.inc");
375 let full_toc = builder.src.join("src/doc/full-toc.inc");
376 t!(fs::copy(builder.src.join("src/doc/rust.css"), out.join("rust.css")));
378 let version_input = builder.src.join("src/doc/version_info.html.template");
379 let version_info = out.join("version_info.html");
381 if !builder.config.dry_run && !up_to_date(&version_input, &version_info) {
382 let mut info = String::new();
383 t!(t!(File::open(&version_input)).read_to_string(&mut info));
384 let info = info.replace("VERSION", &builder.rust_release())
385 .replace("SHORT_HASH", builder.rust_info.sha_short().unwrap_or(""))
386 .replace("STAMP", builder.rust_info.sha().unwrap_or(""));
387 t!(t!(File::create(&version_info)).write_all(info.as_bytes()));
390 for file in t!(fs::read_dir(builder.src.join("src/doc"))) {
392 let path = file.path();
393 let filename = path.file_name().unwrap().to_str().unwrap();
394 if !filename.ends_with(".md") || filename == "README.md" {
398 let html = out.join(filename).with_extension("html");
399 let rustdoc = builder.rustdoc(compiler.host);
400 if up_to_date(&path, &html) &&
401 up_to_date(&footer, &html) &&
402 up_to_date(&favicon, &html) &&
403 up_to_date(&full_toc, &html) &&
404 up_to_date(&version_info, &html) &&
405 (builder.config.dry_run || up_to_date(&rustdoc, &html)) {
409 let mut cmd = builder.rustdoc_cmd(compiler.host);
410 cmd.arg("--html-after-content").arg(&footer)
411 .arg("--html-before-content").arg(&version_info)
412 .arg("--html-in-header").arg(&favicon)
413 .arg("--markdown-no-toc")
414 .arg("--index-page").arg(&builder.src.join("src/doc/index.md"))
415 .arg("--markdown-playground-url")
416 .arg("https://play.rust-lang.org/")
420 if filename == "not_found.md" {
421 cmd.arg("--markdown-css")
422 .arg("https://doc.rust-lang.org/rust.css");
424 cmd.arg("--markdown-css").arg("rust.css");
426 builder.run(&mut cmd);
431 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
434 pub target: Interned<String>,
439 const DEFAULT: bool = true;
441 fn should_run(run: ShouldRun) -> ShouldRun {
442 let builder = run.builder;
443 run.all_krates("std").default_condition(builder.config.docs)
446 fn make_run(run: RunConfig) {
447 run.builder.ensure(Std {
448 stage: run.builder.top_stage,
453 /// Compile all standard library documentation.
455 /// This will generate all documentation for the standard library and its
456 /// dependencies. This is largely just a wrapper around `cargo doc`.
457 fn run(self, builder: &Builder) {
458 let stage = self.stage;
459 let target = self.target;
460 builder.info(&format!("Documenting stage{} std ({})", stage, target));
461 let out = builder.doc_out(target);
462 t!(fs::create_dir_all(&out));
463 let compiler = builder.compiler(stage, builder.config.build);
464 let compiler = if builder.force_use_stage1(compiler, target) {
465 builder.compiler(1, compiler.host)
470 builder.ensure(compile::Std { compiler, target });
471 let out_dir = builder.stage_out(compiler, Mode::Std)
472 .join(target).join("doc");
474 // Here what we're doing is creating a *symlink* (directory junction on
475 // Windows) to the final output location. This is not done as an
476 // optimization but rather for correctness. We've got three trees of
477 // documentation, one for std, one for test, and one for rustc. It's then
478 // our job to merge them all together.
480 // Unfortunately rustbuild doesn't know nearly as well how to merge doc
481 // trees as rustdoc does itself, so instead of actually having three
482 // separate trees we just have rustdoc output to the same location across
485 // This way rustdoc generates output directly into the output, and rustdoc
486 // will also directly handle merging.
487 let my_out = builder.crate_doc_out(target);
488 t!(symlink_dir_force(&builder.config, &my_out, &out_dir));
489 t!(fs::copy(builder.src.join("src/doc/rust.css"), out.join("rust.css")));
491 let run_cargo_rustdoc_for = |package: &str| {
492 let mut cargo = builder.cargo(compiler, Mode::Std, target, "rustdoc");
493 compile::std_cargo(builder, &compiler, target, &mut cargo);
495 // Keep a whitelist so we do not build internal stdlib crates, these will be
496 // build by the rustc step later if enabled.
497 cargo.arg("-Z").arg("unstable-options")
498 .arg("-p").arg(package);
499 // Create all crate output directories first to make sure rustdoc uses
501 // FIXME: Cargo should probably do this itself.
502 t!(fs::create_dir_all(out_dir.join(package)));
504 .arg("--markdown-css").arg("rust.css")
505 .arg("--markdown-no-toc")
506 .arg("--index-page").arg(&builder.src.join("src/doc/index.md"));
508 builder.run(&mut cargo);
509 builder.cp_r(&my_out, &out);
511 for krate in &["alloc", "core", "std"] {
512 run_cargo_rustdoc_for(krate);
517 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
520 target: Interned<String>,
525 const DEFAULT: bool = true;
527 fn should_run(run: ShouldRun) -> ShouldRun {
528 let builder = run.builder;
529 run.krate("test").default_condition(builder.config.docs)
532 fn make_run(run: RunConfig) {
533 run.builder.ensure(Test {
534 stage: run.builder.top_stage,
539 /// Compile all libtest documentation.
541 /// This will generate all documentation for libtest and its dependencies. This
542 /// is largely just a wrapper around `cargo doc`.
543 fn run(self, builder: &Builder) {
544 let stage = self.stage;
545 let target = self.target;
546 builder.info(&format!("Documenting stage{} test ({})", stage, target));
547 let out = builder.doc_out(target);
548 t!(fs::create_dir_all(&out));
549 let compiler = builder.compiler(stage, builder.config.build);
550 let compiler = if builder.force_use_stage1(compiler, target) {
551 builder.compiler(1, compiler.host)
556 // Build libstd docs so that we generate relative links
557 builder.ensure(Std { stage, target });
559 builder.ensure(compile::Test { compiler, target });
560 let out_dir = builder.stage_out(compiler, Mode::Test)
561 .join(target).join("doc");
563 // See docs in std above for why we symlink
564 let my_out = builder.crate_doc_out(target);
565 t!(symlink_dir_force(&builder.config, &my_out, &out_dir));
567 let mut cargo = builder.cargo(compiler, Mode::Test, target, "doc");
568 compile::test_cargo(builder, &compiler, target, &mut cargo);
570 cargo.arg("--no-deps").arg("-p").arg("test");
572 builder.run(&mut cargo);
573 builder.cp_r(&my_out, &out);
577 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
578 pub struct WhitelistedRustc {
580 target: Interned<String>,
583 impl Step for WhitelistedRustc {
585 const DEFAULT: bool = true;
586 const ONLY_HOSTS: bool = true;
588 fn should_run(run: ShouldRun) -> ShouldRun {
589 let builder = run.builder;
590 run.krate("rustc-main").default_condition(builder.config.docs)
593 fn make_run(run: RunConfig) {
594 run.builder.ensure(WhitelistedRustc {
595 stage: run.builder.top_stage,
600 /// Generate whitelisted compiler crate documentation.
602 /// This will generate all documentation for crates that are whitelisted
603 /// to be included in the standard documentation. This documentation is
604 /// included in the standard Rust documentation, so we should always
605 /// document it and symlink to merge with the rest of the std and test
606 /// documentation. We don't build other compiler documentation
607 /// here as we want to be able to keep it separate from the standard
608 /// documentation. This is largely just a wrapper around `cargo doc`.
609 fn run(self, builder: &Builder) {
610 let stage = self.stage;
611 let target = self.target;
612 builder.info(&format!("Documenting stage{} whitelisted compiler ({})", stage, target));
613 let out = builder.doc_out(target);
614 t!(fs::create_dir_all(&out));
615 let compiler = builder.compiler(stage, builder.config.build);
616 let compiler = if builder.force_use_stage1(compiler, target) {
617 builder.compiler(1, compiler.host)
622 // Build libstd docs so that we generate relative links
623 builder.ensure(Std { stage, target });
625 builder.ensure(compile::Rustc { compiler, target });
626 let out_dir = builder.stage_out(compiler, Mode::Rustc)
627 .join(target).join("doc");
629 // See docs in std above for why we symlink
630 let my_out = builder.crate_doc_out(target);
631 t!(symlink_dir_force(&builder.config, &my_out, &out_dir));
633 let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "doc");
634 compile::rustc_cargo(builder, &mut cargo);
636 // We don't want to build docs for internal compiler dependencies in this
637 // step (there is another step for that). Therefore, we whitelist the crates
638 // for which docs must be built.
639 cargo.arg("--no-deps");
640 for krate in &["proc_macro"] {
641 cargo.arg("-p").arg(krate);
644 builder.run(&mut cargo);
645 builder.cp_r(&my_out, &out);
649 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
652 target: Interned<String>,
655 impl Step for Rustc {
657 const DEFAULT: bool = true;
658 const ONLY_HOSTS: bool = true;
660 fn should_run(run: ShouldRun) -> ShouldRun {
661 let builder = run.builder;
662 run.krate("rustc-main").default_condition(builder.config.docs)
665 fn make_run(run: RunConfig) {
666 run.builder.ensure(Rustc {
667 stage: run.builder.top_stage,
672 /// Generate compiler documentation.
674 /// This will generate all documentation for compiler and dependencies.
675 /// Compiler documentation is distributed separately, so we make sure
676 /// we do not merge it with the other documentation from std, test and
677 /// proc_macros. This is largely just a wrapper around `cargo doc`.
678 fn run(self, builder: &Builder) {
679 let stage = self.stage;
680 let target = self.target;
681 builder.info(&format!("Documenting stage{} compiler ({})", stage, target));
683 // This is the intended out directory for compiler documentation.
684 let out = builder.compiler_doc_out(target);
685 t!(fs::create_dir_all(&out));
687 // Get the correct compiler for this stage.
688 let compiler = builder.compiler(stage, builder.config.build);
689 let compiler = if builder.force_use_stage1(compiler, target) {
690 builder.compiler(1, compiler.host)
695 if !builder.config.compiler_docs {
696 builder.info("\tskipping - compiler/librustdoc docs disabled");
700 // Build libstd docs so that we generate relative links.
701 builder.ensure(Std { stage, target });
704 builder.ensure(compile::Rustc { compiler, target });
706 // We do not symlink to the same shared folder that already contains std library
707 // documentation from previous steps as we do not want to include that.
708 let out_dir = builder.stage_out(compiler, Mode::Rustc).join(target).join("doc");
709 t!(symlink_dir_force(&builder.config, &out, &out_dir));
711 // Build cargo command.
712 let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "doc");
713 cargo.env("RUSTDOCFLAGS", "--document-private-items");
714 compile::rustc_cargo(builder, &mut cargo);
716 // Only include compiler crates, no dependencies of those, such as `libc`.
717 cargo.arg("--no-deps");
719 // Find dependencies for top level crates.
720 let mut compiler_crates = HashSet::new();
721 for root_crate in &["rustc", "rustc_driver", "rustc_codegen_llvm"] {
722 let interned_root_crate = INTERNER.intern_str(root_crate);
723 find_compiler_crates(builder, &interned_root_crate, &mut compiler_crates);
726 for krate in &compiler_crates {
727 cargo.arg("-p").arg(krate);
730 builder.run(&mut cargo);
734 fn find_compiler_crates(
736 name: &Interned<String>,
737 crates: &mut HashSet<Interned<String>>
739 // Add current crate.
740 crates.insert(*name);
742 // Look for dependencies.
743 for dep in builder.crates.get(name).unwrap().deps.iter() {
744 if builder.crates.get(dep).unwrap().is_local(builder) {
745 find_compiler_crates(builder, dep, crates);
750 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
753 target: Interned<String>,
756 impl Step for Rustdoc {
758 const DEFAULT: bool = true;
759 const ONLY_HOSTS: bool = true;
761 fn should_run(run: ShouldRun) -> ShouldRun {
762 run.krate("rustdoc-tool")
765 fn make_run(run: RunConfig) {
766 run.builder.ensure(Rustdoc {
767 stage: run.builder.top_stage,
772 /// Generate compiler documentation.
774 /// This will generate all documentation for compiler and dependencies.
775 /// Compiler documentation is distributed separately, so we make sure
776 /// we do not merge it with the other documentation from std, test and
777 /// proc_macros. This is largely just a wrapper around `cargo doc`.
778 fn run(self, builder: &Builder) {
779 let stage = self.stage;
780 let target = self.target;
781 builder.info(&format!("Documenting stage{} rustdoc ({})", stage, target));
783 // This is the intended out directory for compiler documentation.
784 let out = builder.compiler_doc_out(target);
785 t!(fs::create_dir_all(&out));
787 // Get the correct compiler for this stage.
788 let compiler = builder.compiler(stage, builder.config.build);
789 let compiler = if builder.force_use_stage1(compiler, target) {
790 builder.compiler(1, compiler.host)
795 if !builder.config.compiler_docs {
796 builder.info("\tskipping - compiler/librustdoc docs disabled");
800 // Build libstd docs so that we generate relative links.
801 builder.ensure(Std { stage, target });
804 builder.ensure(tool::Rustdoc { host: compiler.host });
806 // Symlink compiler docs to the output directory of rustdoc documentation.
807 let out_dir = builder.stage_out(compiler, Mode::ToolRustc)
810 t!(fs::create_dir_all(&out_dir));
811 t!(symlink_dir_force(&builder.config, &out, &out_dir));
813 // Build cargo command.
814 let mut cargo = prepare_tool_cargo(
825 cargo.env("RUSTDOCFLAGS", "--document-private-items");
826 builder.run(&mut cargo);
830 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
831 pub struct ErrorIndex {
832 target: Interned<String>,
835 impl Step for ErrorIndex {
837 const DEFAULT: bool = true;
838 const ONLY_HOSTS: bool = true;
840 fn should_run(run: ShouldRun) -> ShouldRun {
841 let builder = run.builder;
842 run.path("src/tools/error_index_generator").default_condition(builder.config.docs)
845 fn make_run(run: RunConfig) {
846 run.builder.ensure(ErrorIndex {
851 /// Generates the HTML rendered error-index by running the
852 /// `error_index_generator` tool.
853 fn run(self, builder: &Builder) {
854 let target = self.target;
856 builder.info(&format!("Documenting error index ({})", target));
857 let out = builder.doc_out(target);
858 t!(fs::create_dir_all(&out));
859 let mut index = builder.tool_cmd(Tool::ErrorIndex);
861 index.arg(out.join("error-index.html"));
863 // FIXME: shouldn't have to pass this env var
864 index.env("CFG_BUILD", &builder.config.build)
865 .env("RUSTC_ERROR_METADATA_DST", builder.extended_error_dir());
867 builder.run(&mut index);
871 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
872 pub struct UnstableBookGen {
873 target: Interned<String>,
876 impl Step for UnstableBookGen {
878 const DEFAULT: bool = true;
879 const ONLY_HOSTS: bool = true;
881 fn should_run(run: ShouldRun) -> ShouldRun {
882 let builder = run.builder;
883 run.path("src/tools/unstable-book-gen").default_condition(builder.config.docs)
886 fn make_run(run: RunConfig) {
887 run.builder.ensure(UnstableBookGen {
892 fn run(self, builder: &Builder) {
893 let target = self.target;
895 builder.ensure(compile::Std {
896 compiler: builder.compiler(builder.top_stage, builder.config.build),
900 builder.info(&format!("Generating unstable book md files ({})", target));
901 let out = builder.md_doc_out(target).join("unstable-book");
902 builder.create_dir(&out);
903 builder.remove_dir(&out);
904 let mut cmd = builder.tool_cmd(Tool::UnstableBookGen);
905 cmd.arg(builder.src.join("src"));
908 builder.run(&mut cmd);
912 fn symlink_dir_force(config: &Config, src: &Path, dst: &Path) -> io::Result<()> {
916 if let Ok(m) = fs::symlink_metadata(dst) {
917 if m.file_type().is_dir() {
918 fs::remove_dir_all(dst)?;
920 // handle directory junctions on windows by falling back to
922 fs::remove_file(dst).or_else(|_| {
928 symlink_dir(config, src, dst)