]> git.lizzy.rs Git - rust.git/blobdiff - src/bootstrap/doc.rs
Auto merge of #107443 - cjgillot:generator-less-query, r=compiler-errors
[rust.git] / src / bootstrap / doc.rs
index 2c6fd1e1d4dd4e19edd1a10c3f9b09bd9afec634..7f8aa2573ddb316b2549c65267792a4a91280102 100644 (file)
@@ -12,6 +12,7 @@
 use std::io;
 use std::path::{Path, PathBuf};
 
+use crate::builder::crate_description;
 use crate::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
 use crate::cache::{Interned, INTERNER};
 use crate::compile;
@@ -506,7 +507,11 @@ fn run(self, builder: &Builder<'_>) {
         // Look for library/std, library/core etc in the `x.py doc` arguments and
         // open the corresponding rendered docs.
         for requested_crate in requested_crates {
-            if STD_PUBLIC_CRATES.iter().any(|k| *k == requested_crate.as_str()) {
+            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);
             }
@@ -554,7 +559,8 @@ fn doc_std(
     requested_crates: &[String],
 ) {
     builder.info(&format!(
-        "Documenting stage{} std ({}) in {} format",
+        "Documenting{} stage{} library ({}) in {} format",
+        crate_description(requested_crates),
         stage,
         target,
         format.as_str()
@@ -591,6 +597,9 @@ fn doc_std(
             .arg("--resource-suffix")
             .arg(&builder.version)
             .args(extra_args);
+        if builder.config.library_docs_private_items {
+            cargo.arg("--document-private-items").arg("--document-hidden-items");
+        }
         builder.run(&mut cargo.into());
     };
 
@@ -729,7 +738,7 @@ fn run(self, builder: &Builder<'_>) {
 }
 
 macro_rules! tool_doc {
-    ($tool: ident, $should_run: literal, $path: literal, [$($krate: literal),+ $(,)?] $(,)?) => {
+    ($tool: ident, $should_run: literal, $path: literal, $(rustc_tool = $rustc_tool:literal, )? $(in_tree = $in_tree:literal, )? [$($krate: literal),+ $(,)?] $(,)?) => {
         #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
         pub struct $tool {
             target: TargetSelection,
@@ -763,13 +772,24 @@ fn run(self, builder: &Builder<'_>) {
                 let out = builder.compiler_doc_out(target);
                 t!(fs::create_dir_all(&out));
 
-                // Build rustc docs so that we generate relative links.
-                builder.ensure(Rustc { stage, target });
-                // Rustdoc needs the rustc sysroot available to build.
-                // FIXME: is there a way to only ensure `check::Rustc` here? Last time I tried it failed
-                // with strange errors, but only on a full bors test ...
                 let compiler = builder.compiler(stage, builder.config.build);
-                builder.ensure(compile::Rustc::new(compiler, target));
+                builder.ensure(compile::Std::new(compiler, target));
+
+                if true $(&& $rustc_tool)? {
+                    // Build rustc docs so that we generate relative links.
+                    builder.ensure(Rustc { stage, target });
+
+                    // Rustdoc needs the rustc sysroot available to build.
+                    // FIXME: is there a way to only ensure `check::Rustc` here? Last time I tried it failed
+                    // with strange errors, but only on a full bors test ...
+                    builder.ensure(compile::Rustc::new(compiler, target));
+                }
+
+                let source_type = if true $(&& $in_tree)? {
+                    SourceType::InTree
+                } else {
+                    SourceType::Submodule
+                };
 
                 builder.info(
                     &format!(
@@ -781,9 +801,15 @@ fn run(self, builder: &Builder<'_>) {
                 );
 
                 // Symlink compiler docs to the output directory of rustdoc documentation.
-                let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target.triple).join("doc");
-                t!(fs::create_dir_all(&out_dir));
-                t!(symlink_dir_force(&builder.config, &out, &out_dir));
+                let out_dirs = [
+                    builder.stage_out(compiler, Mode::ToolRustc).join(target.triple).join("doc"),
+                    // Cargo uses a different directory for proc macros.
+                    builder.stage_out(compiler, Mode::ToolRustc).join("doc"),
+                ];
+                for out_dir in out_dirs {
+                    t!(fs::create_dir_all(&out_dir));
+                    t!(symlink_dir_force(&builder.config, &out, &out_dir));
+                }
 
                 // Build cargo command.
                 let mut cargo = prepare_tool_cargo(
@@ -793,7 +819,7 @@ fn run(self, builder: &Builder<'_>) {
                     target,
                     "doc",
                     $path,
-                    SourceType::InTree,
+                    source_type,
                     &[],
                 );
 
@@ -824,6 +850,30 @@ fn run(self, builder: &Builder<'_>) {
 );
 tool_doc!(Clippy, "clippy", "src/tools/clippy", ["clippy_utils"]);
 tool_doc!(Miri, "miri", "src/tools/miri", ["miri"]);
+tool_doc!(
+    Cargo,
+    "cargo",
+    "src/tools/cargo",
+    rustc_tool = false,
+    in_tree = false,
+    [
+        "cargo",
+        "cargo-platform",
+        "cargo-util",
+        "crates-io",
+        "cargo-test-macro",
+        "cargo-test-support",
+        "cargo-credential",
+        "cargo-credential-1password",
+        "mdman",
+        // FIXME: this trips a license check in tidy.
+        // "resolver-tests",
+        // FIXME: we should probably document these, but they're different per-platform so we can't use `tool_doc`.
+        // "cargo-credential-gnome-secret",
+        // "cargo-credential-macos-keychain",
+        // "cargo-credential-wincred",
+    ]
+);
 
 #[derive(Ord, PartialOrd, Debug, Copy, Clone, Hash, PartialEq, Eq)]
 pub struct ErrorIndex {