mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-03 01:25:15 +00:00
Garbage-collect old incremental compilation sessions
This commit is contained in:
@@ -702,8 +702,10 @@ pub(crate) fn garbage_collect_session_directories(
|
||||
lock_file_to_session_dir.items().filter_map(|(lock_file_name, directory_name)| {
|
||||
debug!("garbage_collect_session_directories() - inspecting: {}", directory_name);
|
||||
|
||||
if directory_name.as_str() == current_session_directory_name {
|
||||
// Skipping our own directory is, unfortunately, important for correctness.
|
||||
if directory_name.as_str() == current_session_directory_name
|
||||
&& !is_finalized(directory_name)
|
||||
{
|
||||
// Skipping our own active directory is important for correctness.
|
||||
//
|
||||
// To summarize #147821: we will try to lock directories before deciding they can be
|
||||
// garbage collected, but the ability of `flock::Lock` to detect a lock held *by the
|
||||
@@ -722,6 +724,8 @@ pub(crate) fn garbage_collect_session_directories(
|
||||
// It's not clear that `flock::Lock` can be fixed for this in general, and our own
|
||||
// incremental session directory is the only one which this process may own, so skip
|
||||
// it here and avoid the problem. We know it's not garbage anyway: we're using it.
|
||||
// Once finalized, its lock is released. Include it in collection so we keep only
|
||||
// the newest completed session.
|
||||
return None;
|
||||
}
|
||||
|
||||
|
||||
2
tests/run-make/incremental-session-gc/empty.rs
Normal file
2
tests/run-make/incremental-session-gc/empty.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
#![feature(no_core)]
|
||||
#![no_core]
|
||||
33
tests/run-make/incremental-session-gc/rmake.rs
Normal file
33
tests/run-make/incremental-session-gc/rmake.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
//! Successful sequential builds should retain only the newest incremental session.
|
||||
//! The current session must participate in garbage collection once it is finalized.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use run_make_support::{rfs, rustc, shallow_find_directories};
|
||||
|
||||
fn main() {
|
||||
let compile = || {
|
||||
rustc().input("empty.rs").crate_type("rlib").emit("metadata").incremental("incr").run();
|
||||
};
|
||||
|
||||
compile();
|
||||
let mut previous = session_dir();
|
||||
rfs::write(previous.join("sentinel"), "previous session");
|
||||
|
||||
for _ in 0..2 {
|
||||
compile();
|
||||
let current = session_dir();
|
||||
assert_ne!(previous, current);
|
||||
assert!(!previous.exists(), "superseded session was not collected: {previous:?}");
|
||||
assert_eq!(rfs::read_to_string(current.join("sentinel")), "previous session");
|
||||
previous = current;
|
||||
}
|
||||
}
|
||||
|
||||
fn session_dir() -> PathBuf {
|
||||
let crate_dirs = shallow_find_directories("incr", |_| true);
|
||||
assert_eq!(crate_dirs.len(), 1);
|
||||
let sessions = shallow_find_directories(&crate_dirs[0], |_| true);
|
||||
assert_eq!(sessions.len(), 1, "expected only the newest completed session: {sessions:?}");
|
||||
sessions.into_iter().next().unwrap()
|
||||
}
|
||||
Reference in New Issue
Block a user