Skip to content

Commit aa04395

Browse files
committed
fix(clean): Remove uplifted for specified package for new layout
1 parent ed47fd2 commit aa04395

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/cargo/ops/cargo_clean.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,46 @@ fn clean_specs(
205205
let dir = layout.build_dir().build_unit(&pkg.name());
206206
clean_ctx.rm_rf_glob(&dir)?;
207207
}
208+
209+
for target in pkg.targets() {
210+
if target.is_custom_build() {
211+
continue;
212+
}
213+
for &mode in &[
214+
CompileMode::Build,
215+
CompileMode::Test,
216+
CompileMode::Check { test: false },
217+
] {
218+
for (compile_kind, layout) in &layouts {
219+
let triple = target_data.short_name(compile_kind);
220+
let (file_types, _unsupported) = target_data
221+
.info(*compile_kind)
222+
.rustc_outputs(mode, target.kind(), triple, clean_ctx.gctx)?;
223+
let artifact_dir = layout
224+
.artifact_dir()
225+
.expect("artifact-dir was not locked during clean");
226+
let uplift_dir = match target.kind() {
227+
TargetKind::ExampleBin | TargetKind::ExampleLib(..) => {
228+
Some(artifact_dir.examples())
229+
}
230+
// Tests/benchmarks are never uplifted.
231+
TargetKind::Test | TargetKind::Bench => None,
232+
_ => Some(artifact_dir.dest()),
233+
};
234+
// Remove the uplifted copy.
235+
if let Some(uplift_dir) = uplift_dir {
236+
for file_type in file_types {
237+
let uplifted_path =
238+
uplift_dir.join(file_type.uplift_filename(target));
239+
clean_ctx.rm_rf(&uplifted_path)?;
240+
// Dep-info generated by Cargo itself.
241+
let dep_info = uplifted_path.with_extension("d");
242+
clean_ctx.rm_rf(&dep_info)?;
243+
}
244+
}
245+
}
246+
}
247+
}
208248
continue;
209249
}
210250

tests/testsuite/clean_new_layout.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ fn clean_multiple_packages() {
113113
.masquerade_as_nightly_cargo(&["new build-dir layout"])
114114
.run();
115115
assert!(p.bin("foo").is_file());
116-
assert!(d1_path.is_file()); // FIXME
117-
assert!(d2_path.is_file()); // FIXME
116+
assert!(!d1_path.is_file());
117+
assert!(!d2_path.is_file());
118118
}
119119

120120
#[cargo_test]
@@ -561,7 +561,7 @@ fn clean_remove_rlib_rmeta() {
561561
.arg("-Zbuild-dir-new-layout")
562562
.masquerade_as_nightly_cargo(&["new build-dir layout"])
563563
.run();
564-
assert!(p.target_debug_dir().join("libfoo.rlib").exists()); // FIXME
564+
assert!(!p.target_debug_dir().join("libfoo.rlib").exists());
565565
assert!(!rmeta.exists());
566566
}
567567

0 commit comments

Comments
 (0)