Fix bugs in doc refactor

- Switch from `cargo rustdoc` to `cargo doc`

  This allows passing `-p` to multiple packages.

- Remove `OsStr` support

  It doesn't work with RUSTDOCFLAGS, and we don't support non-utf8 paths
  anyway.

- Pass `-p std` for each crate in the standard library

  By default cargo only documents the top-level crate, which is
  `sysroot` and has no docs.
This commit is contained in:
jyn 2023-05-25 15:14:56 -05:00
parent 71770d5e6e
commit c28ee603c8

View File

@ -7,7 +7,6 @@
//! Everything here is basically just a shim around calling either `rustbook` or //! Everything here is basically just a shim around calling either `rustbook` or
//! `rustdoc`. //! `rustdoc`.
use std::ffi::OsStr;
use std::fs; use std::fs;
use std::io; use std::io;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -471,20 +470,21 @@ impl Step for Std {
builder.ensure(SharedAssets { target: self.target }); builder.ensure(SharedAssets { target: self.target });
} }
let index_page = builder.src.join("src/doc/index.md").into_os_string(); let index_page = builder
.src
.join("src/doc/index.md")
.into_os_string()
.into_string()
.expect("non-utf8 paths are unsupported");
let mut extra_args = match self.format { let mut extra_args = match self.format {
DocumentationFormat::HTML => vec![ DocumentationFormat::HTML => {
OsStr::new("--markdown-css"), vec!["--markdown-css", "rust.css", "--markdown-no-toc", "--index-page", &index_page]
OsStr::new("rust.css"), }
OsStr::new("--markdown-no-toc"), DocumentationFormat::JSON => vec!["--output-format", "json"],
OsStr::new("--index-page"),
&index_page,
],
DocumentationFormat::JSON => vec![OsStr::new("--output-format"), OsStr::new("json")],
}; };
if !builder.config.docs_minification { if !builder.config.docs_minification {
extra_args.push(OsStr::new("--disable-minification")); extra_args.push("--disable-minification");
} }
doc_std(builder, self.format, stage, target, &out, &extra_args, &self.crates); doc_std(builder, self.format, stage, target, &out, &extra_args, &self.crates);
@ -549,7 +549,7 @@ fn doc_std(
stage: u32, stage: u32,
target: TargetSelection, target: TargetSelection,
out: &Path, out: &Path,
extra_args: &[&OsStr], extra_args: &[&str],
requested_crates: &[String], requested_crates: &[String],
) { ) {
if builder.no_std(target) == Some(true) { if builder.no_std(target) == Some(true) {
@ -574,24 +574,39 @@ fn doc_std(
// as a function parameter. // as a function parameter.
let out_dir = target_dir.join(target.triple).join("doc"); let out_dir = target_dir.join(target.triple).join("doc");
let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "rustdoc"); let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "doc");
compile::std_cargo(builder, target, compiler.stage, &mut cargo); compile::std_cargo(builder, target, compiler.stage, &mut cargo);
cargo.arg("--target-dir").arg(&*target_dir.to_string_lossy()).arg("-Zskip-rustdoc-fingerprint"); cargo
.arg("--no-deps")
for krate in requested_crates { .arg("--target-dir")
cargo.arg("-p").arg(krate); .arg(&*target_dir.to_string_lossy())
.arg("-Zskip-rustdoc-fingerprint")
.rustdocflag("-Z")
.rustdocflag("unstable-options")
.rustdocflag("--resource-suffix")
.rustdocflag(&builder.version);
for arg in extra_args {
cargo.rustdocflag(arg);
} }
cargo
.arg("--")
.arg("-Z")
.arg("unstable-options")
.arg("--resource-suffix")
.arg(&builder.version)
.args(extra_args);
if builder.config.library_docs_private_items { if builder.config.library_docs_private_items {
cargo.arg("--document-private-items").arg("--document-hidden-items"); cargo.rustdocflag("--document-private-items").rustdocflag("--document-hidden-items");
}
// HACK: because we use `--manifest-path library/sysroot/Cargo.toml`, cargo thinks we only want to document that specific crate, not its dependencies.
// Override its default.
let built_crates = if requested_crates.is_empty() {
builder
.in_tree_crates("sysroot", None)
.into_iter()
.map(|krate| krate.name.to_string())
.collect()
} else {
requested_crates.to_vec()
};
for krate in built_crates {
cargo.arg("-p").arg(krate);
} }
builder.run(&mut cargo.into()); builder.run(&mut cargo.into());