]> git.lizzy.rs Git - rust.git/blobdiff - src/bootstrap/doc.rs
Rollup merge of #104266 - compiler-errors:issue-102430, r=Mark-Simulacrum
[rust.git] / src / bootstrap / doc.rs
index 1357718b84e351e67cfe4da6bf4c7d6307db2ae1..c7d21bf3cdb3fcce65458134459376d8d86c11c1 100644 (file)
@@ -151,7 +151,7 @@ fn run(self, builder: &Builder<'_>) {
         let index = out.join("index.html");
         let rustbook = builder.tool_exe(Tool::Rustbook);
         let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
-        if builder.config.dry_run || up_to_date(&src, &index) && up_to_date(&rustbook, &index) {
+        if builder.config.dry_run() || up_to_date(&src, &index) && up_to_date(&rustbook, &index) {
             return;
         }
         builder.info(&format!("Rustbook ({}) - {}", target, name));
@@ -331,8 +331,8 @@ fn run(self, builder: &Builder<'_>) {
                 && up_to_date(&footer, &html)
                 && up_to_date(&favicon, &html)
                 && up_to_date(&full_toc, &html)
-                && (builder.config.dry_run || up_to_date(&version_info, &html))
-                && (builder.config.dry_run || up_to_date(&rustdoc, &html))
+                && (builder.config.dry_run() || up_to_date(&version_info, &html))
+                && (builder.config.dry_run() || up_to_date(&rustdoc, &html))
             {
                 continue;
             }
@@ -402,7 +402,7 @@ fn run(self, builder: &Builder<'_>) -> Self::Output {
 
         let version_input = builder.src.join("src").join("doc").join("version_info.html.template");
         let version_info = out.join("version_info.html");
-        if !builder.config.dry_run && !up_to_date(&version_input, &version_info) {
+        if !builder.config.dry_run() && !up_to_date(&version_input, &version_info) {
             let info = t!(fs::read_to_string(&version_input))
                 .replace("VERSION", &builder.rust_release())
                 .replace("SHORT_HASH", builder.rust_info.sha_short().unwrap_or(""))
@@ -420,6 +420,7 @@ fn run(self, builder: &Builder<'_>) -> Self::Output {
 pub struct Std {
     pub stage: u32,
     pub target: TargetSelection,
+    pub format: DocumentationFormat,
 }
 
 impl Step for Std {
@@ -432,7 +433,15 @@ fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
     }
 
     fn make_run(run: RunConfig<'_>) {
-        run.builder.ensure(Std { stage: run.builder.top_stage, target: run.target });
+        run.builder.ensure(Std {
+            stage: run.builder.top_stage,
+            target: run.target,
+            format: if run.builder.config.cmd.json() {
+                DocumentationFormat::JSON
+            } else {
+                DocumentationFormat::HTML
+            },
+        });
     }
 
     /// Compile all standard library documentation.
@@ -442,19 +451,26 @@ fn make_run(run: RunConfig<'_>) {
     fn run(self, builder: &Builder<'_>) {
         let stage = self.stage;
         let target = self.target;
-        let out = builder.doc_out(target);
+        let out = match self.format {
+            DocumentationFormat::HTML => builder.doc_out(target),
+            DocumentationFormat::JSON => builder.json_doc_out(target),
+        };
+
         t!(fs::create_dir_all(&out));
 
         builder.ensure(SharedAssets { target: self.target });
 
         let index_page = builder.src.join("src/doc/index.md").into_os_string();
-        let mut extra_args = vec![
-            OsStr::new("--markdown-css"),
-            OsStr::new("rust.css"),
-            OsStr::new("--markdown-no-toc"),
-            OsStr::new("--index-page"),
-            &index_page,
-        ];
+        let mut extra_args = match self.format {
+            DocumentationFormat::HTML => vec![
+                OsStr::new("--markdown-css"),
+                OsStr::new("rust.css"),
+                OsStr::new("--markdown-no-toc"),
+                OsStr::new("--index-page"),
+                &index_page,
+            ],
+            DocumentationFormat::JSON => vec![OsStr::new("--output-format"), OsStr::new("json")],
+        };
 
         if !builder.config.docs_minification {
             extra_args.push(OsStr::new("--disable-minification"));
@@ -478,15 +494,12 @@ fn run(self, builder: &Builder<'_>) {
             })
             .collect::<Vec<_>>();
 
-        doc_std(
-            builder,
-            DocumentationFormat::HTML,
-            stage,
-            target,
-            &out,
-            &extra_args,
-            &requested_crates,
-        );
+        doc_std(builder, self.format, stage, target, &out, &extra_args, &requested_crates);
+
+        // Don't open if the format is json
+        if let DocumentationFormat::JSON = self.format {
+            return;
+        }
 
         // Look for library/std, library/core etc in the `x.py doc` arguments and
         // open the corresponding rendered docs.
@@ -499,38 +512,6 @@ fn run(self, builder: &Builder<'_>) {
     }
 }
 
-#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
-pub struct JsonStd {
-    pub stage: u32,
-    pub target: TargetSelection,
-}
-
-impl Step for JsonStd {
-    type Output = ();
-    const DEFAULT: bool = false;
-
-    fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
-        let default = run.builder.config.docs && run.builder.config.cmd.json();
-        run.all_krates("test").path("library").default_condition(default)
-    }
-
-    fn make_run(run: RunConfig<'_>) {
-        run.builder.ensure(Std { stage: run.builder.top_stage, target: run.target });
-    }
-
-    /// Build JSON documentation for the standard library crates.
-    ///
-    /// This is largely just a wrapper around `cargo doc`.
-    fn run(self, builder: &Builder<'_>) {
-        let stage = self.stage;
-        let target = self.target;
-        let out = builder.json_doc_out(target);
-        t!(fs::create_dir_all(&out));
-        let extra_args = [OsStr::new("--output-format"), OsStr::new("json")];
-        doc_std(builder, DocumentationFormat::JSON, stage, target, &out, &extra_args, &[])
-    }
-}
-
 /// Name of the crates that are visible to consumers of the standard library.
 /// Documentation for internal crates is handled by the rustc step, so internal crates will show
 /// up there.
@@ -543,7 +524,7 @@ fn run(self, builder: &Builder<'_>) {
 const STD_PUBLIC_CRATES: [&str; 5] = ["core", "alloc", "std", "proc_macro", "test"];
 
 #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
-enum DocumentationFormat {
+pub enum DocumentationFormat {
     HTML,
     JSON,
 }
@@ -919,7 +900,7 @@ fn run(self, builder: &Builder<'_>) {
 }
 
 fn symlink_dir_force(config: &Config, src: &Path, dst: &Path) -> io::Result<()> {
-    if config.dry_run {
+    if config.dry_run() {
         return Ok(());
     }
     if let Ok(m) = fs::symlink_metadata(dst) {