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

Allow cargo doc --open with multiple packages. #6803

Merged
merged 1 commit into from
Apr 1, 2019
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
20 changes: 5 additions & 15 deletions src/cargo/ops/cargo_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions<'_>) -> CargoResult<()> {

let mut lib_names = HashMap::new();
let mut bin_names = HashMap::new();
let mut names = Vec::new();
for package in &pkgs {
for target in package.targets().iter().filter(|t| t.documented()) {
if target.is_lib() {
Expand All @@ -62,27 +63,16 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions<'_>) -> CargoResult<()> {
package
);
}
names.push(target.crate_name());
}
}

ops::compile(ws, &options.compile_opts)?;

if options.open_result {
let name = if pkgs.len() > 1 {
failure::bail!(
"Passing multiple packages and `open` is not supported.\n\
Please re-run this command with `-p <spec>` where `<spec>` \
is one of the following:\n {}",
pkgs.iter()
.map(|p| p.name().as_str())
.collect::<Vec<_>>()
.join("\n ")
);
} else {
match lib_names.keys().chain(bin_names.keys()).nth(0) {
Some(s) => s.to_string(),
None => return Ok(()),
}
let name = match names.first() {
Some(s) => s.to_string(),
None => return Ok(()),
};

// Don't bother locking here as if this is getting deleted there's
Expand Down
14 changes: 3 additions & 11 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,7 @@ fn doc_all_member_dependency_same_name() {
}

#[test]
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
fn doc_workspace_open_help_message() {
let p = project()
.file(
Expand All @@ -1029,19 +1030,10 @@ fn doc_workspace_open_help_message() {

// The order in which bar is compiled or documented is not deterministic
p.cargo("doc --all --open")
.with_status(101)
.env("BROWSER", "echo")
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
.with_stderr_contains(
"error: Passing multiple packages and `open` \
is not supported.",
)
.with_stderr_contains(
"Please re-run this command with `-p <spec>` \
where `<spec>` is one of the following:",
)
.with_stderr_contains(" foo")
.with_stderr_contains(" bar")
.with_stderr_contains("[..] Opening [..]/foo/index.html")
.run();
}

Expand Down