Skip to content

Commit 2e92f66

Browse files
authored
Rollup merge of #103851 - viandoxdev:103816_bootstrap_fix_json_doc, r=jyn514
Fix json flag in bootstrap doc Fix the `--json` flag not working with x.py (Closes #103816) While this works I'm not sure about the `should_run` of `JsonStd`, had to change it because https://github.com/rust-lang/rust/blob/ab5a2bc7316012ee9b2a4a4f3821673f2677f3d5/src/bootstrap/builder.rs#L334 would match with JsonStd and remove the paths that Std matched. So I did [this](https://github.com/viandoxdev/rust/blob/ffd4078264c4892b5098d6191e0adfe3564d62ca/src/bootstrap/doc.rs#L526-L534) but that looks more like a hack/workaround than anything. I'm guessing there's something to do with the default condition thing but idk how it works
2 parents 2e08d30 + 900af41 commit 2e92f66

File tree

3 files changed

+44
-53
lines changed

3 files changed

+44
-53
lines changed

src/bootstrap/dist.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::cache::{Interned, INTERNER};
1919
use crate::channel;
2020
use crate::compile;
2121
use crate::config::TargetSelection;
22+
use crate::doc::DocumentationFormat;
2223
use crate::tarball::{GeneratedTarball, OverlayKind, Tarball};
2324
use crate::tool::{self, Tool};
2425
use crate::util::{exe, is_dylib, output, t, timeit};
@@ -97,7 +98,11 @@ impl Step for JsonDocs {
9798
/// Builds the `rust-docs-json` installer component.
9899
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
99100
let host = self.host;
100-
builder.ensure(crate::doc::JsonStd { stage: builder.top_stage, target: host });
101+
builder.ensure(crate::doc::Std {
102+
stage: builder.top_stage,
103+
target: host,
104+
format: DocumentationFormat::JSON,
105+
});
101106

102107
let dest = "share/doc/rust/json";
103108

src/bootstrap/doc.rs

Lines changed: 32 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ impl Step for SharedAssets {
420420
pub struct Std {
421421
pub stage: u32,
422422
pub target: TargetSelection,
423+
pub format: DocumentationFormat,
423424
}
424425

425426
impl Step for Std {
@@ -432,7 +433,15 @@ impl Step for Std {
432433
}
433434

434435
fn make_run(run: RunConfig<'_>) {
435-
run.builder.ensure(Std { stage: run.builder.top_stage, target: run.target });
436+
run.builder.ensure(Std {
437+
stage: run.builder.top_stage,
438+
target: run.target,
439+
format: if run.builder.config.cmd.json() {
440+
DocumentationFormat::JSON
441+
} else {
442+
DocumentationFormat::HTML
443+
},
444+
});
436445
}
437446

438447
/// Compile all standard library documentation.
@@ -442,19 +451,26 @@ impl Step for Std {
442451
fn run(self, builder: &Builder<'_>) {
443452
let stage = self.stage;
444453
let target = self.target;
445-
let out = builder.doc_out(target);
454+
let out = match self.format {
455+
DocumentationFormat::HTML => builder.doc_out(target),
456+
DocumentationFormat::JSON => builder.json_doc_out(target),
457+
};
458+
446459
t!(fs::create_dir_all(&out));
447460

448461
builder.ensure(SharedAssets { target: self.target });
449462

450463
let index_page = builder.src.join("src/doc/index.md").into_os_string();
451-
let mut extra_args = vec![
452-
OsStr::new("--markdown-css"),
453-
OsStr::new("rust.css"),
454-
OsStr::new("--markdown-no-toc"),
455-
OsStr::new("--index-page"),
456-
&index_page,
457-
];
464+
let mut extra_args = match self.format {
465+
DocumentationFormat::HTML => vec![
466+
OsStr::new("--markdown-css"),
467+
OsStr::new("rust.css"),
468+
OsStr::new("--markdown-no-toc"),
469+
OsStr::new("--index-page"),
470+
&index_page,
471+
],
472+
DocumentationFormat::JSON => vec![OsStr::new("--output-format"), OsStr::new("json")],
473+
};
458474

459475
if !builder.config.docs_minification {
460476
extra_args.push(OsStr::new("--disable-minification"));
@@ -478,15 +494,12 @@ impl Step for Std {
478494
})
479495
.collect::<Vec<_>>();
480496

481-
doc_std(
482-
builder,
483-
DocumentationFormat::HTML,
484-
stage,
485-
target,
486-
&out,
487-
&extra_args,
488-
&requested_crates,
489-
);
497+
doc_std(builder, self.format, stage, target, &out, &extra_args, &requested_crates);
498+
499+
// Don't open if the format is json
500+
if let DocumentationFormat::JSON = self.format {
501+
return;
502+
}
490503

491504
// Look for library/std, library/core etc in the `x.py doc` arguments and
492505
// open the corresponding rendered docs.
@@ -499,38 +512,6 @@ impl Step for Std {
499512
}
500513
}
501514

502-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
503-
pub struct JsonStd {
504-
pub stage: u32,
505-
pub target: TargetSelection,
506-
}
507-
508-
impl Step for JsonStd {
509-
type Output = ();
510-
const DEFAULT: bool = false;
511-
512-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
513-
let default = run.builder.config.docs && run.builder.config.cmd.json();
514-
run.all_krates("test").path("library").default_condition(default)
515-
}
516-
517-
fn make_run(run: RunConfig<'_>) {
518-
run.builder.ensure(Std { stage: run.builder.top_stage, target: run.target });
519-
}
520-
521-
/// Build JSON documentation for the standard library crates.
522-
///
523-
/// This is largely just a wrapper around `cargo doc`.
524-
fn run(self, builder: &Builder<'_>) {
525-
let stage = self.stage;
526-
let target = self.target;
527-
let out = builder.json_doc_out(target);
528-
t!(fs::create_dir_all(&out));
529-
let extra_args = [OsStr::new("--output-format"), OsStr::new("json")];
530-
doc_std(builder, DocumentationFormat::JSON, stage, target, &out, &extra_args, &[])
531-
}
532-
}
533-
534515
/// Name of the crates that are visible to consumers of the standard library.
535516
/// Documentation for internal crates is handled by the rustc step, so internal crates will show
536517
/// up there.
@@ -543,7 +524,7 @@ impl Step for JsonStd {
543524
const STD_PUBLIC_CRATES: [&str; 5] = ["core", "alloc", "std", "proc_macro", "test"];
544525

545526
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
546-
enum DocumentationFormat {
527+
pub enum DocumentationFormat {
547528
HTML,
548529
JSON,
549530
}

src/bootstrap/test.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::cache::Interned;
1616
use crate::compile;
1717
use crate::config::TargetSelection;
1818
use crate::dist;
19+
use crate::doc::DocumentationFormat;
1920
use crate::flags::Subcommand;
2021
use crate::native;
2122
use crate::tool::{self, SourceType, Tool};
@@ -822,7 +823,11 @@ impl Step for RustdocJSStd {
822823
command.arg("--test-file").arg(path);
823824
}
824825
}
825-
builder.ensure(crate::doc::Std { target: self.target, stage: builder.top_stage });
826+
builder.ensure(crate::doc::Std {
827+
target: self.target,
828+
stage: builder.top_stage,
829+
format: DocumentationFormat::HTML,
830+
});
826831
builder.run(&mut command);
827832
} else {
828833
builder.info("No nodejs found, skipping \"src/test/rustdoc-js-std\" tests");

0 commit comments

Comments
 (0)