Skip to content

Commit

Permalink
Error out if cargo clean --doc is mixed with -p.
Browse files Browse the repository at this point in the history
Currently the `-p` is ignored. This should help with any confusion
about the interaction of different flags.
rust-lang#8790 is tracking to fix this.
  • Loading branch information
ehuss committed Sep 7, 2023
1 parent d7a601e commit 187b91b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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
// 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();
}

0 comments on commit 187b91b

Please sign in to comment.