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 {...@@ -194,6 +194,9 @@ pub const Manifest = struct {
194 files: std.ArrayListUnmanaged(File) = .{},194 files: std.ArrayListUnmanaged(File) = .{},
195 hex_digest: [hex_digest_len]u8,195 hex_digest: [hex_digest_len]u8,
196 debug_bin_digest: DebugBinDigest = null_debug_bin_digest,196 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
198 /// Add a file as a dependency of process being cached. When `hit` is201 /// Add a file as a dependency of process being cached. When `hit` is
199 /// called, the file's contents will be checked to ensure that it matches202 /// called, the file's contents will be checked to ensure that it matches
...@@ -255,6 +258,8 @@ pub const Manifest = struct {...@@ -255,6 +258,8 @@ pub const Manifest = struct {
255 pub fn hit(self: *Manifest) !bool {258 pub fn hit(self: *Manifest) !bool {
256 assert(self.manifest_file == null);259 assert(self.manifest_file == null);
257260
261 self.failed_file_index = null;
262
258 const ext = ".txt";263 const ext = ".txt";
259 var manifest_file_path: [self.hex_digest.len + ext.len]u8 = undefined;264 var manifest_file_path: [self.hex_digest.len + ext.len]u8 = undefined;
260265
...@@ -366,7 +371,10 @@ pub const Manifest = struct {...@@ -366,7 +371,10 @@ pub const Manifest = struct {
366 };371 };
367 defer this_file.close();372 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 };
370 const size_match = actual_stat.size == cache_hash_file.stat.size;378 const size_match = actual_stat.size == cache_hash_file.stat.size;
371 const mtime_match = actual_stat.mtime == cache_hash_file.stat.mtime;379 const mtime_match = actual_stat.mtime == cache_hash_file.stat.mtime;
372 const inode_match = actual_stat.inode == cache_hash_file.stat.inode;380 const inode_match = actual_stat.inode == cache_hash_file.stat.inode;
...@@ -382,7 +390,10 @@ pub const Manifest = struct {...@@ -382,7 +390,10 @@ pub const Manifest = struct {
382 }390 }
383391
384 var actual_digest: BinDigest = undefined;392 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
387 if (!mem.eql(u8, &cache_hash_file.bin_digest, &actual_digest)) {398 if (!mem.eql(u8, &cache_hash_file.bin_digest, &actual_digest)) {
388 cache_hash_file.bin_digest = actual_digest;399 cache_hash_file.bin_digest = actual_digest;
...@@ -407,7 +418,10 @@ pub const Manifest = struct {...@@ -407,7 +418,10 @@ pub const Manifest = struct {
407 self.manifest_dirty = true;418 self.manifest_dirty = true;
408 while (idx < input_file_count) : (idx += 1) {419 while (idx < input_file_count) : (idx += 1) {
409 const ch_file = &self.files.items[idx];420 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 };
411 }425 }
412 return false;426 return false;
413 }427 }
src/Compilation.zig+7-2
...@@ -1629,7 +1629,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor...@@ -1629,7 +1629,7 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor
1629 unreachable;1629 unreachable;
16301630
1631 self.updateStage1Module(main_progress_node) catch |err| {1631 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)});
1633 };1633 };
1634 },1634 },
1635 };1635 };
...@@ -3001,7 +3001,12 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node...@@ -3001,7 +3001,12 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node
3001 const prev_hash_state = man.hash.peekBin();3001 const prev_hash_state = man.hash.peekBin();
3002 const input_file_count = man.files.items.len;3002 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) {
3005 const digest = man.final();3010 const digest = man.final();
30063011
3007 // We use an extra hex-encoded byte here to store some flags.3012 // We use an extra hex-encoded byte here to store some flags.