Skip to content

Commit 8fd875d

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#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 542cffe + 1bc2bfa commit 8fd875d

File tree

3 files changed

+39
-52
lines changed

3 files changed

+39
-52
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: 27 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ impl Step for SharedAssets {
434434
pub struct Std {
435435
pub stage: u32,
436436
pub target: TargetSelection,
437+
pub format: DocumentationFormat,
437438
}
438439

439440
impl Step for Std {
@@ -446,7 +447,15 @@ impl Step for Std {
446447
}
447448

448449
fn make_run(run: RunConfig<'_>) {
449-
run.builder.ensure(Std { stage: run.builder.top_stage, target: run.target });
450+
run.builder.ensure(Std {
451+
stage: run.builder.top_stage,
452+
target: run.target,
453+
format: if run.builder.config.cmd.json() {
454+
DocumentationFormat::JSON
455+
} else {
456+
DocumentationFormat::HTML
457+
},
458+
});
450459
}
451460

452461
/// Compile all standard library documentation.
@@ -462,13 +471,16 @@ impl Step for Std {
462471
builder.ensure(SharedAssets { target: self.target });
463472

464473
let index_page = builder.src.join("src/doc/index.md").into_os_string();
465-
let mut extra_args = 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-
];
474+
let mut extra_args = match self.format {
475+
DocumentationFormat::HTML => vec![
476+
OsStr::new("--markdown-css"),
477+
OsStr::new("rust.css"),
478+
OsStr::new("--markdown-no-toc"),
479+
OsStr::new("--index-page"),
480+
&index_page,
481+
],
482+
DocumentationFormat::JSON => vec![OsStr::new("--output-format"), OsStr::new("json")],
483+
};
472484

473485
if !builder.config.docs_minification {
474486
extra_args.push(OsStr::new("--disable-minification"));
@@ -492,15 +504,12 @@ impl Step for Std {
492504
})
493505
.collect::<Vec<_>>();
494506

495-
doc_std(
496-
builder,
497-
DocumentationFormat::HTML,
498-
stage,
499-
target,
500-
&out,
501-
&extra_args,
502-
&requested_crates,
503-
);
507+
doc_std(builder, self.format, stage, target, &out, &extra_args, &requested_crates);
508+
509+
// Don't open if the format is json
510+
if let DocumentationFormat::JSON = self.format {
511+
return;
512+
}
504513

505514
// Look for library/std, library/core etc in the `x.py doc` arguments and
506515
// open the corresponding rendered docs.
@@ -513,38 +522,6 @@ impl Step for Std {
513522
}
514523
}
515524

516-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
517-
pub struct JsonStd {
518-
pub stage: u32,
519-
pub target: TargetSelection,
520-
}
521-
522-
impl Step for JsonStd {
523-
type Output = ();
524-
const DEFAULT: bool = false;
525-
526-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
527-
let default = run.builder.config.docs && run.builder.config.cmd.json();
528-
run.all_krates("test").path("library").default_condition(default)
529-
}
530-
531-
fn make_run(run: RunConfig<'_>) {
532-
run.builder.ensure(Std { stage: run.builder.top_stage, target: run.target });
533-
}
534-
535-
/// Build JSON documentation for the standard library crates.
536-
///
537-
/// This is largely just a wrapper around `cargo doc`.
538-
fn run(self, builder: &Builder<'_>) {
539-
let stage = self.stage;
540-
let target = self.target;
541-
let out = builder.json_doc_out(target);
542-
t!(fs::create_dir_all(&out));
543-
let extra_args = [OsStr::new("--output-format"), OsStr::new("json")];
544-
doc_std(builder, DocumentationFormat::JSON, stage, target, &out, &extra_args, &[])
545-
}
546-
}
547-
548525
/// Name of the crates that are visible to consumers of the standard library.
549526
/// Documentation for internal crates is handled by the rustc step, so internal crates will show
550527
/// up there.
@@ -557,7 +534,7 @@ impl Step for JsonStd {
557534
const STD_PUBLIC_CRATES: [&str; 5] = ["core", "alloc", "std", "proc_macro", "test"];
558535

559536
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
560-
enum DocumentationFormat {
537+
pub enum DocumentationFormat {
561538
HTML,
562539
JSON,
563540
}

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)