Skip to content

Commit 765f153

Browse files
Rollup merge of #88666 - GuillaumeGomez:compiler-docs, r=Mark-Simulacrum
Improve build command for compiler docs It was rather complicated to document rustc crates. With this, you can directly run: ```console x.py doc compiler x.py doc compiler/rustc_hir_pretty ``` The second commit adds the handling of the `--open` flag. r? `@Mark-Simulacrum`
2 parents 1b78967 + 57ee7a6 commit 765f153

File tree

1 file changed

+53
-10
lines changed

1 file changed

+53
-10
lines changed

src/bootstrap/doc.rs

+53-10
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ impl Step for Rustc {
537537

538538
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
539539
let builder = run.builder;
540-
run.krate("rustc-main").default_condition(builder.config.docs)
540+
run.krate("rustc-main").path("compiler").default_condition(builder.config.docs)
541541
}
542542

543543
fn make_run(run: RunConfig<'_>) {
@@ -553,9 +553,24 @@ impl Step for Rustc {
553553
fn run(self, builder: &Builder<'_>) {
554554
let stage = self.stage;
555555
let target = self.target;
556+
let mut is_explicit_request = false;
556557
builder.info(&format!("Documenting stage{} compiler ({})", stage, target));
557558

558-
if !builder.config.compiler_docs {
559+
let paths = builder
560+
.paths
561+
.iter()
562+
.map(components_simplified)
563+
.filter_map(|path| {
564+
if path.get(0) == Some(&"compiler") {
565+
is_explicit_request = true;
566+
path.get(1).map(|p| p.to_owned())
567+
} else {
568+
None
569+
}
570+
})
571+
.collect::<Vec<_>>();
572+
573+
if !builder.config.compiler_docs && !is_explicit_request {
559574
builder.info("\tskipping - compiler/librustdoc docs disabled");
560575
return;
561576
}
@@ -604,26 +619,54 @@ impl Step for Rustc {
604619
cargo.rustdocflag("--extern-html-root-url");
605620
cargo.rustdocflag("ena=https://docs.rs/ena/latest/");
606621

607-
// Find dependencies for top level crates.
608622
let mut compiler_crates = HashSet::new();
609-
for root_crate in &["rustc_driver", "rustc_codegen_llvm", "rustc_codegen_ssa"] {
610-
compiler_crates.extend(
611-
builder
612-
.in_tree_crates(root_crate, Some(target))
613-
.into_iter()
614-
.map(|krate| krate.name),
615-
);
623+
624+
if paths.is_empty() {
625+
// Find dependencies for top level crates.
626+
for root_crate in &["rustc_driver", "rustc_codegen_llvm", "rustc_codegen_ssa"] {
627+
compiler_crates.extend(
628+
builder
629+
.in_tree_crates(root_crate, Some(target))
630+
.into_iter()
631+
.map(|krate| krate.name),
632+
);
633+
}
634+
} else {
635+
for root_crate in paths {
636+
if !builder.src.join("compiler").join(&root_crate).exists() {
637+
builder.info(&format!(
638+
"\tskipping - compiler/{} (unknown compiler crate)",
639+
root_crate
640+
));
641+
} else {
642+
compiler_crates.extend(
643+
builder
644+
.in_tree_crates(root_crate, Some(target))
645+
.into_iter()
646+
.map(|krate| krate.name),
647+
);
648+
}
649+
}
616650
}
617651

652+
let mut to_open = None;
618653
for krate in &compiler_crates {
619654
// Create all crate output directories first to make sure rustdoc uses
620655
// relative links.
621656
// FIXME: Cargo should probably do this itself.
622657
t!(fs::create_dir_all(out_dir.join(krate)));
623658
cargo.arg("-p").arg(krate);
659+
if to_open.is_none() {
660+
to_open = Some(krate);
661+
}
624662
}
625663

626664
builder.run(&mut cargo.into());
665+
// Let's open the first crate documentation page:
666+
if let Some(krate) = to_open {
667+
let index = out.join(krate).join("index.html");
668+
open(builder, &index);
669+
}
627670
}
628671
}
629672

0 commit comments

Comments
 (0)