Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean verif/ directory before writing to it #1303

Merged
merged 3 commits into from
Jan 27, 2025
Merged
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
29 changes: 28 additions & 1 deletion creusot/src/translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,40 @@ fn monolithic_output<T: Write>(modl: &FileModule, out: &mut T) -> std::io::Resul
Ok(())
}

// Remove coma files in the `verif/{krate}/` directory to avoid obsolete files left after
// (re)moving functions in source code.
// We don't want to just `remove_dir_all()` because it may contain
// `proof.json`, `why3session.xml`, and `why3shapes.xml` files that users want to preserve.
fn remove_coma_files(dir: &PathBuf) -> std::io::Result<()> {
if dir.exists() {
for entry in std::fs::read_dir(dir)? {
let entry = entry?;
let path = entry.path();
if path.is_dir() {
remove_coma_files(&path)?;
let _ = std::fs::remove_dir(path); // remove the directory if it's empty, do nothing otherwise
} else if path.extension().map_or(false, |ext| ext == "coma") {
std::fs::remove_file(&path)?;
}
}
}
Ok(())
}

fn print_crate<I: Iterator<Item = FileModule>>(
output_target: Output,
prefix: Vec<why3::Ident>,
modules: I,
) -> std::io::Result<Option<PathBuf>> {
let (root, mut output) = match output_target {
Output::Directory(dir) => (Some(dir.clone()), OutputHandle::Directory(dir, prefix)),
Output::Directory(dir) => {
let mut outdir = dir.clone();
for m in &prefix {
outdir.push(m.as_str());
}
remove_coma_files(&outdir)?;
(Some(dir.clone()), OutputHandle::Directory(dir, prefix))
}
Output::File(ref f) => {
std::fs::create_dir_all(f.parent().unwrap()).unwrap();
(
Expand Down
Loading