diff --git a/lib/compiler/Maker/Step/Run.zig b/lib/compiler/Maker/Step/Run.zig index 2e750ccfb9f963ed8bb544a5d99af61bb45fb77a..828b5eb170515c999e8c0e40da4d1b668adfb1a8 100644 --- a/lib/compiler/Maker/Step/Run.zig +++ b/lib/compiler/Maker/Step/Run.zig @@ -292,16 +292,32 @@ pub fn make( switch (arg.flags.tag) { .output_file => if (arg.flags.dep_file) { const generated_path = maker.generatedPath(arg.generated.value.?).*; - const result = if (has_side_effects) - man.addDepFile(generated_path.root_dir.handle, generated_path.sub_path) - else - man.addDepFilePost(generated_path.root_dir.handle, generated_path.sub_path); - result catch |err| switch (err) { - error.OutOfMemory, error.Canceled => |e| return e, - else => |e| return step.fail(maker, "failed adding to cache the file {f}: {t}", .{ - generated_path, e, - }), - }; + if (has_side_effects) { + var diagnostic: Cache.DepTokenizer.Token = undefined; + man.addInputDepFile(generated_path, &diagnostic) catch |err| switch (err) { + error.OutOfMemory, error.Canceled => |e| return e, + error.InvalidDepFile => return step.fail(maker, "failed adding dep file {f} to cache: {f}", .{ + generated_path, diagnostic, + }), + else => |e| return step.fail(maker, "failed adding dep file {f} to cache: {t}", .{ + generated_path, e, + }), + }; + } else { + var diagnostic: Cache.Manifest.AddDiscoveredDepFileDiagnostic = undefined; + man.addDiscoveredDepFile(generated_path, &diagnostic) catch |err| switch (err) { + error.OutOfMemory, error.Canceled => |e| return e, + error.InvalidDepFile => return step.fail(maker, "failed adding dep file {f} to cache: {f}", .{ + generated_path, diagnostic.dep_tokenizer, + }), + error.FileSystemFailure => return step.fail(maker, "failed adding a path from dep file {f} to cache: {f}", .{ + generated_path, diagnostic.add_discovered_path, + }), + else => |e| return step.fail(maker, "failed adding dep file {f} to cache: {t}", .{ + generated_path, e, + }), + }; + } }, .output_directory => continue, else => unreachable, diff --git a/lib/std/Build/Cache.zig b/lib/std/Build/Cache.zig index a4864beb29c3926406868d315d146b8e32079af8..91c678ed2f94515d5104b42e162944f23920923b 100644 --- a/lib/std/Build/Cache.zig +++ b/lib/std/Build/Cache.zig @@ -759,6 +759,52 @@ pub const Manifest = struct { _ = try addInputPath(m, opt_path orelse return, options); } + pub const AddInputDepFileError = error{ + InvalidDepFile, + } || Allocator.Error || Io.File.OpenError || Io.File.Reader.Error; + + pub fn addInputDepFile(m: *Manifest, path: Path, diagnostic: ?*DepTokenizer.Token) AddInputDepFileError!void { + assert(m.manifest_file == null); + assert(m.state == .input); + + const cache = m.cache; + const gpa = cache.gpa; + const io = cache.io; + + // TODO: change DepTokenizer to be streaming rather than operating on slice of bytes. + const prev_len = m.all_input_content.items.len; + defer m.all_input_content.items.len = prev_len; + + const file = try path.root_dir.handle.openFile(io, path.sub_path, .{}); + defer file.close(io); + + var file_reader: Io.File.Reader = .init(file, io, &.{}); + file_reader.interface.appendRemainingUnlimited(gpa, &m.all_input_content) catch |err| switch (err) { + error.OutOfMemory => |e| return e, + error.ReadFailed => return file_reader.err.?, + }; + + var aux: std.ArrayList(u8) = .empty; + defer aux.deinit(gpa); + + var it: DepTokenizer = .{ .bytes = m.all_input_content.items[prev_len..] }; + while (it.next()) |token| switch (token) { + .target, .target_must_resolve => {}, + .prereq => |file_path| { + _ = try m.addInputPath(.initCwd(file_path), .{}); + }, + .prereq_must_resolve => { + aux.clearRetainingCapacity(); + try token.resolve(gpa, &aux); + _ = try m.addInputPath(.initCwd(aux.items), .{}); + }, + else => |err| { + if (diagnostic) |d| d.* = err; + return error.InvalidDepFile; + }, + }; + } + pub const CheckResult = union(enum) { hit, incomplete_manifest, @@ -1614,6 +1660,13 @@ pub const Manifest = struct { stat_dir: Io.Dir.StatError, read_file: Io.File.ReadPositionalError, read_dir: Io.Dir.Reader.Error, + + pub fn format(this: @This(), w: *Io.Writer) Io.Writer.Error!void { + switch (this) { + .none => return w.writeAll("none"), + else => |err, tag| return w.print("{t}: {t}", .{ tag, err }), + } + } }; pub const AddDiscoveredPathError = error{ @@ -1726,6 +1779,59 @@ pub const Manifest = struct { } } + pub const AddDiscoveredDepFileError = error{ + InvalidDepFile, + } || AddDiscoveredPathError || Io.File.OpenError || Io.File.Reader.Error; + + pub const AddDiscoveredDepFileDiagnostic = union(enum) { + add_discovered_path: AddDiscoveredPathDiagnostic, + dep_tokenizer: DepTokenizer.Token, + }; + + pub fn addDiscoveredDepFile( + m: *Manifest, + path: Path, + diagnostic: ?*AddDiscoveredDepFileDiagnostic, + ) AddDiscoveredDepFileError!void { + assert(m.manifest_file != null); + transitionToMissDiscovered(m); + + const cache = m.cache; + const gpa = cache.gpa; + const io = cache.io; + + // TODO: change DepTokenizer to be streaming rather than operating on slice of bytes. + const prev_len = m.all_input_content.items.len; + defer m.all_input_content.items.len = prev_len; + + const file = try path.root_dir.handle.openFile(io, path.sub_path, .{}); + defer file.close(io); + + var file_reader: Io.File.Reader = .init(file, io, &.{}); + file_reader.interface.appendRemainingUnlimited(gpa, &m.all_input_content) catch |err| switch (err) { + error.OutOfMemory => |e| return e, + error.ReadFailed => return file_reader.err.?, + }; + + var aux: std.ArrayList(u8) = .empty; + defer aux.deinit(gpa); + + var it: DepTokenizer = .{ .bytes = m.all_input_content.items[prev_len..] }; + while (it.next()) |token| switch (token) { + .target, .target_must_resolve => {}, + .prereq => |p| try m.addDiscoveredPath(.{ .discovered_path = .{ .unresolved = .initCwd(p) } }), + .prereq_must_resolve => { + aux.clearRetainingCapacity(); + try token.resolve(gpa, &aux); + try m.addDiscoveredPath(.{ .discovered_path = .{ .unresolved = .initCwd(aux.items) } }); + }, + else => |err| { + if (diagnostic) |d| d.* = .{ .dep_tokenizer = err }; + return error.InvalidDepFile; + }, + }; + } + fn populateFile( m: *Manifest, file: *File, @@ -1810,53 +1916,6 @@ pub const Manifest = struct { } } - pub fn addDepFile(self: *Manifest, dir: Io.Dir, dep_file_sub_path: []const u8) !void { - assert(self.manifest_file == null); - return self.addDepFileMaybePost(dir, dep_file_sub_path); - } - - pub fn addDepFilePost(self: *Manifest, dir: Io.Dir, dep_file_sub_path: []const u8) !void { - assert(self.manifest_file != null); - return self.addDepFileMaybePost(dir, dep_file_sub_path); - } - - fn addDepFileMaybePost(self: *Manifest, dir: Io.Dir, dep_file_sub_path: []const u8) !void { - const gpa = self.cache.gpa; - const io = self.cache.io; - const dep_file_contents = try dir.readFileAlloc(io, dep_file_sub_path, gpa, .unlimited); - defer gpa.free(dep_file_contents); - - var error_buf: std.ArrayList(u8) = .empty; - defer error_buf.deinit(gpa); - - var resolve_buf: std.ArrayList(u8) = .empty; - defer resolve_buf.deinit(gpa); - - var it: DepTokenizer = .{ .bytes = dep_file_contents }; - while (it.next()) |token| switch (token) { - // We don't care about targets, we only want the prereqs - // Clang is invoked in single-source mode but other programs may not - .target, .target_must_resolve => {}, - .prereq => |file_path| if (self.manifest_file == null) { - _ = try self.addInputPath(.initCwd(file_path), .{}); - } else try self.addDiscoveredPath(.{ .discovered_path = .{ .unresolved = .initCwd(file_path) } }), - .prereq_must_resolve => { - resolve_buf.clearRetainingCapacity(); - try token.resolve(gpa, &resolve_buf); - if (self.manifest_file == null) { - _ = try self.addInputPath(.initCwd(resolve_buf.items), .{}); - } else try self.addDiscoveredPath(.{ - .discovered_path = .{ .unresolved = .initCwd(resolve_buf.items) }, - }); - }, - else => |err| { - try err.printError(gpa, &error_buf); - log.err("failed parsing {s}: {s}", .{ dep_file_sub_path, error_buf.items }); - return error.InvalidDepFile; - }, - }; - } - /// See also `hitDigestHex`. pub fn hitDigest(m: *Manifest) BinDigest { assert(m.manifest_file != null); @@ -2533,3 +2592,9 @@ test "Manifest with files added after initial hash" { try testing.expect(!mem.eql(u8, &digest1, &digest3)); } } + +test { + _ = Path; + _ = Directory; + _ = DepTokenizer; +} diff --git a/lib/std/Build/Cache/DepTokenizer.zig b/lib/std/Build/Cache/DepTokenizer.zig index 4fe61603c8b768f6a60652f869adb8859a8cd53a..737ff54e55b513ca4792a3049e10a47c4884b828 100644 --- a/lib/std/Build/Cache/DepTokenizer.zig +++ b/lib/std/Build/Cache/DepTokenizer.zig @@ -1,14 +1,15 @@ const Tokenizer = @This(); -index: usize = 0, -bytes: []const u8, -state: State = .lhs, - const std = @import("std"); +const Io = std.Io; const testing = std.testing; const assert = std.debug.assert; const Allocator = std.mem.Allocator; +index: usize = 0, +bytes: []const u8, +state: State = .lhs, + pub fn next(self: *Tokenizer) ?Token { var start = self.index; var must_resolve = false; @@ -16,10 +17,7 @@ pub fn next(self: *Tokenizer) ?Token { const char = self.bytes[self.index]; switch (self.state) { .lhs => switch (char) { - '\t', '\n', '\r', ' ' => { - // silently ignore whitespace - self.index += 1; - }, + '\t', '\n', '\r', ' ' => self.index += 1, // Ignore whitespace. else => { start = self.index; self.state = .target; @@ -79,7 +77,7 @@ pub fn next(self: *Tokenizer) ?Token { self.index += 1; }, else => { - return errorIllegalChar(.expected_dollar_sign, self.index, char); + return errorIllegalChar(.expected_dollar, self.index, char); }, }, .target_colon => switch (char) { @@ -347,7 +345,7 @@ pub const Token = union(enum) { invalid_target: IndexAndChar, bad_target_escape: IndexAndChar, - expected_dollar_sign: IndexAndChar, + expected_dollar: IndexAndChar, continuation_eol: IndexAndChar, incomplete_escape: IndexAndChar, expected_colon: IndexAndChar, @@ -429,48 +427,23 @@ pub const Token = union(enum) { } } - pub fn printError(self: Token, gpa: Allocator, list: *std.ArrayList(u8)) error{OutOfMemory}!void { - switch (self) { - .target, .target_must_resolve, .prereq, .prereq_must_resolve => unreachable, // not an error - .incomplete_quoted_prerequisite, - .incomplete_target, - => |index_and_bytes| { - try list.print(gpa, "{s} '", .{self.errStr()}); - if (self == .incomplete_target) { - const tmp = Token{ .target_must_resolve = index_and_bytes.bytes }; - try tmp.resolve(gpa, list); - } else { - try printCharValues(gpa, list, index_and_bytes.bytes); - } - try list.print(gpa, "' at position {d}", .{index_and_bytes.index}); - }, + pub fn format(token: Token, w: *Io.Writer) Io.Writer.Error!void { + switch (token) { + .target, .target_must_resolve, .prereq, .prereq_must_resolve => return w.writeAll(@tagName(token)), + .incomplete_quoted_prerequisite, .incomplete_target => |info| return w.print("{t} {q} at position {d}", .{ + token, info.bytes, info.index, + }), .invalid_target, .bad_target_escape, - .expected_dollar_sign, + .expected_dollar, .continuation_eol, .incomplete_escape, .expected_colon, - => |index_and_char| { - try list.appendSlice(gpa, "illegal char "); - try printUnderstandableChar(gpa, list, index_and_char.char); - try list.print(gpa, " at position {d}: {s}", .{ index_and_char.index, self.errStr() }); - }, + => |info| return w.print("illegal char '{f}' at position {d}: {t}", .{ + std.zig.fmtChar(info.char), info.index, token, + }), } } - - fn errStr(self: Token) []const u8 { - return switch (self) { - .target, .target_must_resolve, .prereq, .prereq_must_resolve => unreachable, // not an error - .incomplete_quoted_prerequisite => "incomplete quoted prerequisite", - .incomplete_target => "incomplete target", - .invalid_target => "invalid target", - .bad_target_escape => "bad target escape", - .expected_dollar_sign => "expecting '$'", - .continuation_eol => "continuation expecting end-of-line", - .incomplete_escape => "incomplete escape", - .expected_colon => "expecting ':'", - }; - } }; test "empty file" { @@ -493,37 +466,37 @@ test "empty colon" { } test "empty target" { - try depTokenizer("foo.o:", "target = {foo.o}"); + try depTokenizer("foo.o:", "target = {\"foo.o\"}"); try depTokenizer( \\foo.o: \\bar.o: \\abcd.o: , - \\target = {foo.o} - \\target = {bar.o} - \\target = {abcd.o} + \\target = {"foo.o"} + \\target = {"bar.o"} + \\target = {"abcd.o"} ); } test "whitespace empty target" { - try depTokenizer("\nfoo.o:", "target = {foo.o}"); - try depTokenizer("\rfoo.o:", "target = {foo.o}"); - try depTokenizer("\r\nfoo.o:", "target = {foo.o}"); - try depTokenizer(" foo.o:", "target = {foo.o}"); + try depTokenizer("\nfoo.o:", "target = {\"foo.o\"}"); + try depTokenizer("\rfoo.o:", "target = {\"foo.o\"}"); + try depTokenizer("\r\nfoo.o:", "target = {\"foo.o\"}"); + try depTokenizer(" foo.o:", "target = {\"foo.o\"}"); } test "escape empty target" { - try depTokenizer("\\ foo.o:", "target = { foo.o}"); - try depTokenizer("\\#foo.o:", "target = {#foo.o}"); - try depTokenizer("\\\\foo.o:", "target = {\\foo.o}"); - try depTokenizer("$$foo.o:", "target = {$foo.o}"); + try depTokenizer("\\ foo.o:", "target = {\" foo.o\"}"); + try depTokenizer("\\#foo.o:", "target = {\"#foo.o\"}"); + try depTokenizer("\\\\foo.o:", "target = {\"\\\\foo.o\"}"); + try depTokenizer("$$foo.o:", "target = {\"$foo.o\"}"); } test "empty target linefeeds" { try depTokenizer("\n", ""); try depTokenizer("\r\n", ""); - const expect = "target = {foo.o}"; + const expect = "target = {\"foo.o\"}"; try depTokenizer( \\foo.o: , expect); @@ -541,7 +514,7 @@ test "empty target linefeeds" { } test "empty target linefeeds + continuations" { - const expect = "target = {foo.o}"; + const expect = "target = {\"foo.o\"}"; try depTokenizer( \\foo.o:\ , expect); @@ -559,7 +532,7 @@ test "empty target linefeeds + continuations" { } test "empty target linefeeds + hspace + continuations" { - const expect = "target = {foo.o}"; + const expect = "target = {\"foo.o\"}"; try depTokenizer( \\foo.o: \ , expect); @@ -577,7 +550,7 @@ test "empty target linefeeds + hspace + continuations" { } test "empty target + hspace + colon" { - const expect = "target = {foo.o}"; + const expect = "target = {\"foo.o\"}"; try depTokenizer("foo.o :", expect); try depTokenizer("foo.o\t\t\t:", expect); @@ -588,8 +561,8 @@ test "empty target + hspace + colon" { test "prereq" { const expect = - \\target = {foo.o} - \\prereq = {foo.c} + \\target = {"foo.o"} + \\prereq = {"foo.c"} ; try depTokenizer("foo.o: foo.c", expect); try depTokenizer( @@ -608,9 +581,9 @@ test "prereq" { test "prereq continuation" { const expect = - \\target = {foo.o} - \\prereq = {foo.h} - \\prereq = {bar.h} + \\target = {"foo.o"} + \\prereq = {"foo.h"} + \\prereq = {"bar.h"} ; try depTokenizer( \\foo.o: foo.h\ @@ -624,19 +597,19 @@ test "prereq continuation" { test "prereq continuation (CRLF)" { const expect = - \\target = {foo.o} - \\prereq = {foo.h} - \\prereq = {bar.h} + \\target = {"foo.o"} + \\prereq = {"foo.h"} + \\prereq = {"bar.h"} ; try depTokenizer("foo.o: foo.h\\\r\nbar.h", expect); } test "multiple prereqs" { const expect = - \\target = {foo.o} - \\prereq = {foo.c} - \\prereq = {foo.h} - \\prereq = {bar.h} + \\target = {"foo.o"} + \\prereq = {"foo.c"} + \\prereq = {"foo.h"} + \\prereq = {"bar.h"} ; try depTokenizer("foo.o: foo.c foo.h bar.h", expect); try depTokenizer( @@ -680,19 +653,19 @@ test "multiple targets and prereqs" { \\ one.h two.h \ \\ three.h four.h , - \\target = {foo.o} - \\prereq = {foo.c} - \\target = {bar.o} - \\prereq = {bar.c} - \\prereq = {a.h} - \\prereq = {b.h} - \\prereq = {c.h} - \\target = {abc.o} - \\prereq = {abc.c} - \\prereq = {one.h} - \\prereq = {two.h} - \\prereq = {three.h} - \\prereq = {four.h} + \\target = {"foo.o"} + \\prereq = {"foo.c"} + \\target = {"bar.o"} + \\prereq = {"bar.c"} + \\prereq = {"a.h"} + \\prereq = {"b.h"} + \\prereq = {"c.h"} + \\target = {"abc.o"} + \\prereq = {"abc.c"} + \\prereq = {"one.h"} + \\prereq = {"two.h"} + \\prereq = {"three.h"} + \\prereq = {"four.h"} ); try depTokenizer( \\ascii.o: ascii.c @@ -702,21 +675,21 @@ test "multiple targets and prereqs" { \\ macho.c\ \\ a.h b.h c.h , - \\target = {ascii.o} - \\prereq = {ascii.c} - \\target = {base64.o} - \\prereq = {base64.c} - \\prereq = {stdio.h} - \\target = {elf.o} - \\prereq = {elf.c} - \\prereq = {a.h} - \\prereq = {b.h} - \\prereq = {c.h} - \\target = {macho.o} - \\prereq = {macho.c} - \\prereq = {a.h} - \\prereq = {b.h} - \\prereq = {c.h} + \\target = {"ascii.o"} + \\prereq = {"ascii.c"} + \\target = {"base64.o"} + \\prereq = {"base64.c"} + \\prereq = {"stdio.h"} + \\target = {"elf.o"} + \\prereq = {"elf.c"} + \\prereq = {"a.h"} + \\prereq = {"b.h"} + \\prereq = {"c.h"} + \\target = {"macho.o"} + \\prereq = {"macho.c"} + \\prereq = {"a.h"} + \\prereq = {"b.h"} + \\prereq = {"c.h"} ); try depTokenizer( \\a$$scii.o: ascii.c @@ -726,20 +699,20 @@ test "multiple targets and prereqs" { \\ "macho!.c" \ \\ a.h b.h c.h , - \\target = {a$scii.o} - \\prereq = {ascii.c} - \\target = {\base64.o} - \\prereq = {\base64.c} - \\prereq = {s t#dio.h} - \\target = {e\lf.o} - \\prereq = {e\lf.c} - \\prereq = {a.h$$} - \\prereq = {$$b.h c.h$$} - \\target = {macho.o} - \\prereq = {macho!.c} - \\prereq = {a.h} - \\prereq = {b.h} - \\prereq = {c.h} + \\target = {"a$scii.o"} + \\prereq = {"ascii.c"} + \\target = {"\\base64.o"} + \\prereq = {"\\base64.c"} + \\prereq = {"s t#dio.h"} + \\target = {"e\\lf.o"} + \\prereq = {"e\\lf.c"} + \\prereq = {"a.h$$"} + \\prereq = {"$$b.h c.h$$"} + \\target = {"macho.o"} + \\prereq = {"macho!.c"} + \\prereq = {"a.h"} + \\prereq = {"b.h"} + \\prereq = {"c.h"} ); } @@ -750,12 +723,12 @@ test "windows quoted prereqs" { \\ "C:\Program Files (x86)\Microsoft Visual Studio\foo1.h" \ \\ "C:\Program Files (x86)\Microsoft Visual Studio\foo2.h" , - \\target = {c:\foo.o} - \\prereq = {C:\Program Files (x86)\Microsoft Visual Studio\foo.c} - \\target = {c:\foo2.o} - \\prereq = {C:\Program Files (x86)\Microsoft Visual Studio\foo2.c} - \\prereq = {C:\Program Files (x86)\Microsoft Visual Studio\foo1.h} - \\prereq = {C:\Program Files (x86)\Microsoft Visual Studio\foo2.h} + \\target = {"c:\\foo.o"} + \\prereq = {"C:\\Program Files (x86)\\Microsoft Visual Studio\\foo.c"} + \\target = {"c:\\foo2.o"} + \\prereq = {"C:\\Program Files (x86)\\Microsoft Visual Studio\\foo2.c"} + \\prereq = {"C:\\Program Files (x86)\\Microsoft Visual Studio\\foo1.h"} + \\prereq = {"C:\\Program Files (x86)\\Microsoft Visual Studio\\foo2.h"} ); } @@ -779,23 +752,23 @@ test "windows mixed prereqs" { \\ "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.21.27702\lib\x64\\..\..\include\vcruntime_string.h" \ \\ "C:\Program Files (x86)\Windows Kits\10\\Include\10.0.17763.0\ucrt\corecrt_wstring.h" , - \\target = {cimport.o} - \\prereq = {C:\msys64\home\anon\project\zig\master\zig-cache\o\qhvhbUo7GU5iKyQ5mpA8TcQpncCYaQu0wwvr3ybiSTj_Dtqi1Nmcb70kfODJ2Qlg\cimport.h} - \\prereq = {C:\Program Files (x86)\Windows Kits\10\\Include\10.0.17763.0\ucrt\stdio.h} - \\prereq = {C:\Program Files (x86)\Windows Kits\10\\Include\10.0.17763.0\ucrt\corecrt.h} - \\prereq = {C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.21.27702\lib\x64\\..\..\include\vcruntime.h} - \\prereq = {C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.21.27702\lib\x64\\..\..\include\sal.h} - \\prereq = {C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.21.27702\lib\x64\\..\..\include\concurrencysal.h} - \\prereq = {C:\msys64\opt\zig\lib\zig\include\vadefs.h} - \\prereq = {C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.21.27702\lib\x64\\..\..\include\vadefs.h} - \\prereq = {C:\Program Files (x86)\Windows Kits\10\\Include\10.0.17763.0\ucrt\corecrt_wstdio.h} - \\prereq = {C:\Program Files (x86)\Windows Kits\10\\Include\10.0.17763.0\ucrt\corecrt_stdio_config.h} - \\prereq = {C:\Program Files (x86)\Windows Kits\10\\Include\10.0.17763.0\ucrt\string.h} - \\prereq = {C:\Program Files (x86)\Windows Kits\10\\Include\10.0.17763.0\ucrt\corecrt_memory.h} - \\prereq = {C:\Program Files (x86)\Windows Kits\10\\Include\10.0.17763.0\ucrt\corecrt_memcpy_s.h} - \\prereq = {C:\Program Files (x86)\Windows Kits\10\\Include\10.0.17763.0\ucrt\errno.h} - \\prereq = {C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.21.27702\lib\x64\\..\..\include\vcruntime_string.h} - \\prereq = {C:\Program Files (x86)\Windows Kits\10\\Include\10.0.17763.0\ucrt\corecrt_wstring.h} + \\target = {"cimport.o"} + \\prereq = {"C:\\msys64\\home\\anon\\project\\zig\\master\\zig-cache\\o\\qhvhbUo7GU5iKyQ5mpA8TcQpncCYaQu0wwvr3ybiSTj_Dtqi1Nmcb70kfODJ2Qlg\\cimport.h"} + \\prereq = {"C:\\Program Files (x86)\\Windows Kits\\10\\\\Include\\10.0.17763.0\\ucrt\\stdio.h"} + \\prereq = {"C:\\Program Files (x86)\\Windows Kits\\10\\\\Include\\10.0.17763.0\\ucrt\\corecrt.h"} + \\prereq = {"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.21.27702\\lib\\x64\\\\..\\..\\include\\vcruntime.h"} + \\prereq = {"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.21.27702\\lib\\x64\\\\..\\..\\include\\sal.h"} + \\prereq = {"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.21.27702\\lib\\x64\\\\..\\..\\include\\concurrencysal.h"} + \\prereq = {"C:\\msys64\\opt\\zig\\lib\\zig\\include\\vadefs.h"} + \\prereq = {"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.21.27702\\lib\\x64\\\\..\\..\\include\\vadefs.h"} + \\prereq = {"C:\\Program Files (x86)\\Windows Kits\\10\\\\Include\\10.0.17763.0\\ucrt\\corecrt_wstdio.h"} + \\prereq = {"C:\\Program Files (x86)\\Windows Kits\\10\\\\Include\\10.0.17763.0\\ucrt\\corecrt_stdio_config.h"} + \\prereq = {"C:\\Program Files (x86)\\Windows Kits\\10\\\\Include\\10.0.17763.0\\ucrt\\string.h"} + \\prereq = {"C:\\Program Files (x86)\\Windows Kits\\10\\\\Include\\10.0.17763.0\\ucrt\\corecrt_memory.h"} + \\prereq = {"C:\\Program Files (x86)\\Windows Kits\\10\\\\Include\\10.0.17763.0\\ucrt\\corecrt_memcpy_s.h"} + \\prereq = {"C:\\Program Files (x86)\\Windows Kits\\10\\\\Include\\10.0.17763.0\\ucrt\\errno.h"} + \\prereq = {"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.21.27702\\lib\\x64\\\\..\\..\\include\\vcruntime_string.h"} + \\prereq = {"C:\\Program Files (x86)\\Windows Kits\\10\\\\Include\\10.0.17763.0\\ucrt\\corecrt_wstring.h"} ); } @@ -810,14 +783,14 @@ test "windows funky targets" { \\C:\Users\anon\$$foo.o: \\C:\Users\anon\\\ \ \ \ \ foo.o: , - \\target = {C:\Users\anon\foo.o} - \\target = {C:\Users\anon\foo .o} - \\target = {C:\Users\anon\foo#.o} - \\target = {C:\Users\anon\foo$.o} - \\target = {C:\Users\anon\ foo.o} - \\target = {C:\Users\anon\#foo.o} - \\target = {C:\Users\anon\$foo.o} - \\target = {C:\Users\anon\ foo.o} + \\target = {"C:\\Users\\anon\\foo.o"} + \\target = {"C:\\Users\\anon\\foo .o"} + \\target = {"C:\\Users\\anon\\foo#.o"} + \\target = {"C:\\Users\\anon\\foo$.o"} + \\target = {"C:\\Users\\anon\\ foo.o"} + \\target = {"C:\\Users\\anon\\#foo.o"} + \\target = {"C:\\Users\\anon\\$foo.o"} + \\target = {"C:\\Users\\anon\\ foo.o"} ); } @@ -837,13 +810,13 @@ test "windows funky prereqs" { \\ somedir\\ \\ \c.c\ \\ , - \\target = {cimport.o} - \\prereq = {trailingbackslash\} - \\prereq = {C:\Users\John Smith\AppData\Local\zig\p\1220d14057af1a9d6dde4643293527bd5ee5099517d655251a066666a4320737ea7c\cimport.c} - \\prereq = {somedir\ a.c} - \\prereq = {somedir/ a.c} - \\prereq = {somedir\ b.c} - \\prereq = {somedir\ \ \c.c} + \\target = {"cimport.o"} + \\prereq = {"trailingbackslash\\"} + \\prereq = {"C:\\Users\\John Smith\\AppData\\Local\\zig\\p\\1220d14057af1a9d6dde4643293527bd5ee5099517d655251a066666a4320737ea7c\\cimport.c"} + \\prereq = {"somedir\\ a.c"} + \\prereq = {"somedir/ a.c"} + \\prereq = {"somedir\\ b.c"} + \\prereq = {"somedir\\ \\ \\c.c"} ); } @@ -852,171 +825,171 @@ test "windows drive and forward slashes" { \\C:/msys64/what/zig-cache\tmp\48ac4d78dd531abd-cxa_thread_atexit.obj: \ \\ C:/msys64/opt/zig3/lib/zig/libc/mingw/crt/cxa_thread_atexit.c , - \\target = {C:/msys64/what/zig-cache\tmp\48ac4d78dd531abd-cxa_thread_atexit.obj} - \\prereq = {C:/msys64/opt/zig3/lib/zig/libc/mingw/crt/cxa_thread_atexit.c} + \\target = {"C:/msys64/what/zig-cache\\tmp\\48ac4d78dd531abd-cxa_thread_atexit.obj"} + \\prereq = {"C:/msys64/opt/zig3/lib/zig/libc/mingw/crt/cxa_thread_atexit.c"} ); } test "error incomplete escape - reverse_solidus" { try depTokenizer("\\", - \\ERROR: illegal char '\' at position 0: incomplete escape + \\ERROR: illegal char '\\' at position 0: incomplete_escape ); try depTokenizer("\t\\", - \\ERROR: illegal char '\' at position 1: incomplete escape + \\ERROR: illegal char '\\' at position 1: incomplete_escape ); try depTokenizer("\n\\", - \\ERROR: illegal char '\' at position 1: incomplete escape + \\ERROR: illegal char '\\' at position 1: incomplete_escape ); try depTokenizer("\r\\", - \\ERROR: illegal char '\' at position 1: incomplete escape + \\ERROR: illegal char '\\' at position 1: incomplete_escape ); try depTokenizer("\r\n\\", - \\ERROR: illegal char '\' at position 2: incomplete escape + \\ERROR: illegal char '\\' at position 2: incomplete_escape ); try depTokenizer(" \\", - \\ERROR: illegal char '\' at position 1: incomplete escape + \\ERROR: illegal char '\\' at position 1: incomplete_escape ); } test "error incomplete escape - dollar_sign" { try depTokenizer("$", - \\ERROR: illegal char '$' at position 0: incomplete escape + \\ERROR: illegal char '$' at position 0: incomplete_escape ); try depTokenizer("\t$", - \\ERROR: illegal char '$' at position 1: incomplete escape + \\ERROR: illegal char '$' at position 1: incomplete_escape ); try depTokenizer("\n$", - \\ERROR: illegal char '$' at position 1: incomplete escape + \\ERROR: illegal char '$' at position 1: incomplete_escape ); try depTokenizer("\r$", - \\ERROR: illegal char '$' at position 1: incomplete escape + \\ERROR: illegal char '$' at position 1: incomplete_escape ); try depTokenizer("\r\n$", - \\ERROR: illegal char '$' at position 2: incomplete escape + \\ERROR: illegal char '$' at position 2: incomplete_escape ); try depTokenizer(" $", - \\ERROR: illegal char '$' at position 1: incomplete escape + \\ERROR: illegal char '$' at position 1: incomplete_escape ); } test "error incomplete target" { try depTokenizer("foo.o", - \\ERROR: incomplete target 'foo.o' at position 0 + \\ERROR: incomplete_target "foo.o" at position 0 ); try depTokenizer("\tfoo.o", - \\ERROR: incomplete target 'foo.o' at position 1 + \\ERROR: incomplete_target "foo.o" at position 1 ); try depTokenizer("\nfoo.o", - \\ERROR: incomplete target 'foo.o' at position 1 + \\ERROR: incomplete_target "foo.o" at position 1 ); try depTokenizer("\rfoo.o", - \\ERROR: incomplete target 'foo.o' at position 1 + \\ERROR: incomplete_target "foo.o" at position 1 ); try depTokenizer("\r\nfoo.o", - \\ERROR: incomplete target 'foo.o' at position 2 + \\ERROR: incomplete_target "foo.o" at position 2 ); try depTokenizer(" foo.o", - \\ERROR: incomplete target 'foo.o' at position 1 + \\ERROR: incomplete_target "foo.o" at position 1 ); try depTokenizer("\\ foo.o", - \\ERROR: incomplete target ' foo.o' at position 0 + \\ERROR: incomplete_target "\\ foo.o" at position 0 ); try depTokenizer("\\#foo.o", - \\ERROR: incomplete target '#foo.o' at position 0 + \\ERROR: incomplete_target "\\#foo.o" at position 0 ); try depTokenizer("\\\\foo.o", - \\ERROR: incomplete target '\foo.o' at position 0 + \\ERROR: incomplete_target "\\\\foo.o" at position 0 ); try depTokenizer("$$foo.o", - \\ERROR: incomplete target '$foo.o' at position 0 + \\ERROR: incomplete_target "$$foo.o" at position 0 ); } test "error illegal char at position - bad target escape" { try depTokenizer("\\\t", - \\ERROR: illegal char \x09 at position 1: bad target escape + \\ERROR: illegal char '\t' at position 1: bad_target_escape ); try depTokenizer("\\\n", - \\ERROR: illegal char \x0A at position 1: bad target escape + \\ERROR: illegal char '\n' at position 1: bad_target_escape ); try depTokenizer("\\\r", - \\ERROR: illegal char \x0D at position 1: bad target escape + \\ERROR: illegal char '\r' at position 1: bad_target_escape ); try depTokenizer("\\\r\n", - \\ERROR: illegal char \x0D at position 1: bad target escape + \\ERROR: illegal char '\r' at position 1: bad_target_escape ); } test "error illegal char at position - expecting dollar_sign" { try depTokenizer("$\t", - \\ERROR: illegal char \x09 at position 1: expecting '$' + \\ERROR: illegal char '\t' at position 1: expected_dollar ); try depTokenizer("$\n", - \\ERROR: illegal char \x0A at position 1: expecting '$' + \\ERROR: illegal char '\n' at position 1: expected_dollar ); try depTokenizer("$\r", - \\ERROR: illegal char \x0D at position 1: expecting '$' + \\ERROR: illegal char '\r' at position 1: expected_dollar ); try depTokenizer("$\r\n", - \\ERROR: illegal char \x0D at position 1: expecting '$' + \\ERROR: illegal char '\r' at position 1: expected_dollar ); } test "error illegal char at position - invalid target" { try depTokenizer("foo\n.o", - \\ERROR: illegal char \x0A at position 3: invalid target + \\ERROR: illegal char '\n' at position 3: invalid_target ); try depTokenizer("foo\r.o", - \\ERROR: illegal char \x0D at position 3: invalid target + \\ERROR: illegal char '\r' at position 3: invalid_target ); try depTokenizer("foo\r\n.o", - \\ERROR: illegal char \x0D at position 3: invalid target + \\ERROR: illegal char '\r' at position 3: invalid_target ); } test "error target - continuation expecting end-of-line" { try depTokenizer("foo.o: \\\t", - \\target = {foo.o} - \\ERROR: illegal char \x09 at position 8: continuation expecting end-of-line + \\target = {"foo.o"} + \\ERROR: illegal char '\t' at position 8: continuation_eol ); try depTokenizer("foo.o: \\ ", - \\target = {foo.o} - \\ERROR: illegal char ' ' at position 8: continuation expecting end-of-line + \\target = {"foo.o"} + \\ERROR: illegal char ' ' at position 8: continuation_eol ); try depTokenizer("foo.o: \\x", - \\target = {foo.o} - \\ERROR: illegal char 'x' at position 8: continuation expecting end-of-line + \\target = {"foo.o"} + \\ERROR: illegal char 'x' at position 8: continuation_eol ); try depTokenizer("foo.o: \\\x0dx", - \\target = {foo.o} - \\ERROR: illegal char 'x' at position 9: continuation expecting end-of-line + \\target = {"foo.o"} + \\ERROR: illegal char 'x' at position 9: continuation_eol ); } test "error prereq - continuation expecting end-of-line" { try depTokenizer("foo.o: foo.h\\\x0dx", - \\target = {foo.o} - \\ERROR: illegal char 'x' at position 14: continuation expecting end-of-line + \\target = {"foo.o"} + \\ERROR: illegal char 'x' at position 14: continuation_eol ); } test "error illegal char at position - expecting colon" { try depTokenizer("foo\t.o:", - \\target = {foo} - \\ERROR: illegal char '.' at position 4: expecting ':' + \\target = {"foo"} + \\ERROR: illegal char '.' at position 4: expected_colon ); try depTokenizer("foo .o:", - \\target = {foo} - \\ERROR: illegal char '.' at position 4: expecting ':' + \\target = {"foo"} + \\ERROR: illegal char '.' at position 4: expected_colon ); try depTokenizer("foo \n.o:", - \\target = {foo} - \\ERROR: illegal char \x0A at position 4: expecting ':' + \\target = {"foo"} + \\ERROR: illegal char '\n' at position 4: expected_colon ); try depTokenizer("foo.o\t\n:", - \\target = {foo.o} - \\ERROR: illegal char \x0A at position 6: expecting ':' + \\target = {"foo.o"} + \\ERROR: illegal char '\n' at position 6: expected_colon ); } @@ -1028,70 +1001,35 @@ fn depTokenizer(input: []const u8, expect: []const u8) !void { var it: Tokenizer = .{ .bytes = input }; var buffer: std.ArrayList(u8) = .empty; - var resolve_buf: std.ArrayList(u8) = .empty; + var aux: std.ArrayList(u8) = .empty; var i: usize = 0; while (it.next()) |token| { if (i != 0) try buffer.appendSlice(arena, "\n"); switch (token) { .target, .prereq => |bytes| { - try buffer.appendSlice(arena, @tagName(token)); - try buffer.appendSlice(arena, " = {"); - for (bytes) |b| { - try buffer.append(arena, printable_char_tab[b]); - } - try buffer.appendSlice(arena, "}"); + try buffer.print(arena, "{t} = {{{q}}}", .{ token, bytes }); }, .target_must_resolve => { try buffer.appendSlice(arena, "target = {"); - try token.resolve(arena, &resolve_buf); - for (resolve_buf.items) |b| { - try buffer.append(arena, printable_char_tab[b]); - } - resolve_buf.items.len = 0; + aux.clearRetainingCapacity(); + try token.resolve(arena, &aux); + try buffer.print(arena, "{q}", .{aux.items}); try buffer.appendSlice(arena, "}"); }, .prereq_must_resolve => { try buffer.appendSlice(arena, "prereq = {"); - try token.resolve(arena, &resolve_buf); - for (resolve_buf.items) |b| { - try buffer.append(arena, printable_char_tab[b]); - } - resolve_buf.items.len = 0; + aux.clearRetainingCapacity(); + try token.resolve(arena, &aux); + try buffer.print(arena, "{q}", .{aux.items}); try buffer.appendSlice(arena, "}"); }, else => { - try buffer.appendSlice(arena, "ERROR: "); - try token.printError(arena, &buffer); + try buffer.print(arena, "ERROR: {f}", .{token}); break; }, } i += 1; } - if (std.mem.eql(u8, expect, buffer.items)) { - try testing.expect(true); - return; - } - try testing.expectEqualStrings(expect, buffer.items); } - -fn printCharValues(gpa: Allocator, list: *std.ArrayList(u8), bytes: []const u8) !void { - for (bytes) |b| try list.append(gpa, printable_char_tab[b]); -} - -fn printUnderstandableChar(gpa: Allocator, list: *std.ArrayList(u8), char: u8) !void { - if (std.ascii.isPrint(char)) { - try list.print(gpa, "'{c}'", .{char}); - } else { - try list.print(gpa, "\\x{X:0>2}", .{char}); - } -} - -// zig fmt: off -const printable_char_tab: [256]u8 = ( - "................................ !\"#$%&'()*+,-./0123456789:;<=>?" ++ - "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~." ++ - "................................................................" ++ - "................................................................" -).*; diff --git a/src/Compilation.zig b/src/Compilation.zig index 6599e8c34085ae331173e65edf15112e090c104d..bc2bbbc18d94efc51a1726071482bc7a173ed9bc 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -5094,9 +5094,13 @@ pub fn translateC( try @import("main.zig").translateC(gpa, arena, io, argv.items, environ_map, prog_node, comp.thread_limit, &stdout); if (out_dep_path) |dep_file_path| add_deps: { + var diagnostic: Cache.Manifest.AddDiscoveredDepFileDiagnostic = undefined; const dep_basename = fs.path.basename(dep_file_path); // Add the files depended on to the cache system, if a dep file was emitted - man.addDepFilePost(cache_tmp_dir, dep_basename) catch |err| switch (err) { + man.addDiscoveredDepFile(.{ + .root_dir = .{ .handle = cache_tmp_dir, .path = tmp_sub_path }, + .sub_path = dep_basename, + }, &diagnostic) catch |err| switch (err) { error.FileNotFound => break :add_deps, else => |e| return e, }; @@ -5105,14 +5109,17 @@ pub fn translateC( .whole => |whole| if (whole.cache_manifest) |whole_cache_manifest| { try whole.cache_manifest_mutex.lock(io); defer whole.cache_manifest_mutex.unlock(io); - try whole_cache_manifest.addDepFilePost(cache_tmp_dir, dep_basename); + try whole_cache_manifest.addDiscoveredDepFile(.{ + .root_dir = .{ .handle = cache_tmp_dir, .path = tmp_sub_path }, + .sub_path = dep_basename, + }, &diagnostic); }, .incremental, .none => {}, } // Just to save disk space, we delete the file because it is never needed again. cache_tmp_dir.deleteFile(io, dep_basename) catch |err| { - log.warn("failed to delete '{s}': {t}", .{ dep_file_path, err }); + log.warn("failed to delete dep file {q}: {t}", .{ dep_file_path, err }); }; } @@ -5527,7 +5534,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr const target = comp.getTarget(); assert(target.ofmt != .c); const o_ext = target.ofmt.fileExt(target.cpu.arch); - const digest = if (!comp.disable_c_depfile and try man.check(child_progress_node)) man.final() else blk: { + const digest = if (!comp.disable_c_depfile and .hit == try man.check(child_progress_node)) man.hitDigestHex() else miss: { var argv: std.array_list.Managed([]const u8) = .init(gpa); defer argv.deinit(); @@ -5654,11 +5661,11 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr // Just to save disk space, we delete the files that are never needed again. defer if (out_diag_path) |diag_file_path| zig_cache_tmp_dir.deleteFile(io, fs.path.basename(diag_file_path)) catch |err| switch (err) { error.FileNotFound => {}, // the file wasn't created due to an error we reported - else => log.warn("failed to delete '{s}': {s}", .{ diag_file_path, @errorName(err) }), + else => log.warn("failed to delete {q}: {t}", .{ diag_file_path, err }), }; defer if (out_dep_path) |dep_file_path| zig_cache_tmp_dir.deleteFile(io, fs.path.basename(dep_file_path)) catch |err| switch (err) { error.FileNotFound => {}, // the file wasn't created due to an error we reported - else => log.warn("failed to delete '{s}': {s}", .{ dep_file_path, @errorName(err) }), + else => log.warn("failed to delete {q}: {t}", .{ dep_file_path, err }), }; if (std.process.can_spawn) { if (comp.clang_passthrough_mode) { @@ -5747,8 +5754,10 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr const dep_basename = fs.path.basename(dep_file_path); if (comp.file_system_inputs != null) { + // TODO instead of this rely on passing the manifest contents directly + // Use the same file size limit as the cache code does for dependency files. - const dep_file_contents = try zig_cache_tmp_dir.readFileAlloc(io, dep_basename, gpa, .limited(Cache.manifest_file_size_max)); + const dep_file_contents = try zig_cache_tmp_dir.readFileAlloc(io, dep_basename, gpa, .unlimited); defer gpa.free(dep_file_contents); var str_buf: std.ArrayList(u8) = .empty; @@ -5763,9 +5772,8 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr try token.resolve(gpa, &str_buf); break :p try .fromUnresolved(arena, comp.dirs, &.{str_buf.items}); }, - else => |err| { - try err.printError(gpa, &str_buf); - log.err("failed parsing {s}: {s}", .{ dep_basename, str_buf.items }); + else => |err_token| { + log.err("failed parsing {s}: {f}", .{ dep_basename, err_token }); return error.InvalidDepFile; }, }; @@ -5774,13 +5782,26 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr } // Add the files depended on to the cache system. - try man.addDepFilePost(zig_cache_tmp_dir, dep_basename); + var diagnostic: Cache.Manifest.AddDiscoveredDepFileDiagnostic = undefined; + try man.addDiscoveredDepFile(.{ + .root_dir = .{ + .handle = zig_cache_tmp_dir, + .path = "tmp", + }, + .sub_path = dep_basename, + }, &diagnostic); switch (comp.cache_use) { .whole => |whole| { if (whole.cache_manifest) |whole_cache_manifest| { try whole.cache_manifest_mutex.lock(io); defer whole.cache_manifest_mutex.unlock(io); - try whole_cache_manifest.addDepFilePost(zig_cache_tmp_dir, dep_basename); + try whole_cache_manifest.addDiscoveredDepFile(.{ + .root_dir = .{ + .handle = zig_cache_tmp_dir, + .path = "tmp", + }, + .sub_path = dep_basename, + }, &diagnostic); } }, .incremental, .none => {}, @@ -5791,13 +5812,13 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr if (comp.disable_c_depfile) _ = try man.check(child_progress_node); // Rename into place. - const digest = man.final(); - const o_sub_path = try fs.path.join(arena, &[_][]const u8{ "o", &digest }); + const digest = man.missDigestHex(); + const o_sub_path = try fs.path.join(arena, &.{ "o", &digest }); var o_dir = try comp.dirs.local_cache.handle.createDirPathOpen(io, o_sub_path, .{}); defer o_dir.close(io); const tmp_basename = fs.path.basename(out_obj_path); try Io.Dir.rename(zig_cache_tmp_dir, tmp_basename, o_dir, o_basename, io); - break :blk digest; + break :miss digest; }; if (man.have_exclusive_lock) { diff --git a/src/libs/freebsd.zig b/src/libs/freebsd.zig index b02b3569af70d363eb73619f7bdd7cd514e0d1cc..36062854757ac0b1369c0712031f80e806f453f4 100644 --- a/src/libs/freebsd.zig +++ b/src/libs/freebsd.zig @@ -465,9 +465,8 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye .request_contents = true, }); - if (try man.check(prog_node)) { - const digest = man.final(); - + if (.hit == try man.check(prog_node)) { + const digest = man.hitDigestHex(); return queueSharedObjects(comp, .{ .lock = man.toOwnedLock(), .dir_path = .{ @@ -477,7 +476,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye }); } - const digest = man.final(); + const digest = man.missDigestHex(); const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest }); var o_directory: Cache.Directory = .{ @@ -486,7 +485,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye }; defer o_directory.handle.close(io); - const abilists_contents = man.files.keys()[abilists_index].contents.?; + const abilists_contents = abilists_index.contents(&man); const metadata = try loadMetaData(gpa, abilists_contents); defer metadata.destroy(gpa); diff --git a/src/libs/glibc.zig b/src/libs/glibc.zig index 08b9214d6db5d64a8fef5dcf4dde164e9f7f9f12..691da1bd0f047f527c37c4b850cdceea7dd036a8 100644 --- a/src/libs/glibc.zig +++ b/src/libs/glibc.zig @@ -705,9 +705,8 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye .request_contents = true, }); - if (try man.check(prog_node)) { - const digest = man.final(); - + if (.hit == try man.check(prog_node)) { + const digest = man.hitDigestHex(); return queueSharedObjects(comp, .{ .lock = man.toOwnedLock(), .dir_path = .{ @@ -717,8 +716,8 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye }); } - const digest = man.final(); - const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest }); + const digest = man.missDigestHex(); + const o_sub_path = try path.join(arena, &.{ "o", &digest }); var o_directory: Cache.Directory = .{ .handle = try comp.dirs.global_cache.handle.createDirPathOpen(io, o_sub_path, .{}), @@ -726,7 +725,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye }; defer o_directory.handle.close(io); - const abilists_contents = man.files.keys()[abilists_index].contents.?; + const abilists_contents = abilists_index.contents(&man); const metadata = try loadMetaData(gpa, abilists_contents); defer metadata.destroy(gpa); diff --git a/src/libs/netbsd.zig b/src/libs/netbsd.zig index 9d120d46ae2db878175c5ff5b84c8ebf7eaf7c9b..5445f5fcaab4906ada5cc8950ef403fb4fc825f6 100644 --- a/src/libs/netbsd.zig +++ b/src/libs/netbsd.zig @@ -413,9 +413,8 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye .request_contents = true, }); - if (try man.check(prog_node)) { - const digest = man.final(); - + if (.hit == try man.check(prog_node)) { + const digest = man.hitDigestHex(); return queueSharedObjects(comp, .{ .lock = man.toOwnedLock(), .dir_path = .{ @@ -425,8 +424,8 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye }); } - const digest = man.final(); - const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest }); + const digest = man.missDigestHex(); + const o_sub_path = try path.join(arena, &.{ "o", &digest }); var o_directory: Cache.Directory = .{ .handle = try comp.dirs.global_cache.handle.createDirPathOpen(io, o_sub_path, .{}), @@ -434,7 +433,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye }; defer o_directory.handle.close(io); - const abilists_contents = man.files.keys()[abilists_index].contents.?; + const abilists_contents = abilists_index.contents(&man); const metadata = try loadMetaData(gpa, abilists_contents); defer metadata.destroy(gpa); diff --git a/src/libs/openbsd.zig b/src/libs/openbsd.zig index e65fc524967c09300979897a0e5dd089e5fd8ad1..ab126f2a96aa9dce467620052d07a5af8f965e49 100644 --- a/src/libs/openbsd.zig +++ b/src/libs/openbsd.zig @@ -334,9 +334,8 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye .request_contents = true, }); - if (try man.check(prog_node)) { - const digest = man.final(); - + if (.hit == try man.check(prog_node)) { + const digest = man.hitDigestHex(); return queueSharedObjects(comp, .{ .lock = man.toOwnedLock(), .dir_path = .{ @@ -346,7 +345,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye }); } - const digest = man.final(); + const digest = man.missDigestHex(); const o_sub_path = try path.join(arena, &[_][]const u8{ "o", &digest }); var o_directory: Cache.Directory = .{ @@ -355,7 +354,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye }; defer o_directory.handle.close(io); - const abilists_contents = man.files.keys()[abilists_index].contents.?; + const abilists_contents = abilists_index.contents(&man); const metadata = try loadMetaData(gpa, abilists_contents); defer metadata.destroy(gpa);