Skip to content

Commit 59b6d22

Browse files
committed
fix(doc): Collapse down Generated statuses without --verbose
Fixes #13336
1 parent 17b606b commit 59b6d22

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
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/doc.rs

Lines changed: 3 additions & 6 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();
@@ -1189,8 +1187,7 @@ fn doc_all_workspace() {
11891187
.with_stderr_contains("[DOCUMENTING] bar v0.1.0 ([..])")
11901188
.with_stderr_contains("[CHECKING] bar v0.1.0 ([..])")
11911189
.with_stderr_contains("[DOCUMENTING] foo v0.1.0 ([..])")
1192-
.with_stderr_contains("[GENERATED] [CWD]/target/doc/bar/index.html")
1193-
.with_stderr_contains("[GENERATED] [CWD]/target/doc/foo/index.html")
1190+
.with_stderr_contains("[GENERATED] [CWD]/target/doc/bar/index.html and 1 other file")
11941191
.run();
11951192
}
11961193

0 commit comments

Comments
 (0)