about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authorEric Huss <eric@huss.org>2020-09-08 15:09:57 -0700
committerEric Huss <eric@huss.org>2020-09-13 08:48:03 -0700
commit45c1e0ae07b9581d8c2d2b39315ac7cc79475d75 (patch)
treebffba54de1eeb0b5dc313e3497b68aead9b9cc97 /src/bootstrap
parenta055c5a1bd95e029e9b31891db63b6dc8258b472 (diff)
downloadrust-45c1e0ae07b9581d8c2d2b39315ac7cc79475d75.tar.gz
rust-45c1e0ae07b9581d8c2d2b39315ac7cc79475d75.zip
Auto-generate lint documentation.
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/doc.rs67
-rw-r--r--src/bootstrap/tool.rs1
2 files changed, 67 insertions, 1 deletions
diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs
index d7f3a888edd..be5182b939d 100644
--- a/src/bootstrap/doc.rs
+++ b/src/bootstrap/doc.rs
@@ -66,7 +66,6 @@ book!(
     Nomicon, "src/doc/nomicon", "nomicon";
     Reference, "src/doc/reference", "reference";
     RustByExample, "src/doc/rust-by-example", "rust-by-example";
-    RustcBook, "src/doc/rustc", "rustc";
     RustdocBook, "src/doc/rustdoc", "rustdoc";
 );
 
@@ -718,3 +717,69 @@ fn symlink_dir_force(config: &Config, src: &Path, dst: &Path) -> io::Result<()>
 
     symlink_dir(config, src, dst)
 }
+
+#[derive(Ord, PartialOrd, Debug, Copy, Clone, Hash, PartialEq, Eq)]
+pub struct RustcBook {
+    pub compiler: Compiler,
+    pub target: TargetSelection,
+}
+
+impl Step for RustcBook {
+    type Output = ();
+    const DEFAULT: bool = true;
+    const ONLY_HOSTS: bool = true;
+
+    fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
+        let builder = run.builder;
+        run.path("src/doc/rustc").default_condition(builder.config.docs)
+    }
+
+    fn make_run(run: RunConfig<'_>) {
+        run.builder.ensure(RustcBook {
+            compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
+            target: run.target,
+        });
+    }
+
+    /// Builds the rustc book.
+    ///
+    /// The lints are auto-generated by a tool, and then merged into the book
+    /// in the "md-doc" directory in the build output directory. Then
+    /// "rustbook" is used to convert it to HTML.
+    fn run(self, builder: &Builder<'_>) {
+        let out_base = builder.md_doc_out(self.target).join("rustc");
+        t!(fs::create_dir_all(&out_base));
+        let out_listing = out_base.join("src/lints");
+        builder.cp_r(&builder.src.join("src/doc/rustc"), &out_base);
+        builder.info(&format!("Generating lint docs ({})", self.target));
+        let rustc = builder.rustc(self.compiler);
+        // The tool runs `rustc` for extracting output examples, so it needs a
+        // functional sysroot.
+        builder.ensure(compile::Std { compiler: self.compiler, target: self.target });
+        let rustdoc = builder.rustdoc(self.compiler);
+        let mut cmd = builder.tool_cmd(Tool::LintDocs);
+        cmd.arg("--src");
+        cmd.arg(builder.src.join("compiler"));
+        cmd.arg("--out");
+        cmd.arg(&out_listing);
+        cmd.arg("--rustc");
+        cmd.arg(rustc);
+        cmd.arg("--rustdoc");
+        cmd.arg(rustdoc);
+        if builder.config.verbose() {
+            cmd.arg("--verbose");
+        }
+        builder.run(&mut cmd);
+        // Run rustbook/mdbook to generate the HTML pages.
+        builder.ensure(RustbookSrc {
+            target: self.target,
+            name: INTERNER.intern_str("rustc"),
+            src: INTERNER.intern_path(out_base),
+        });
+        if is_explicit_request(builder, "src/doc/rustc") {
+            let out = builder.doc_out(self.target);
+            let index = out.join("rustc").join("index.html");
+            open(builder, &index);
+        }
+    }
+}
diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs
index a607f0fe258..99e33e3b006 100644
--- a/src/bootstrap/tool.rs
+++ b/src/bootstrap/tool.rs
@@ -367,6 +367,7 @@ bootstrap_tool!(
     RustInstaller, "src/tools/rust-installer", "fabricate", is_external_tool = true;
     RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes";
     ExpandYamlAnchors, "src/tools/expand-yaml-anchors", "expand-yaml-anchors";
+    LintDocs, "src/tools/lint-docs", "lint-docs";
 );
 
 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]