mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Treat calls to rm_rf_prefix_list as idempotent
Starting with this commit we deduplicate calls to rm_rf_prefix_list by crate name and not by directory; this can lead to more calls to rm_rf_prefix_list (especially in presence of multiple -p arguments), but it is also more transparent in terms of progress reporting (we're just storing away whether a given directory + glob pair has already been removed)
This commit is contained in:
parent
c770700885
commit
d33ef8fbe7
@ -170,7 +170,8 @@ fn clean_specs(
|
||||
let packages = pkg_set.get_many(pkg_ids)?;
|
||||
|
||||
clean_ctx.progress = Box::new(CleaningPackagesBar::new(clean_ctx.gctx, packages.len()));
|
||||
let mut dirs_to_clean: HashMap<_, HashSet<_>> = HashMap::new();
|
||||
|
||||
let mut cleaned_packages: HashMap<_, HashSet<_>> = HashMap::default();
|
||||
for pkg in packages {
|
||||
let pkg_dir = format!("{}-*", pkg.name());
|
||||
clean_ctx.progress.on_cleaning_package(&pkg.name())?;
|
||||
@ -194,10 +195,9 @@ fn clean_specs(
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let crate_name = target.crate_name();
|
||||
let crate_name: Rc<str> = target.crate_name().into();
|
||||
let path_dot: Rc<str> = format!("{crate_name}.").into();
|
||||
let path_dash: Rc<str> = format!("{crate_name}-").into();
|
||||
|
||||
for &mode in &[
|
||||
CompileMode::Build,
|
||||
CompileMode::Test,
|
||||
@ -242,17 +242,24 @@ fn clean_specs(
|
||||
clean_ctx.rm_rf(&unhashed_dep_info)?;
|
||||
// Remove split-debuginfo files generated by rustc.
|
||||
|
||||
let paths = [
|
||||
(path_dash.clone(), ".d"),
|
||||
(path_dot.clone(), ".o"),
|
||||
(path_dot.clone(), ".dwo"),
|
||||
(path_dot.clone(), ".dwp"),
|
||||
];
|
||||
if !dir_glob_str.ends_with(std::path::MAIN_SEPARATOR) {
|
||||
dir_glob_str.push(std::path::MAIN_SEPARATOR);
|
||||
}
|
||||
dir_glob_str.push('*');
|
||||
dirs_to_clean.entry(dir_glob_str).or_default().extend(paths);
|
||||
let dir_glob_str: Rc<str> = dir_glob_str.into();
|
||||
if cleaned_packages
|
||||
.entry(dir_glob_str.clone())
|
||||
.or_default()
|
||||
.insert(crate_name.clone())
|
||||
{
|
||||
let paths = [
|
||||
(path_dash.clone(), ".d"),
|
||||
(path_dot.clone(), ".o"),
|
||||
(path_dot.clone(), ".dwo"),
|
||||
(path_dot.clone(), ".dwp"),
|
||||
];
|
||||
clean_ctx.rm_rf_prefix_list(&dir_glob_str, &paths)?;
|
||||
}
|
||||
|
||||
// TODO: what to do about build_script_build?
|
||||
let dir = escape_glob_path(layout.incremental())?;
|
||||
@ -263,9 +270,6 @@ fn clean_specs(
|
||||
}
|
||||
}
|
||||
|
||||
for (dir, paths) in dirs_to_clean {
|
||||
clean_ctx.rm_rf_prefix_list(&dir, &paths)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -338,7 +342,7 @@ impl<'gctx> CleanContext<'gctx> {
|
||||
fn rm_rf_prefix_list(
|
||||
&mut self,
|
||||
pattern: &str,
|
||||
path_matchers: &HashSet<(Rc<str>, &str)>,
|
||||
path_matchers: &[(Rc<str>, &str)],
|
||||
) -> CargoResult<()> {
|
||||
// TODO: Display utf8 warning to user? Or switch to globset?
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user