From 67463c4357d0d0f43b8962231659fb8a1cc4869a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 24 Sep 2020 21:52:37 -0700 Subject: correct `@cImport` caching to handle "unhit" case if you hit() you have to unhit() to get the same digest if you don't end up treating it as a hit. --- src/Compilation.zig | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/Compilation.zig') diff --git a/src/Compilation.zig b/src/Compilation.zig index 0b222bd787..03da22d80c 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1242,7 +1242,16 @@ pub fn cImport(comp: *Compilation, c_src: []const u8) !CImportResult { // If the previous invocation resulted in clang errors, we will see a hit // here with 0 files in the manifest, in which case it is actually a miss. - const actual_hit = (try man.hit()) and man.files.items.len != 0; + // We need to "unhit" in this case, to keep the digests matching. + const prev_hash_state = man.hash.peekBin(); + const actual_hit = hit: { + const is_hit = try man.hit(); + if (man.files.items.len == 0) { + man.unhit(prev_hash_state, 0); + break :hit false; + } + break :hit true; + }; const digest = if (!actual_hit) digest: { var arena_allocator = std.heap.ArenaAllocator.init(comp.gpa); defer arena_allocator.deinit(); @@ -1396,7 +1405,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void { mem.split(c_source_basename, ".").next().?; const o_basename = try std.fmt.allocPrint(arena, "{}{}", .{ o_basename_noext, comp.getTarget().oFileExt() }); - const digest = if ((try man.hit()) and !comp.disable_c_depfile) man.final() else blk: { + const digest = if (!comp.disable_c_depfile and try man.hit()) man.final() else blk: { var argv = std.ArrayList([]const u8).init(comp.gpa); defer argv.deinit(); -- cgit v1.2.3