Auto merge of #8216 - ehuss:beta-1.44-clean-p-fix, r=alexcrichton

[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.
This commit is contained in:
bors 2020-05-06 19:12:48 +00:00
commit 05d080faa4
2 changed files with 44 additions and 0 deletions

View File

@ -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

View File

@ -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
);
}