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

Error out if cargo clean --doc is mixed with -p. #12637

Merged
merged 1 commit into from
Sep 7, 2023
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
11 changes: 10 additions & 1 deletion src/cargo/ops/cargo_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::util::errors::CargoResult;
use crate::util::interning::InternedString;
use crate::util::{Config, Progress, ProgressStyle};

use anyhow::Context as _;
use anyhow::{bail, Context as _};
use cargo_util::paths;
use std::fs;
use std::path::Path;
Expand All @@ -33,6 +33,15 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {

// If the doc option is set, we just want to delete the doc directory.
if opts.doc {
if !opts.spec.is_empty() {
// FIXME: https://github.com/rust-lang/cargo/issues/8790
Comment on lines +36 to +37
Copy link
Contributor

Choose a reason for hiding this comment

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

This culd be done with clap but sicne this is just a fixme, it likely doesn't matter

// This should support the ability to clean specific packages
// within the doc directory. It's a little tricky since it
// needs to find all documentable targets, but also consider
// the fact that target names might overlap with dependency
// names and such.
bail!("--doc cannot be used with -p");
}
target_dir = target_dir.join("doc");
return clean_entire_folder(&target_dir.into_path_unlocked(), config);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/testsuite/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,3 +673,13 @@ fn clean_spec_reserved() {
)
.run();
}

#[cargo_test]
fn doc_with_package_selection() {
// --doc with -p
let p = project().file("src/lib.rs", "").build();
p.cargo("clean --doc -p foo")
.with_status(101)
.with_stderr("error: --doc cannot be used with -p")
.run();
}