Skip to content
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
54 changes: 48 additions & 6 deletions src/cargo/ops/cargo_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,54 @@ fn clean_specs(
let pkg_dir = format!("{}-*", pkg.name());
clean_ctx.progress.on_cleaning_package(&pkg.name())?;

if clean_ctx.gctx.cli_unstable().build_dir_new_layout {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have tests for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I duplicated clean.rs tests to verify -Zbuild-dir-new-layout. This uncovered several issues. I fixed most. There remains one which has test overlap with this so no test results changed. I decided to go ahead and get this update up rather than wait on all of them since this last one may be a bit nasty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #16302 for this

for (_compile_kind, layout) in &layouts_with_host {
let dir = layout.build_dir().build_unit(&pkg.name());
clean_ctx.rm_rf(&dir)?;
}

for target in pkg.targets() {
if target.is_custom_build() {
continue;
}
for &mode in &[
CompileMode::Build,
CompileMode::Test,
CompileMode::Check { test: false },
] {
for (compile_kind, layout) in &layouts {
let triple = target_data.short_name(compile_kind);
let (file_types, _unsupported) = target_data
.info(*compile_kind)
.rustc_outputs(mode, target.kind(), triple, clean_ctx.gctx)?;
let artifact_dir = layout
.artifact_dir()
.expect("artifact-dir was not locked during clean");
Comment on lines +223 to +225
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can't merge this until we un-revert #16299

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come? Without that, artifact_dir() should always be Some

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Err nvm, I forgot we split that into 2 PRs

let uplift_dir = match target.kind() {
TargetKind::ExampleBin | TargetKind::ExampleLib(..) => {
Some(artifact_dir.examples())
}
// Tests/benchmarks are never uplifted.
TargetKind::Test | TargetKind::Bench => None,
_ => Some(artifact_dir.dest()),
};
// Remove the uplifted copy.
if let Some(uplift_dir) = uplift_dir {
for file_type in file_types {
let uplifted_path =
uplift_dir.join(file_type.uplift_filename(target));
clean_ctx.rm_rf(&uplifted_path)?;
// Dep-info generated by Cargo itself.
let dep_info = uplifted_path.with_extension("d");
clean_ctx.rm_rf(&dep_info)?;
}
}
}
}
}
continue;
}

// Clean fingerprints.
for (_, layout) in &layouts_with_host {
let dir = escape_glob_path(layout.build_dir().legacy_fingerprint())?;
Expand Down Expand Up @@ -228,12 +276,6 @@ fn clean_specs(
CompileMode::Check { test: false },
] {
for (compile_kind, layout) in &layouts {
if clean_ctx.gctx.cli_unstable().build_dir_new_layout {
let dir = layout.build_dir().build_unit(&pkg.name());
clean_ctx.rm_rf_glob(&dir)?;
continue;
}

let triple = target_data.short_name(compile_kind);
let (file_types, _unsupported) = target_data
.info(*compile_kind)
Expand Down
Loading