diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-10-10 14:19:32 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-10-10 14:21:52 -0700 |
| commit | 40006855579bc42d9d2ed2b3db67be289e91750d (patch) | |
| tree | 75074f72d9193767243f6b805fccd9edfd402dbc /src/Compilation.zig | |
| parent | 01aab9f6b38d13c37719cba1fdd0b4109ac0f6d2 (diff) | |
| download | zig-40006855579bc42d9d2ed2b3db67be289e91750d.tar.gz zig-40006855579bc42d9d2ed2b3db67be289e91750d.zip | |
Compilation: don't write cache manifest on failure
When errors occurred during flush(), incremental cache mode was still
writing a successful cache manifest, making subsequent compilations fail
because they would get a cache hit only to find invalid data.
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 6ba09d5c6d..8d276980ea 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -2302,7 +2302,7 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { try pt.processExports(); } - if (try comp.totalErrorCount() != 0) { + if (anyErrors(comp)) { // Skip flushing and keep source files loaded for error reporting. comp.link_error_flags = .{}; return; @@ -2392,6 +2392,10 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { .sub_path = o_sub_path, }, .main, main_progress_node); + // Calling `flush` may have produced errors, in which case the + // cache manifest must not be written. + if (anyErrors(comp)) return; + // Failure here only means an unnecessary cache miss. man.writeManifest() catch |err| { log.warn("failed to write cache manifest: {s}", .{@errorName(err)}); @@ -3291,6 +3295,10 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle { return bundle.toOwnedBundle(compile_log_text); } +fn anyErrors(comp: *Compilation) bool { + return (totalErrorCount(comp) catch return true) != 0; +} + fn totalErrorCount(comp: *Compilation) !u32 { var errors = try comp.getAllErrorsAlloc(); defer errors.deinit(comp.gpa); |
