Skip to content

Commit

Permalink
bootstrap: improve linking of tool docs
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <[email protected]>
  • Loading branch information
onur-ozkan committed Nov 4, 2023
1 parent 52933e0 commit 5188964
Showing 1 changed file with 34 additions and 29 deletions.
63 changes: 34 additions & 29 deletions src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,10 @@ macro_rules! tool_doc {
$should_run: literal,
$path: literal,
$(rustc_tool = $rustc_tool:literal, )?
$(in_tree = $in_tree:literal, )?
[$($extra_arg: literal),+ $(,)?]
$(,)?
) => {
$(in_tree = $in_tree:literal ,)?
$(is_library = $is_library:expr,)?
$(crates = $crates:expr)?
) => {
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct $tool {
target: TargetSelection,
Expand Down Expand Up @@ -828,8 +828,13 @@ macro_rules! tool_doc {
// Cargo uses a different directory for proc macros.
builder.stage_out(compiler, Mode::ToolRustc).join("doc"),
];

$(for krate in $crates {
let dir_name = krate.replace("-", "_");
t!(fs::create_dir_all(&out.join(dir_name)));
})?

for out_dir in out_dirs {
t!(fs::create_dir_all(&out_dir));
symlink_dir_force(&builder.config, &out, &out_dir);
}

Expand All @@ -849,9 +854,13 @@ macro_rules! tool_doc {
// Only include compiler crates, no dependencies of those, such as `libc`.
cargo.arg("--no-deps");

$(
cargo.arg($extra_arg);
)+
if false $(|| $is_library)? {
cargo.arg("--lib");
}

$(for krate in $crates {
cargo.arg("-p").arg(krate);
})?

cargo.rustdocflag("--document-private-items");
// Since we always pass --document-private-items, there's no need to warn about linking to private items.
Expand All @@ -863,60 +872,56 @@ macro_rules! tool_doc {

let _guard = builder.msg_doc(compiler, stringify!($tool).to_lowercase(), target);
builder.run(&mut cargo.into());

if !builder.config.dry_run() {
// Sanity check on linked doc directories
$(for krate in $crates {
let dir_name = krate.replace("-", "_");
// Making sure the directory exists and is not empty.
assert!(out.join(&*dir_name).read_dir().unwrap().next().is_some());
})?
}
}
}
}
}

tool_doc!(
Rustdoc,
"rustdoc-tool",
"src/tools/rustdoc",
["-p", "rustdoc", "-p", "rustdoc-json-types"]
);
tool_doc!(Rustdoc, "rustdoc-tool", "src/tools/rustdoc", crates = ["rustdoc", "rustdoc-json-types"]);
tool_doc!(
Rustfmt,
"rustfmt-nightly",
"src/tools/rustfmt",
["-p", "rustfmt-nightly", "-p", "rustfmt-config_proc_macro"],
crates = ["rustfmt-nightly", "rustfmt-config_proc_macro"]
);
tool_doc!(Clippy, "clippy", "src/tools/clippy", ["-p", "clippy_utils"]);
tool_doc!(Miri, "miri", "src/tools/miri", ["-p", "miri"]);
tool_doc!(Clippy, "clippy", "src/tools/clippy", crates = ["clippy_utils"]);
tool_doc!(Miri, "miri", "src/tools/miri", crates = ["miri"]);
tool_doc!(
Cargo,
"cargo",
"src/tools/cargo",
rustc_tool = false,
in_tree = false,
[
"-p",
crates = [
"cargo",
"-p",
"cargo-platform",
"-p",
"cargo-util",
"-p",
"crates-io",
"-p",
"cargo-test-macro",
"-p",
"cargo-test-support",
"-p",
"cargo-credential",
"-p",
"mdman",
// FIXME: this trips a license check in tidy.
// "-p",
// "resolver-tests",
]
);
tool_doc!(Tidy, "tidy", "src/tools/tidy", rustc_tool = false, ["-p", "tidy"]);
tool_doc!(Tidy, "tidy", "src/tools/tidy", rustc_tool = false, crates = ["tidy"]);
tool_doc!(
Bootstrap,
"bootstrap",
"src/bootstrap",
rustc_tool = false,
["--lib", "-p", "bootstrap"]
is_library = true,
crates = ["bootstrap"]
);

#[derive(Ord, PartialOrd, Debug, Copy, Clone, Hash, PartialEq, Eq)]
Expand Down

0 comments on commit 5188964

Please sign in to comment.