Skip to content

Commit

Permalink
c2rust-transpile: only delete compile_commands.json if it was a tempo…
Browse files Browse the repository at this point in the history
…rary file we created
  • Loading branch information
fw-immunant committed Apr 29, 2024
1 parent 3d85abc commit 03facd3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion c2rust/src/bin/c2rust-transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ fn main() {
tcfg.emit_modules = true
};

let mut created_temp_compile_commands = false;

let compile_commands = if args.compile_commands.len() == 1
&& args.compile_commands[0].extension() == Some(std::ffi::OsStr::new("json"))
{
Expand All @@ -244,6 +246,7 @@ fn main() {
Exactly one compile_commands.json file should be provided, or a list of source files, but not both.");
} else {
// Handle as a list of source files
created_temp_compile_commands = true;
c2rust_transpile::create_temp_compile_commands(&args.compile_commands)
};

Expand All @@ -256,7 +259,7 @@ fn main() {
c2rust_transpile::transpile(tcfg, &compile_commands, &extra_args);

// Remove the temporary compile_commands.json if it was created
if args.compile_commands.len() > 0 {
if created_temp_compile_commands {
std::fs::remove_file(&compile_commands)
.expect("Failed to remove temporary compile_commands.json");
}
Expand Down

0 comments on commit 03facd3

Please sign in to comment.