authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-28 21:48:56-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-12-28 21:49:40-07:00
loge0a78d10ccb3c9b5d6ebb17f32ef3b79363cd4d0
tree782264e99a163c7ffe8e289ddf93803dd7377209
parent78dcd1b23ed4ca9d4202e1613ce2ec17c7b85e5c

stage2: better error message for root zig source file not found

closes #6777 closes #6893

2 files changed, 24 insertions(+), 5 deletions(-)

src/Cache.zig+17-3
......@@ -194,6 +194,9 @@ pub const Manifest = struct {
194194 files: std.ArrayListUnmanaged(File) = .{},
195195 hex_digest: [hex_digest_len]u8,
196196 debug_bin_digest: DebugBinDigest = null_debug_bin_digest,
197 /// Populated when hit() returns an error because of one
198 /// of the files listed in the manifest.
199 failed_file_index: ?usize = null,
197200
198201 /// Add a file as a dependency of process being cached. When `hit` is
199202 /// called, the file's contents will be checked to ensure that it matches
......@@ -255,6 +258,8 @@ pub const Manifest = struct {
255258 pub fn hit(self: *Manifest) !bool {
256259 assert(self.manifest_file == null);
257260
261 self.failed_file_index = null;
262
258263 const ext = ".txt";
259264 var manifest_file_path: [self.hex_digest.len + ext.len]u8 = undefined;
260265
......@@ -366,7 +371,10 @@ pub const Manifest = struct {
366371 };
367372 defer this_file.close();
368373
369 const actual_stat = try this_file.stat();
374 const actual_stat = this_file.stat() catch |err| {
375 self.failed_file_index = idx;
376 return err;
377 };
370378 const size_match = actual_stat.size == cache_hash_file.stat.size;
371379 const mtime_match = actual_stat.mtime == cache_hash_file.stat.mtime;
372380 const inode_match = actual_stat.inode == cache_hash_file.stat.inode;
......@@ -382,7 +390,10 @@ pub const Manifest = struct {
382390 }
383391
384392 var actual_digest: BinDigest = undefined;
385 try hashFile(this_file, &actual_digest);
393 hashFile(this_file, &actual_digest) catch |err| {
394 self.failed_file_index = idx;
395 return err;
396 };
386397
387398 if (!mem.eql(u8, &cache_hash_file.bin_digest, &actual_digest)) {
388399 cache_hash_file.bin_digest = actual_digest;
......@@ -407,7 +418,10 @@ pub const Manifest = struct {
407418 self.manifest_dirty = true;
408419 while (idx < input_file_count) : (idx += 1) {
409420 const ch_file = &self.files.items[idx];
410 try self.populateFileHash(ch_file);
421 self.populateFileHash(ch_file) catch |err| {
422 self.failed_file_index = idx;
423 return err;
424 };
411425 }
412426 return false;
413427 }
src/Compilation.zig+7-2
......@@ -1629,7 +1629,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
16291629 unreachable;
16301630
16311631 self.updateStage1Module(main_progress_node) catch |err| {
1632 fatal("unable to build stage1 zig object: {}", .{@errorName(err)});
1632 fatal("unable to build stage1 zig object: {s}", .{@errorName(err)});
16331633 };
16341634 },
16351635 };
......@@ -3001,7 +3001,12 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
30013001 const prev_hash_state = man.hash.peekBin();
30023002 const input_file_count = man.files.items.len;
30033003
3004 if (try man.hit()) {
3004 const hit = man.hit() catch |err| {
3005 const i = man.failed_file_index orelse return err;
3006 const file_path = man.files.items[i].path orelse return err;
3007 fatal("unable to build stage1 zig object: {s}: {s}", .{ @errorName(err), file_path });
3008 };
3009 if (hit) {
30053010 const digest = man.final();
30063011
30073012 // We use an extra hex-encoded byte here to store some flags.