summaryrefslogtreecommitdiffstats
path: root/src/bootstrap/doc.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /src/bootstrap/doc.rs
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/bootstrap/doc.rs')
-rw-r--r--src/bootstrap/doc.rs170
1 files changed, 85 insertions, 85 deletions
diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs
index 5ebfe0995..505f06ed1 100644
--- a/src/bootstrap/doc.rs
+++ b/src/bootstrap/doc.rs
@@ -11,13 +11,12 @@ use std::fs;
use std::path::{Path, PathBuf};
use crate::builder::crate_description;
-use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
+use crate::builder::{Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
use crate::cache::{Interned, INTERNER};
use crate::compile;
-use crate::compile::make_run_crates;
use crate::config::{Config, TargetSelection};
use crate::tool::{self, prepare_tool_cargo, SourceType, Tool};
-use crate::util::{symlink_dir, t, up_to_date};
+use crate::util::{dir_is_empty, symlink_dir, t, up_to_date};
use crate::Mode;
macro_rules! submodule_helper {
@@ -148,7 +147,7 @@ impl<P: Step> Step for RustbookSrc<P> {
if !builder.config.dry_run() && !(up_to_date(&src, &index) || up_to_date(&rustbook, &index))
{
- builder.info(&format!("Rustbook ({}) - {}", target, name));
+ builder.info(&format!("Rustbook ({target}) - {name}"));
let _ = fs::remove_dir_all(&out);
builder.run(rustbook_cmd.arg("build").arg(&src).arg("-d").arg(out));
@@ -198,11 +197,21 @@ impl Step for TheBook {
let compiler = self.compiler;
let target = self.target;
+ let absolute_path = builder.src.join(&relative_path);
+ let redirect_path = absolute_path.join("redirects");
+ if !absolute_path.exists()
+ || !redirect_path.exists()
+ || dir_is_empty(&absolute_path)
+ || dir_is_empty(&redirect_path)
+ {
+ eprintln!("Please checkout submodule: {}", relative_path.display());
+ crate::exit!(1);
+ }
// build book
builder.ensure(RustbookSrc {
target,
name: INTERNER.intern_str("book"),
- src: INTERNER.intern_path(builder.src.join(&relative_path)),
+ src: INTERNER.intern_path(absolute_path.clone()),
parent: Some(self),
});
@@ -210,8 +219,8 @@ impl Step for TheBook {
for edition in &["first-edition", "second-edition", "2018-edition"] {
builder.ensure(RustbookSrc {
target,
- name: INTERNER.intern_string(format!("book/{}", edition)),
- src: INTERNER.intern_path(builder.src.join(&relative_path).join(edition)),
+ name: INTERNER.intern_string(format!("book/{edition}")),
+ src: INTERNER.intern_path(absolute_path.join(edition)),
// There should only be one book that is marked as the parent for each target, so
// treat the other editions as not having a parent.
parent: Option::<Self>::None,
@@ -221,9 +230,12 @@ impl Step for TheBook {
// build the version info page and CSS
let shared_assets = builder.ensure(SharedAssets { target });
+ // build the command first so we don't nest GHA groups
+ builder.rustdoc_cmd(compiler);
+
// build the redirect pages
- builder.msg_doc(compiler, "book redirect pages", target);
- for file in t!(fs::read_dir(builder.src.join(&relative_path).join("redirects"))) {
+ let _guard = builder.msg_doc(compiler, "book redirect pages", target);
+ for file in t!(fs::read_dir(redirect_path)) {
let file = t!(file);
let path = file.path();
let path = path.to_str().unwrap();
@@ -306,7 +318,7 @@ impl Step for Standalone {
fn run(self, builder: &Builder<'_>) {
let target = self.target;
let compiler = self.compiler;
- builder.msg_doc(compiler, "standalone", target);
+ let _guard = builder.msg_doc(compiler, "standalone", target);
let out = builder.doc_out(target);
t!(fs::create_dir_all(&out));
@@ -424,8 +436,18 @@ pub struct Std {
}
impl Std {
- pub(crate) fn new(stage: u32, target: TargetSelection, format: DocumentationFormat) -> Self {
- Std { stage, target, format, crates: INTERNER.intern_list(vec![]) }
+ pub(crate) fn new(
+ stage: u32,
+ target: TargetSelection,
+ builder: &Builder<'_>,
+ format: DocumentationFormat,
+ ) -> Self {
+ let crates = builder
+ .in_tree_crates("sysroot", Some(target))
+ .into_iter()
+ .map(|krate| krate.name.to_string())
+ .collect();
+ Std { stage, target, format, crates: INTERNER.intern_list(crates) }
}
}
@@ -447,7 +469,7 @@ impl Step for Std {
} else {
DocumentationFormat::HTML
},
- crates: make_run_crates(&run, "library"),
+ crates: run.make_run_crates(Alias::Library),
});
}
@@ -455,7 +477,7 @@ impl Step for Std {
///
/// This will generate all documentation for the standard library and its
/// dependencies. This is largely just a wrapper around `cargo doc`.
- fn run(mut self, builder: &Builder<'_>) {
+ fn run(self, builder: &Builder<'_>) {
let stage = self.stage;
let target = self.target;
let out = match self.format {
@@ -493,20 +515,17 @@ impl Step for Std {
return;
}
- // Look for library/std, library/core etc in the `x.py doc` arguments and
- // open the corresponding rendered docs.
- if self.crates.is_empty() {
- self.crates = INTERNER.intern_list(vec!["library".to_owned()]);
- };
-
- for requested_crate in &*self.crates {
- if requested_crate == "library" {
- // For `x.py doc library --open`, open `std` by default.
- let index = out.join("std").join("index.html");
- builder.open_in_browser(index);
- } else if STD_PUBLIC_CRATES.iter().any(|&k| k == requested_crate) {
- let index = out.join(requested_crate).join("index.html");
- builder.open_in_browser(index);
+ if builder.paths.iter().any(|path| path.ends_with("library")) {
+ // For `x.py doc library --open`, open `std` by default.
+ let index = out.join("std").join("index.html");
+ builder.open_in_browser(index);
+ } else {
+ for requested_crate in &*self.crates {
+ if STD_PUBLIC_CRATES.iter().any(|&k| k == requested_crate) {
+ let index = out.join(requested_crate).join("index.html");
+ builder.open_in_browser(index);
+ break;
+ }
}
}
}
@@ -539,9 +558,6 @@ impl DocumentationFormat {
}
/// Build the documentation for public standard library crates.
-///
-/// `requested_crates` can be used to build only a subset of the crates. If empty, all crates will
-/// be built.
fn doc_std(
builder: &Builder<'_>,
format: DocumentationFormat,
@@ -554,16 +570,12 @@ fn doc_std(
if builder.no_std(target) == Some(true) {
panic!(
"building std documentation for no_std target {target} is not supported\n\
- Set `docs = false` in the config to disable documentation, or pass `--exclude doc::library`."
+ Set `docs = false` in the config to disable documentation, or pass `--skip library`."
);
}
let compiler = builder.compiler(stage, builder.config.build);
- let description =
- format!("library{} in {} format", crate_description(&requested_crates), format.as_str());
- let _guard = builder.msg_doc(compiler, &description, target);
-
let target_doc_dir_name = if format == DocumentationFormat::JSON { "json-doc" } else { "doc" };
let target_dir =
builder.stage_out(compiler, Mode::Std).join(target.triple).join(target_doc_dir_name);
@@ -592,22 +604,18 @@ fn doc_std(
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 {
+ for krate in requested_crates {
+ if krate == "sysroot" {
+ // The sysroot crate is an implementation detail, don't include it in public docs.
+ continue;
+ }
cargo.arg("-p").arg(krate);
}
+ let description =
+ format!("library{} in {} format", crate_description(&requested_crates), format.as_str());
+ let _guard = builder.msg_doc(compiler, &description, target);
+
builder.run(&mut cargo.into());
builder.cp_r(&out_dir, &out);
}
@@ -621,20 +629,10 @@ pub struct Rustc {
impl Rustc {
pub(crate) fn new(stage: u32, target: TargetSelection, builder: &Builder<'_>) -> Self {
- // Find dependencies for top level crates.
- let root_crates = vec![
- INTERNER.intern_str("rustc_driver"),
- INTERNER.intern_str("rustc_codegen_llvm"),
- INTERNER.intern_str("rustc_codegen_ssa"),
- ];
- let crates: Vec<_> = root_crates
- .iter()
- .flat_map(|krate| {
- builder
- .in_tree_crates(krate, Some(target))
- .into_iter()
- .map(|krate| krate.name.to_string())
- })
+ let crates = builder
+ .in_tree_crates("rustc-main", Some(target))
+ .into_iter()
+ .map(|krate| krate.name.to_string())
.collect();
Self { stage, target, crates: INTERNER.intern_list(crates) }
}
@@ -656,7 +654,7 @@ impl Step for Rustc {
run.builder.ensure(Rustc {
stage: run.builder.top_stage,
target: run.target,
- crates: make_run_crates(&run, "compiler"),
+ crates: run.make_run_crates(Alias::Compiler),
});
}
@@ -666,7 +664,7 @@ impl Step for Rustc {
/// Compiler documentation is distributed separately, so we make sure
/// we do not merge it with the other documentation from std, test and
/// proc_macros. This is largely just a wrapper around `cargo doc`.
- fn run(mut self, builder: &Builder<'_>) {
+ fn run(self, builder: &Builder<'_>) {
let stage = self.stage;
let target = self.target;
@@ -726,24 +724,26 @@ impl Step for Rustc {
let mut to_open = None;
- if self.crates.is_empty() {
- self.crates = INTERNER.intern_list(vec!["rustc_driver".to_owned()]);
- };
-
for krate in &*self.crates {
// Create all crate output directories first to make sure rustdoc uses
// relative links.
// FIXME: Cargo should probably do this itself.
- t!(fs::create_dir_all(out_dir.join(krate)));
+ let dir_name = krate.replace("-", "_");
+ t!(fs::create_dir_all(out_dir.join(&*dir_name)));
cargo.arg("-p").arg(krate);
if to_open.is_none() {
- to_open = Some(krate);
+ to_open = Some(dir_name);
}
}
builder.run(&mut cargo.into());
- // Let's open the first crate documentation page:
- if let Some(krate) = to_open {
+
+ if builder.paths.iter().any(|path| path.ends_with("compiler")) {
+ // For `x.py doc compiler --open`, open `rustc_middle` by default.
+ let index = out.join("rustc_middle").join("index.html");
+ builder.open_in_browser(index);
+ } else if let Some(krate) = to_open {
+ // Let's open the first crate documentation page:
let index = out.join(krate).join("index.html");
builder.open_in_browser(index);
}
@@ -812,8 +812,6 @@ macro_rules! tool_doc {
SourceType::Submodule
};
- builder.msg_doc(compiler, stringify!($tool).to_lowercase(), target);
-
// Symlink compiler docs to the output directory of rustdoc documentation.
let out_dirs = [
builder.stage_out(compiler, Mode::ToolRustc).join(target.triple).join("doc"),
@@ -852,6 +850,8 @@ macro_rules! tool_doc {
cargo.rustdocflag("--show-type-layout");
cargo.rustdocflag("--generate-link-to-definition");
cargo.rustdocflag("-Zunstable-options");
+
+ let _guard = builder.msg_doc(compiler, stringify!($tool).to_lowercase(), target);
builder.run(&mut cargo.into());
}
}
@@ -894,19 +894,10 @@ tool_doc!(
"-p",
"cargo-credential",
"-p",
- "cargo-credential-1password",
- "-p",
"mdman",
// FIXME: this trips a license check in tidy.
// "-p",
// "resolver-tests",
- // FIXME: we should probably document these, but they're different per-platform so we can't use `tool_doc`.
- // "-p",
- // "cargo-credential-gnome-secret",
- // "-p",
- // "cargo-credential-macos-keychain",
- // "-p",
- // "cargo-credential-wincred",
]
);
tool_doc!(Tidy, "tidy", "src/tools/tidy", rustc_tool = false, ["-p", "tidy"]);
@@ -975,7 +966,7 @@ impl Step for UnstableBookGen {
fn run(self, builder: &Builder<'_>) {
let target = self.target;
- builder.info(&format!("Generating unstable book md files ({})", target));
+ builder.info(&format!("Generating unstable book md files ({target})"));
let out = builder.md_doc_out(target).join("unstable-book");
builder.create_dir(&out);
builder.remove_dir(&out);
@@ -1073,7 +1064,16 @@ impl Step for RustcBook {
// config.toml), then this needs to explicitly update the dylib search
// path.
builder.add_rustc_lib_path(self.compiler, &mut cmd);
+ let doc_generator_guard = builder.msg(
+ Kind::Run,
+ self.compiler.stage,
+ "lint-docs",
+ self.compiler.host,
+ self.target,
+ );
builder.run(&mut cmd);
+ drop(doc_generator_guard);
+
// Run rustbook/mdbook to generate the HTML pages.
builder.ensure(RustbookSrc {
target: self.target,