Skip to content

Commit

Permalink
fix(doc): Collapse down Generated statuses without --verbose
Browse files Browse the repository at this point in the history
Fixes #13336
  • Loading branch information
epage committed Mar 7, 2024
1 parent 7ffa09a commit 7bc6044
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
34 changes: 32 additions & 2 deletions src/cargo/ops/cargo_doc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::core::compiler::{Compilation, CompileKind};
use crate::core::{Shell, Workspace};
use crate::core::{shell::Verbosity, Shell, Workspace};
use crate::ops;
use crate::util::context::{GlobalContext, PathAndArgs};
use crate::util::CargoResult;
Expand Down Expand Up @@ -77,7 +77,7 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
)?;
open_docs(&path, &mut shell, config_browser, ws.gctx())?;
}
} else {
} else if ws.gctx().shell().verbosity() == Verbosity::Verbose {
for name in &compilation.root_crate_names {
for kind in &options.compile_opts.build_config.requested_kinds {
let path =
Expand All @@ -92,6 +92,36 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
}
}
}
} else {
let mut output = compilation.root_crate_names.iter().flat_map(|name| {
options
.compile_opts
.build_config
.requested_kinds
.iter()
.map(|kind| path_by_output_format(&compilation, kind, name, &options.output_format))
.filter(|path| path.exists())
});
if let Some(first_path) = output.next() {
let remaining = output.count();
let remaining = match remaining {
0 => "".to_owned(),
1 => " and 1 other file".to_owned(),
n => format!(" and {n} other files"),
};

let mut shell = ws.gctx().shell();
let link = shell.err_file_hyperlink(&first_path);
shell.status(
"Generated",
format!(
"{}{}{}{remaining}",
link.open(),
first_path.display(),
link.close()
),
)?;
}
}

Ok(())
Expand Down
3 changes: 1 addition & 2 deletions tests/testsuite/collisions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,7 @@ the same path; see <https://github.com/rust-lang/cargo/issues/6313>.
[DOCUMENTING] foo-macro v1.0.0 [..]
[DOCUMENTING] abc v1.0.0 [..]
[FINISHED] [..]
[GENERATED] [CWD]/target/doc/abc/index.html
[GENERATED] [CWD]/target/doc/foo_macro/index.html
[GENERATED] [CWD]/target/doc/abc/index.html and 1 other file
")
.run();
}
9 changes: 3 additions & 6 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,7 @@ the same path; see <https://github.com/rust-lang/cargo/issues/6313>.
[DOCUMENTING] bar v0.1.0 ([ROOT]/foo/bar)
[DOCUMENTING] foo v0.1.0 ([ROOT]/foo/foo)
[FINISHED] [..]
[GENERATED] [CWD]/target/doc/foo_lib/index.html
[GENERATED] [CWD]/target/doc/foo_lib/index.html
[GENERATED] [CWD]/target/doc/foo_lib/index.html and 1 other file
",
)
.run();
Expand Down Expand Up @@ -658,8 +657,7 @@ fn doc_lib_bin_example_same_name_documents_examples_when_requested() {
[CHECKING] foo v0.0.1 ([CWD])
[DOCUMENTING] foo v0.0.1 ([CWD])
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
[GENERATED] [CWD]/target/doc/ex1/index.html
[GENERATED] [CWD]/target/doc/ex2/index.html
[GENERATED] [CWD]/target/doc/ex1/index.html and 1 other file
",
)
.run();
Expand Down Expand Up @@ -1189,8 +1187,7 @@ fn doc_all_workspace() {
.with_stderr_contains("[DOCUMENTING] bar v0.1.0 ([..])")
.with_stderr_contains("[CHECKING] bar v0.1.0 ([..])")
.with_stderr_contains("[DOCUMENTING] foo v0.1.0 ([..])")
.with_stderr_contains("[GENERATED] [CWD]/target/doc/bar/index.html")
.with_stderr_contains("[GENERATED] [CWD]/target/doc/foo/index.html")
.with_stderr_contains("[GENERATED] [CWD]/target/doc/bar/index.html and 1 other file")
.run();
}

Expand Down

0 comments on commit 7bc6044

Please sign in to comment.