Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(doc): Collapse down Generated statuses without --verbose #13557

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions src/cargo/ops/cargo_doc.rs
Copy link
Member

@weihanglo weihanglo Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same behavior for cargo test --no-run?
I believe people are doing evil things like parsing the executable paths…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of problems with cargo test and I'd like to look at all of them holistically

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(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please implement the fancy alternate form for links 😁.

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();
}
45 changes: 38 additions & 7 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 @@ -1186,9 +1184,42 @@ fn doc_all_workspace() {

// The order in which bar is compiled or documented is not deterministic
p.cargo("doc --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("[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 and 1 other file")
.run();
}

#[cargo_test]
fn doc_all_workspace_verbose() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
edition = "2015"

[dependencies]
bar = { path = "bar" }

[workspace]
"#,
)
.file("src/main.rs", "fn main() {}")
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
.file("bar/src/lib.rs", "pub fn bar() {}")
.build();

// The order in which bar is compiled or documented is not deterministic
p.cargo("doc --workspace -v")
.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")
.run();
}

Expand Down