Skip to content

Commit 6b27055

Browse files
committed
Auto merge of #13557 - epage:doc, r=weihanglo
fix(doc): Collapse down Generated statuses without --verbose ### What does this PR try to resolve? This is trying to balance - Overwhelming the user with a lot of paths - Clarity to the user that the one path is representative of the rest clap before: ``` Finished dev [unoptimized + debuginfo] target(s) in 3.81s Generated /home/epage/src/personal/clap/target/doc/clap/index.html Generated /home/epage/src/personal/clap/target/doc/stdio_fixture/index.html Generated /home/epage/src/personal/clap/target/doc/clap_bench/index.html Generated /home/epage/src/personal/clap/target/doc/clap_builder/index.html Generated /home/epage/src/personal/clap/target/doc/clap_complete/index.html Generated /home/epage/src/personal/clap/target/doc/clap_complete_fig/index.html Generated /home/epage/src/personal/clap/target/doc/clap_complete_nushell/index.html Generated /home/epage/src/personal/clap/target/doc/clap_derive/index.html Generated /home/epage/src/personal/clap/target/doc/clap_lex/index.html Generated /home/epage/src/personal/clap/target/doc/clap_mangen/index.html ``` clap after: ``` Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.44s Generated /home/epage/src/personal/clap/target/doc/clap/index.html and 9 other files ``` Fixes #13336 ### How should we test and review this PR? Tests were updated in earlier commits to help show the behavior change ### Additional information
2 parents ce3d32a + 7bc6044 commit 6b27055

File tree

3 files changed

+71
-11
lines changed

3 files changed

+71
-11
lines changed

src/cargo/ops/cargo_doc.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::core::compiler::{Compilation, CompileKind};
2-
use crate::core::{Shell, Workspace};
2+
use crate::core::{shell::Verbosity, Shell, Workspace};
33
use crate::ops;
44
use crate::util::context::{GlobalContext, PathAndArgs};
55
use crate::util::CargoResult;
@@ -77,7 +77,7 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
7777
)?;
7878
open_docs(&path, &mut shell, config_browser, ws.gctx())?;
7979
}
80-
} else {
80+
} else if ws.gctx().shell().verbosity() == Verbosity::Verbose {
8181
for name in &compilation.root_crate_names {
8282
for kind in &options.compile_opts.build_config.requested_kinds {
8383
let path =
@@ -92,6 +92,36 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
9292
}
9393
}
9494
}
95+
} else {
96+
let mut output = compilation.root_crate_names.iter().flat_map(|name| {
97+
options
98+
.compile_opts
99+
.build_config
100+
.requested_kinds
101+
.iter()
102+
.map(|kind| path_by_output_format(&compilation, kind, name, &options.output_format))
103+
.filter(|path| path.exists())
104+
});
105+
if let Some(first_path) = output.next() {
106+
let remaining = output.count();
107+
let remaining = match remaining {
108+
0 => "".to_owned(),
109+
1 => " and 1 other file".to_owned(),
110+
n => format!(" and {n} other files"),
111+
};
112+
113+
let mut shell = ws.gctx().shell();
114+
let link = shell.err_file_hyperlink(&first_path);
115+
shell.status(
116+
"Generated",
117+
format!(
118+
"{}{}{}{remaining}",
119+
link.open(),
120+
first_path.display(),
121+
link.close()
122+
),
123+
)?;
124+
}
95125
}
96126

97127
Ok(())

tests/testsuite/collisions.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,7 @@ the same path; see <https://github.com/rust-lang/cargo/issues/6313>.
561561
[DOCUMENTING] foo-macro v1.0.0 [..]
562562
[DOCUMENTING] abc v1.0.0 [..]
563563
[FINISHED] [..]
564-
[GENERATED] [CWD]/target/doc/abc/index.html
565-
[GENERATED] [CWD]/target/doc/foo_macro/index.html
564+
[GENERATED] [CWD]/target/doc/abc/index.html and 1 other file
566565
")
567566
.run();
568567
}

tests/testsuite/doc.rs

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ the same path; see <https://github.com/rust-lang/cargo/issues/6313>.
309309
[DOCUMENTING] bar v0.1.0 ([ROOT]/foo/bar)
310310
[DOCUMENTING] foo v0.1.0 ([ROOT]/foo/foo)
311311
[FINISHED] [..]
312-
[GENERATED] [CWD]/target/doc/foo_lib/index.html
313-
[GENERATED] [CWD]/target/doc/foo_lib/index.html
312+
[GENERATED] [CWD]/target/doc/foo_lib/index.html and 1 other file
314313
",
315314
)
316315
.run();
@@ -658,8 +657,7 @@ fn doc_lib_bin_example_same_name_documents_examples_when_requested() {
658657
[CHECKING] foo v0.0.1 ([CWD])
659658
[DOCUMENTING] foo v0.0.1 ([CWD])
660659
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
661-
[GENERATED] [CWD]/target/doc/ex1/index.html
662-
[GENERATED] [CWD]/target/doc/ex2/index.html
660+
[GENERATED] [CWD]/target/doc/ex1/index.html and 1 other file
663661
",
664662
)
665663
.run();
@@ -1186,9 +1184,42 @@ fn doc_all_workspace() {
11861184

11871185
// The order in which bar is compiled or documented is not deterministic
11881186
p.cargo("doc --workspace")
1189-
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
1190-
.with_stderr_contains("[..] Checking bar v0.1.0 ([..])")
1191-
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
1187+
.with_stderr_contains("[DOCUMENTING] bar v0.1.0 ([..])")
1188+
.with_stderr_contains("[CHECKING] bar v0.1.0 ([..])")
1189+
.with_stderr_contains("[DOCUMENTING] foo v0.1.0 ([..])")
1190+
.with_stderr_contains("[GENERATED] [CWD]/target/doc/bar/index.html and 1 other file")
1191+
.run();
1192+
}
1193+
1194+
#[cargo_test]
1195+
fn doc_all_workspace_verbose() {
1196+
let p = project()
1197+
.file(
1198+
"Cargo.toml",
1199+
r#"
1200+
[package]
1201+
name = "foo"
1202+
version = "0.1.0"
1203+
edition = "2015"
1204+
1205+
[dependencies]
1206+
bar = { path = "bar" }
1207+
1208+
[workspace]
1209+
"#,
1210+
)
1211+
.file("src/main.rs", "fn main() {}")
1212+
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
1213+
.file("bar/src/lib.rs", "pub fn bar() {}")
1214+
.build();
1215+
1216+
// The order in which bar is compiled or documented is not deterministic
1217+
p.cargo("doc --workspace -v")
1218+
.with_stderr_contains("[DOCUMENTING] bar v0.1.0 ([..])")
1219+
.with_stderr_contains("[CHECKING] bar v0.1.0 ([..])")
1220+
.with_stderr_contains("[DOCUMENTING] foo v0.1.0 ([..])")
1221+
.with_stderr_contains("[GENERATED] [CWD]/target/doc/bar/index.html")
1222+
.with_stderr_contains("[GENERATED] [CWD]/target/doc/foo/index.html")
11921223
.run();
11931224
}
11941225

0 commit comments

Comments
 (0)