From 6e1361f358849b55f9112dd374282161dfb67e2e Mon Sep 17 00:00:00 2001 From: viandoxdev Date: Tue, 1 Nov 2022 21:50:28 +0100 Subject: [PATCH 1/4] Fixes #103816 make --json work --- src/bootstrap/builder.rs | 1 + src/bootstrap/doc.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index c8285c85d0358..e2d76a0c57e8a 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -689,6 +689,7 @@ impl<'a> Builder<'a> { doc::UnstableBookGen, doc::TheBook, doc::Standalone, + doc::JsonStd, doc::Std, doc::Rustc, doc::Rustdoc, diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 5d265b9ad0c19..649c11be8e05a 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -529,7 +529,7 @@ impl Step for JsonStd { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Std { stage: run.builder.top_stage, target: run.target }); + run.builder.ensure(JsonStd { stage: run.builder.top_stage, target: run.target }); } /// Build JSON documentation for the standard library crates. From ffd4078264c4892b5098d6191e0adfe3564d62ca Mon Sep 17 00:00:00 2001 From: viandoxdev Date: Tue, 1 Nov 2022 22:18:19 +0100 Subject: [PATCH 2/4] fix json running all the time --- src/bootstrap/doc.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 649c11be8e05a..827a5346491d2 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -524,8 +524,13 @@ impl Step for JsonStd { 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) + if run.builder.config.cmd.json() { + let default = run.builder.config.docs && run.builder.config.cmd.json(); + run.all_krates("test").path("library").default_condition(default) + } else { + // Without this JsonStd would take priority on Std and prevent it from running. + run.never() + } } fn make_run(run: RunConfig<'_>) { From 972d075aa62c87bc9fb660335e7dc1f75fa853c1 Mon Sep 17 00:00:00 2001 From: viandoxdev Date: Wed, 2 Nov 2022 11:23:42 +0100 Subject: [PATCH 3/4] merge JsonStd and Std steps --- src/bootstrap/builder.rs | 1 - src/bootstrap/dist.rs | 7 +++- src/bootstrap/doc.rs | 77 ++++++++++++---------------------------- src/bootstrap/test.rs | 7 +++- 4 files changed, 34 insertions(+), 58 deletions(-) diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index e2d76a0c57e8a..c8285c85d0358 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -689,7 +689,6 @@ impl<'a> Builder<'a> { doc::UnstableBookGen, doc::TheBook, doc::Standalone, - doc::JsonStd, doc::Std, doc::Rustc, doc::Rustdoc, diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 805633c926c3a..110a3ee4918da 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -19,6 +19,7 @@ use crate::cache::{Interned, INTERNER}; use crate::channel; use crate::compile; use crate::config::TargetSelection; +use crate::doc::DocumentationFormat; use crate::tarball::{GeneratedTarball, OverlayKind, Tarball}; use crate::tool::{self, Tool}; use crate::util::{exe, is_dylib, output, t, timeit}; @@ -97,7 +98,11 @@ impl Step for JsonDocs { /// Builds the `rust-docs-json` installer component. fn run(self, builder: &Builder<'_>) -> Option { let host = self.host; - builder.ensure(crate::doc::JsonStd { stage: builder.top_stage, target: host }); + builder.ensure(crate::doc::Std { + stage: builder.top_stage, + target: host, + format: DocumentationFormat::JSON, + }); let dest = "share/doc/rust/json"; diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index 827a5346491d2..bbd8830a01c9f 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -434,6 +434,7 @@ impl Step for SharedAssets { pub struct Std { pub stage: u32, pub target: TargetSelection, + pub format: DocumentationFormat, } impl Step for Std { @@ -446,7 +447,15 @@ impl Step for Std { } 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. @@ -462,13 +471,16 @@ impl Step for Std { 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")); @@ -492,15 +504,7 @@ impl Step for Std { }) .collect::>(); - doc_std( - builder, - DocumentationFormat::HTML, - stage, - target, - &out, - &extra_args, - &requested_crates, - ); + doc_std(builder, self.format, stage, target, &out, &extra_args, &requested_crates); // Look for library/std, library/core etc in the `x.py doc` arguments and // open the corresponding rendered docs. @@ -513,43 +517,6 @@ impl Step for Std { } } -#[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<'_> { - if run.builder.config.cmd.json() { - let default = run.builder.config.docs && run.builder.config.cmd.json(); - run.all_krates("test").path("library").default_condition(default) - } else { - // Without this JsonStd would take priority on Std and prevent it from running. - run.never() - } - } - - fn make_run(run: RunConfig<'_>) { - run.builder.ensure(JsonStd { 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. @@ -562,7 +529,7 @@ impl Step for JsonStd { 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, } diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index e168dd571f6d2..a73e0bb7b8c2f 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -16,6 +16,7 @@ use crate::cache::Interned; use crate::compile; use crate::config::TargetSelection; use crate::dist; +use crate::doc::DocumentationFormat; use crate::flags::Subcommand; use crate::native; use crate::tool::{self, SourceType, Tool}; @@ -822,7 +823,11 @@ impl Step for RustdocJSStd { command.arg("--test-file").arg(path); } } - builder.ensure(crate::doc::Std { target: self.target, stage: builder.top_stage }); + builder.ensure(crate::doc::Std { + target: self.target, + stage: builder.top_stage, + format: DocumentationFormat::HTML, + }); builder.run(&mut command); } else { builder.info("No nodejs found, skipping \"src/test/rustdoc-js-std\" tests"); From 1bc2bfa44cb70bb744bfd469f05d2d92e040e247 Mon Sep 17 00:00:00 2001 From: viandoxdev Date: Wed, 2 Nov 2022 11:28:31 +0100 Subject: [PATCH 4/4] prevent open with json --- src/bootstrap/doc.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index bbd8830a01c9f..f3883e5e6bfd1 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -506,6 +506,11 @@ impl Step for Std { 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. for requested_crate in requested_crates {