Skip to content

Commit 81f3ab6

Browse files
committed
Use a macro for documenting rustdoc
1 parent 0ce2112 commit 81f3ab6

File tree

2 files changed

+75
-67
lines changed

2 files changed

+75
-67
lines changed

src/bootstrap/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ impl<'a> Builder<'a> {
465465
doc::Std,
466466
doc::Rustc,
467467
doc::Rustdoc,
468+
// doc::Rustfmt,
468469
doc::ErrorIndex,
469470
doc::Nomicon,
470471
doc::Reference,

src/bootstrap/doc.rs

+74-67
Original file line numberDiff line numberDiff line change
@@ -593,84 +593,91 @@ impl Step for Rustc {
593593
}
594594
}
595595

596-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
597-
pub struct Rustdoc {
598-
stage: u32,
599-
target: TargetSelection,
600-
}
601-
602-
impl Step for Rustdoc {
603-
type Output = ();
604-
const DEFAULT: bool = true;
605-
const ONLY_HOSTS: bool = true;
606-
607-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
608-
run.krate("rustdoc-tool")
609-
}
610-
611-
fn make_run(run: RunConfig<'_>) {
612-
run.builder.ensure(Rustdoc { stage: run.builder.top_stage, target: run.target });
613-
}
614-
615-
/// Generates compiler documentation.
616-
///
617-
/// This will generate all documentation for compiler and dependencies.
618-
/// Compiler documentation is distributed separately, so we make sure
619-
/// we do not merge it with the other documentation from std, test and
620-
/// proc_macros. This is largely just a wrapper around `cargo doc`.
621-
fn run(self, builder: &Builder<'_>) {
622-
let stage = self.stage;
623-
let target = self.target;
624-
builder.info(&format!("Documenting stage{} rustdoc ({})", stage, target));
625-
626-
// This is the intended out directory for compiler documentation.
627-
let out = builder.compiler_doc_out(target);
628-
t!(fs::create_dir_all(&out));
596+
macro_rules! tool_doc {
597+
($tool: ident, $should_run: literal, $path: literal, [$($krate: literal),+ $(,)?]) => {
598+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
599+
pub struct $tool {
600+
stage: u32,
601+
target: TargetSelection,
602+
}
629603

630-
let compiler = builder.compiler(stage, builder.config.build);
604+
impl Step for $tool {
605+
type Output = ();
606+
const DEFAULT: bool = true;
607+
const ONLY_HOSTS: bool = true;
631608

632-
if !builder.config.compiler_docs {
633-
builder.info("\tskipping - compiler/librustdoc docs disabled");
634-
return;
635-
}
609+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
610+
run.krate($should_run)
611+
}
636612

637-
// Build rustc docs so that we generate relative links.
638-
builder.ensure(Rustc { stage, target });
613+
fn make_run(run: RunConfig<'_>) {
614+
run.builder.ensure($tool { stage: run.builder.top_stage, target: run.target });
615+
}
639616

640-
// Build rustdoc.
641-
builder.ensure(tool::Rustdoc { compiler });
617+
/// Generates compiler documentation.
618+
///
619+
/// This will generate all documentation for compiler and dependencies.
620+
/// Compiler documentation is distributed separately, so we make sure
621+
/// we do not merge it with the other documentation from std, test and
622+
/// proc_macros. This is largely just a wrapper around `cargo doc`.
623+
fn run(self, builder: &Builder<'_>) {
624+
let stage = self.stage;
625+
let target = self.target;
626+
builder.info(&format!("Documenting stage{} {} ({})", stage, stringify!($tool).to_lowercase(), target));
642627

643-
// Symlink compiler docs to the output directory of rustdoc documentation.
644-
let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target.triple).join("doc");
645-
t!(fs::create_dir_all(&out_dir));
646-
t!(symlink_dir_force(&builder.config, &out, &out_dir));
628+
// This is the intended out directory for compiler documentation.
629+
let out = builder.compiler_doc_out(target);
630+
t!(fs::create_dir_all(&out));
647631

648-
// Build cargo command.
649-
let mut cargo = prepare_tool_cargo(
650-
builder,
651-
compiler,
652-
Mode::ToolRustc,
653-
target,
654-
"doc",
655-
"src/tools/rustdoc",
656-
SourceType::InTree,
657-
&[],
658-
);
632+
let compiler = builder.compiler(stage, builder.config.build);
659633

660-
cargo.arg("-Zskip-rustdoc-fingerprint");
661-
// Only include compiler crates, no dependencies of those, such as `libc`.
662-
cargo.arg("--no-deps");
663-
cargo.arg("-p").arg("rustdoc");
664-
cargo.arg("-p").arg("rustdoc-json-types");
634+
if !builder.config.compiler_docs {
635+
builder.info("\tskipping - compiler/tool docs disabled");
636+
return;
637+
}
665638

666-
cargo.rustdocflag("--document-private-items");
667-
cargo.rustdocflag("--enable-index-page");
668-
cargo.rustdocflag("--show-type-layout");
669-
cargo.rustdocflag("-Zunstable-options");
670-
builder.run(&mut cargo.into());
639+
// Build rustc docs so that we generate relative links.
640+
builder.ensure(Rustc { stage, target });
641+
642+
// Build the tool.
643+
builder.ensure(tool::$tool { compiler });
644+
645+
// Symlink compiler docs to the output directory of rustdoc documentation.
646+
let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target.triple).join("doc");
647+
t!(fs::create_dir_all(&out_dir));
648+
t!(symlink_dir_force(&builder.config, &out, &out_dir));
649+
650+
// Build cargo command.
651+
let mut cargo = prepare_tool_cargo(
652+
builder,
653+
compiler,
654+
Mode::ToolRustc,
655+
target,
656+
"doc",
657+
$path,
658+
SourceType::InTree,
659+
&[],
660+
);
661+
662+
cargo.arg("-Zskip-rustdoc-fingerprint");
663+
// Only include compiler crates, no dependencies of those, such as `libc`.
664+
cargo.arg("--no-deps");
665+
$(
666+
cargo.arg("-p").arg($krate);
667+
)+
668+
669+
cargo.rustdocflag("--document-private-items");
670+
cargo.rustdocflag("--enable-index-page");
671+
cargo.rustdocflag("--show-type-layout");
672+
cargo.rustdocflag("-Zunstable-options");
673+
builder.run(&mut cargo.into());
674+
}
675+
}
671676
}
672677
}
673678

679+
tool_doc!(Rustdoc, "rustdoc-tool", "src/tools/rustdoc", ["rustdoc", "rustdoc-json-types"]);
680+
674681
#[derive(Ord, PartialOrd, Debug, Copy, Clone, Hash, PartialEq, Eq)]
675682
pub struct ErrorIndex {
676683
pub target: TargetSelection,

0 commit comments

Comments
 (0)