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

[beta] Fix clean -p with a build dependency. #8216

Merged
merged 1 commit into from
May 6, 2020
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
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
);
}