authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-05-22 08:18:44-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-22 10:42:01-04:00
loged75f62568f64c0d3859aab35aaf5289c3f07026
tree6dd2ebc0520ed61c8221e04a01b4b2f715f5520c
parent0286970b19249a36edac35fe2ee7caac8fbe927c

Compilation: better cleanup of temporary files

The diag file did not get deleted on the success path and the dep file did not get deleted on the failure path.

1 files changed, 11 insertions(+), 12 deletions(-)

src/Compilation.zig+11-12
......@@ -4568,7 +4568,10 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
45684568 // We can't know the digest until we do the C compiler invocation,
45694569 // so we need a temporary filename.
45704570 const out_obj_path = try comp.tmpFilePath(arena, o_basename);
4571 const out_diag_path = try std.fmt.allocPrint(arena, "{s}.diag", .{out_obj_path});
4571 const out_diag_path = if (comp.clang_passthrough_mode)
4572 undefined
4573 else
4574 try std.fmt.allocPrint(arena, "{s}.diag", .{out_obj_path});
45724575 var zig_cache_tmp_dir = try comp.local_cache_directory.handle.makeOpenPath("tmp", .{});
45734576 defer zig_cache_tmp_dir.close();
45744577
......@@ -4603,6 +4606,13 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
46034606 dump_argv(argv.items);
46044607 }
46054608
4609 // Just to save disk space, we delete the files that are never needed again.
4610 defer if (!comp.clang_passthrough_mode) zig_cache_tmp_dir.deleteFile(std.fs.path.basename(out_diag_path)) catch |err| {
4611 log.warn("failed to delete '{s}': {s}", .{ out_diag_path, @errorName(err) });
4612 };
4613 defer if (out_dep_path) |dep_file_path| zig_cache_tmp_dir.deleteFile(std.fs.path.basename(dep_file_path)) catch |err| {
4614 log.warn("failed to delete '{s}': {s}", .{ dep_file_path, @errorName(err) });
4615 };
46064616 if (std.process.can_spawn) {
46074617 var child = std.ChildProcess.init(argv.items, arena);
46084618 if (comp.clang_passthrough_mode) {
......@@ -4643,9 +4653,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
46434653 log.err("{}: failed to parse clang diagnostics: {s}", .{ err, stderr });
46444654 return comp.failCObj(c_object, "clang exited with code {d}", .{code});
46454655 };
4646 zig_cache_tmp_dir.deleteFile(out_diag_path) catch |err| {
4647 log.warn("failed to delete '{s}': {s}", .{ out_diag_path, @errorName(err) });
4648 };
46494656 return comp.failCObjWithOwnedDiagBundle(c_object, bundle);
46504657 }
46514658 },
......@@ -4685,10 +4692,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
46854692 },
46864693 .incremental => {},
46874694 }
4688 // Just to save disk space, we delete the file because it is never needed again.
4689 zig_cache_tmp_dir.deleteFile(dep_basename) catch |err| {
4690 log.warn("failed to delete '{s}': {s}", .{ dep_file_path, @errorName(err) });
4691 };
46924695 }
46934696
46944697 // We don't actually care whether it's a cache hit or miss; we just need the digest and the lock.
......@@ -4924,10 +4927,6 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
49244927 .incremental => {},
49254928 }
49264929 }
4927 // Just to save disk space, we delete the file because it is never needed again.
4928 zig_cache_tmp_dir.deleteFile(dep_basename) catch |err| {
4929 log.warn("failed to delete '{s}': {s}", .{ out_dep_path, @errorName(err) });
4930 };
49314930 }
49324931
49334932 // Rename into place.