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
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/build_runner/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {
panic!("doc tests do not have an out dir");
} else if unit.target.is_custom_build() {
self.build_script_dir(unit)
} else if unit.target.is_example() {
} else if unit.target.is_example() && !self.ws.gctx().cli_unstable().build_dir_new_layout {
self.layout(unit.kind).build_dir().examples().to_path_buf()
} else if unit.artifact.is_true() {
self.artifact_dir(unit)
Comment on lines 225 to 226
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'm assuming we should eventually revisit this design as well so that artifact-deps doesn't affect the atomic nature of build units to allow for #5931.

Expand Down
5 changes: 5 additions & 0 deletions src/cargo/ops/cargo_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ fn clean_specs(
if target.is_custom_build() {
continue;
}
let crate_name: Rc<str> = target.crate_name().into();
for &mode in &[
CompileMode::Build,
CompileMode::Test,
Expand Down Expand Up @@ -240,6 +241,10 @@ fn clean_specs(
clean_ctx.rm_rf(&dep_info)?;
}
}

let dir = escape_glob_path(layout.build_dir().incremental())?;
let incremental = Path::new(&dir).join(format!("{}-*", crate_name));
clean_ctx.rm_rf_glob(&incremental)?;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/build_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ fn examples_should_output_to_build_dir_and_uplift_to_target_dir() {
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/fingerprint/example-foo
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/fingerprint/example-foo.json
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/fingerprint/invoked.timestamp
[ROOT]/foo/build-dir/debug/examples/foo[..][EXE]
[ROOT]/foo/build-dir/debug/examples/foo[..].d
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo[..][EXE]
[ROOT]/foo/build-dir/debug/build/foo/[HASH]/deps/foo[..].d

"#]]);

Expand Down
46 changes: 43 additions & 3 deletions tests/testsuite/clean_new_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ fn clean_multiple_packages_in_glob_char_path() {
p.cargo("clean -p foo")
.arg("-Zbuild-dir-new-layout")
.masquerade_as_nightly_cargo(&["new build-dir layout"])
.with_stderr_data(str![[r#"
[REMOVED] [FILE_NUM] files, [FILE_SIZE]B total

"#]])
.run();
assert_eq!(get_build_artifacts(foo_path, file_glob).len(), 0);
}
Expand Down Expand Up @@ -598,7 +602,7 @@ fn package_cleans_all_the_things() {
.arg("-Zbuild-dir-new-layout")
.masquerade_as_nightly_cargo(&["new build-dir layout"])
.run();
//assert_all_clean(&p.build_dir()); // FIXME
assert_all_clean(&p.build_dir());
}
let p = project()
.file(
Expand Down Expand Up @@ -657,7 +661,7 @@ fn package_cleans_all_the_things() {
.arg("-Zbuild-dir-new-layout")
.masquerade_as_nightly_cargo(&["new build-dir layout"])
.run();
//assert_all_clean(&p.build_dir()); // FIXME
assert_all_clean(&p.build_dir());

// Try some targets.
p.cargo("build --all-targets --target")
Expand All @@ -670,7 +674,43 @@ fn package_cleans_all_the_things() {
.arg("-Zbuild-dir-new-layout")
.masquerade_as_nightly_cargo(&["new build-dir layout"])
.run();
//assert_all_clean(&p.build_dir()); // FIXME
assert_all_clean(&p.build_dir());
}

// Ensures that all files for the package have been deleted.
#[track_caller]
fn assert_all_clean(build_dir: &Path) {
let walker = walkdir::WalkDir::new(build_dir).into_iter();
for entry in walker.filter_entry(|e| {
let path = e.path();
// This is a known limitation, clean can't differentiate between
// the different build scripts from different packages.
!(path
.file_name()
.unwrap()
.to_str()
.unwrap()
.starts_with("build_script_build")
&& path
.parent()
.unwrap()
.file_name()
.unwrap()
.to_str()
.unwrap()
== "incremental")
}) {
let entry = entry.unwrap();
let path = entry.path();
if let ".rustc_info.json" | ".cargo-lock" | "CACHEDIR.TAG" =
path.file_name().unwrap().to_str().unwrap()
{
continue;
}
if path.is_symlink() || path.is_file() {
panic!("{:?} was not cleaned", path);
}
}
}

#[cargo_test]
Expand Down