Skip to content

Commit

Permalink
Auto merge of #8216 - ehuss:beta-1.44-clean-p-fix, r=alexcrichton
Browse files Browse the repository at this point in the history
[beta] Fix `clean -p` with a build dependency.

This is a temporary and simple fix for #8149 where `cargo clean -p foo` would fail if `foo` has a build dependency.  The full fix is in #8210, but I think that PR is way too risky to backport.
  • Loading branch information
bors committed May 6, 2020
2 parents ff91911 + 5a6849e commit 05d080f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cargo/ops/cargo_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {
for target in pkg.targets() {
for kind in [CompileKind::Host, build_config.requested_kind].iter() {
for mode in CompileMode::all_modes() {
if target.is_custom_build() && (mode.is_any_test() || !kind.is_host()) {
// Workaround where the UnitFor code will panic
// because it is not expecting strange combinations
// like "testing a build script".
continue;
}
for unit_for in UnitFor::all_values() {
let profile = if mode.is_run_custom_build() {
bcx.profiles
Expand Down
38 changes: 38 additions & 0 deletions tests/testsuite/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,41 @@ fn clean_remove_rlib_rmeta() {
assert!(!p.target_debug_dir().join("libfoo.rlib").exists());
assert!(!rmeta.exists());
}

#[cargo_test]
fn clean_with_build_dep() {
// Test for panic when there was a build dep with `-p`.
Package::new("bar", "0.1.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[build-dependencies]
bar = "0.1"
"#,
)
.file("src/lib.rs", "")
.file("build.rs", "fn main() {}")
.build();

p.cargo("build").run();
// Two build directories, one for the executable, one for the run output.
assert_eq!(p.glob(p.target_debug_dir().join("build/foo-*")).count(), 2);
// Produces both an rlib and rmeta.
assert_eq!(
p.glob(p.target_debug_dir().join("deps/libfoo-*.*")).count(),
2
);
p.cargo("clean -p foo").run();
// `clean -p` doesn't clean the output directory, it should.
// Will be fixed via https://github.com/rust-lang/cargo/pull/8210
assert_eq!(p.glob(p.target_debug_dir().join("build/foo-*")).count(), 1);
assert_eq!(
p.glob(p.target_debug_dir().join("deps/libfoo-*.*")).count(),
0
);
}

0 comments on commit 05d080f

Please sign in to comment.