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...@@ -4568,7 +4568,10 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
4568 // We can't know the digest until we do the C compiler invocation,4568 // We can't know the digest until we do the C compiler invocation,
4569 // so we need a temporary filename.4569 // so we need a temporary filename.
4570 const out_obj_path = try comp.tmpFilePath(arena, o_basename);4570 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});
4572 var zig_cache_tmp_dir = try comp.local_cache_directory.handle.makeOpenPath("tmp", .{});4575 var zig_cache_tmp_dir = try comp.local_cache_directory.handle.makeOpenPath("tmp", .{});
4573 defer zig_cache_tmp_dir.close();4576 defer zig_cache_tmp_dir.close();
45744577
...@@ -4603,6 +4606,13 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P...@@ -4603,6 +4606,13 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
4603 dump_argv(argv.items);4606 dump_argv(argv.items);
4604 }4607 }
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 };
4606 if (std.process.can_spawn) {4616 if (std.process.can_spawn) {
4607 var child = std.ChildProcess.init(argv.items, arena);4617 var child = std.ChildProcess.init(argv.items, arena);
4608 if (comp.clang_passthrough_mode) {4618 if (comp.clang_passthrough_mode) {
...@@ -4643,9 +4653,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P...@@ -4643,9 +4653,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
4643 log.err("{}: failed to parse clang diagnostics: {s}", .{ err, stderr });4653 log.err("{}: failed to parse clang diagnostics: {s}", .{ err, stderr });
4644 return comp.failCObj(c_object, "clang exited with code {d}", .{code});4654 return comp.failCObj(c_object, "clang exited with code {d}", .{code});
4645 };4655 };
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 };
4649 return comp.failCObjWithOwnedDiagBundle(c_object, bundle);4656 return comp.failCObjWithOwnedDiagBundle(c_object, bundle);
4650 }4657 }
4651 },4658 },
...@@ -4685,10 +4692,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P...@@ -4685,10 +4692,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P
4685 },4692 },
4686 .incremental => {},4693 .incremental => {},
4687 }4694 }
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 };
4692 }4695 }
46934696
4694 // We don't actually care whether it's a cache hit or miss; we just need the digest and the lock.4697 // 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...@@ -4924,10 +4927,6 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32
4924 .incremental => {},4927 .incremental => {},
4925 }4928 }
4926 }4929 }
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 };
4931 }4930 }
49324931
4933 // Rename into place.4932 // Rename into place.