Sitelet https://github.com/voronor/compilers/commit/909e64d1c3474eb82d0774b0584c78f7f0e49324
Skip to content

Commit 909e64d

Browse files
authored
fix: remove outdated build infos (foundry-rs#177)
Closes foundry-rs#172
1 parent 7cf89ec commit 909e64d

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎crates/compilers/src/cache.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,27 @@ impl<S: CompilerSettings> CompilerCache<S> {
150150
Ok(())
151151
}
152152

153+
/// Removes build infos which don't have any artifacts linked to them.
154+
pub fn remove_outdated_builds(&mut self) {
155+
let mut outdated = Vec::new();
156+
for build_id in &self.builds {
157+
if !self
158+
.entries()
159+
.flat_map(|e| e.artifacts.values())
160+
.flat_map(|a| a.values())
161+
.any(|a| a.build_id == *build_id)
162+
{
163+
outdated.push(build_id.to_owned());
164+
}
165+
}
166+
167+
for build_id in outdated {
168+
self.builds.remove(&build_id);
169+
let path = self.paths.build_infos.join(build_id).with_extension("json");
170+
let _ = std::fs::remove_file(path);
171+
}
172+
}
173+
153174
/// Sets the `CacheEntry`'s file paths to `root` adjoined to `self.file`.
154175
pub fn join_entries(&mut self, root: &Path) -> &mut Self {
155176
self.files = std::mem::take(&mut self.files)
@@ -1035,6 +1056,7 @@ impl<'a, T: ArtifactOutput, C: Compiler> ArtifactsCache<'a, T, C> {
10351056

10361057
// write to disk
10371058
if write_to_disk {
1059+
cache.remove_outdated_builds();
10381060
// make all `CacheEntry` paths relative to the project root and all artifact
10391061
// paths relative to the artifact's directory
10401062
cache

0 commit comments

Comments
 (0)