authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-05-09 04:57:58+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-05-09 11:52:26+01:00
log787020b30b68d665cd08824d05ce5c7e459eccd1
tree7083cf9378b05b9e79d35f17a6c195733b997fb6
parenta5cfa3db3aa6a9f649ef19fc6be35cf27208d06b

Compilation: don't warn about failure to delete missing C depfile

If clang encountered bad imports, the depfile will not be generated. It doesn't make sense to warn the user in this case. In fact, `FileNotFound` is never worth warning about here; it just means that the file we were deleting to save space isn't there in the first place! If the missing file actually affected the compilation (e.g. another process raced to delete it for some reason) we would already error in the normal code path which reads these files, so we can safely omit the warning in the `FileNotFound` case always, only warning when the file might still exist. To see what this fixes, create the following file... ```c #include <nonexist> ``` ...and run `zig build-obj` on it. Before this commit, you will get a redundant warning; after this commit, that warning is gone.

1 files changed, 6 insertions(+), 4 deletions(-)

src/Compilation.zig+6-4
......@@ -5174,11 +5174,13 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
51745174 }
51755175
51765176 // Just to save disk space, we delete the files that are never needed again.
5177 defer if (out_diag_path) |diag_file_path| zig_cache_tmp_dir.deleteFile(std.fs.path.basename(diag_file_path)) catch |err| {
5178 log.warn("failed to delete '{s}': {s}", .{ diag_file_path, @errorName(err) });
5177 defer if (out_diag_path) |diag_file_path| zig_cache_tmp_dir.deleteFile(std.fs.path.basename(diag_file_path)) catch |err| switch (err) {
5178 error.FileNotFound => {}, // the file wasn't created due to an error we reported
5179 else => log.warn("failed to delete '{s}': {s}", .{ diag_file_path, @errorName(err) }),
51795180 };
5180 defer if (out_dep_path) |dep_file_path| zig_cache_tmp_dir.deleteFile(std.fs.path.basename(dep_file_path)) catch |err| {
5181 log.warn("failed to delete '{s}': {s}", .{ dep_file_path, @errorName(err) });
5181 defer if (out_dep_path) |dep_file_path| zig_cache_tmp_dir.deleteFile(std.fs.path.basename(dep_file_path)) catch |err| switch (err) {
5182 error.FileNotFound => {}, // the file wasn't created due to an error we reported
5183 else => log.warn("failed to delete '{s}': {s}", .{ dep_file_path, @errorName(err) }),
51825184 };
51835185 if (std.process.can_spawn) {
51845186 var child = std.process.Child.init(argv.items, arena);