authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2023-12-11 23:08:03+01:00
committergravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2023-12-11 23:08:03+01:00
log26e27f5f644437526b5ed5cad6559db8250bb545
treeb126f859fd57ab7927f02297f28ccba54a43440f
parent69195d0cd43468f213332c5792df04c941f8313d

std.Build.Cache: add HexDigest type


1 files changed, 15 insertions(+), 14 deletions(-)

lib/std/Build/Cache.zig+15-14
...@@ -179,6 +179,7 @@ fn getPrefixSubpath(allocator: Allocator, prefix: []const u8, path: []u8) ![]u8...@@ -179,6 +179,7 @@ fn getPrefixSubpath(allocator: Allocator, prefix: []const u8, path: []u8) ![]u8
179pub const bin_digest_len = 16;179pub const bin_digest_len = 16;
180pub const hex_digest_len = bin_digest_len * 2;180pub const hex_digest_len = bin_digest_len * 2;
181pub const BinDigest = [bin_digest_len]u8;181pub const BinDigest = [bin_digest_len]u8;
182pub const HexDigest = [hex_digest_len]u8;
182183
183/// This is currently just an arbitrary non-empty string that can't match another manifest line.184/// This is currently just an arbitrary non-empty string that can't match another manifest line.
184const manifest_header = "0";185const manifest_header = "0";
...@@ -300,11 +301,11 @@ pub const HashHelper = struct {...@@ -300,11 +301,11 @@ pub const HashHelper = struct {
300 }301 }
301302
302 /// Returns a hex encoded hash of the inputs, mutating the state of the hasher.303 /// Returns a hex encoded hash of the inputs, mutating the state of the hasher.
303 pub fn final(hh: *HashHelper) [hex_digest_len]u8 {304 pub fn final(hh: *HashHelper) HexDigest {
304 var bin_digest: BinDigest = undefined;305 var bin_digest: BinDigest = undefined;
305 hh.hasher.final(&bin_digest);306 hh.hasher.final(&bin_digest);
306307
307 var out_digest: [hex_digest_len]u8 = undefined;308 var out_digest: HexDigest = undefined;
308 _ = fmt.bufPrint(309 _ = fmt.bufPrint(
309 &out_digest,310 &out_digest,
310 "{s}",311 "{s}",
...@@ -346,7 +347,7 @@ pub const Manifest = struct {...@@ -346,7 +347,7 @@ pub const Manifest = struct {
346 // will then use the same timestamp, to avoid unnecessary filesystem writes.347 // will then use the same timestamp, to avoid unnecessary filesystem writes.
347 want_refresh_timestamp: bool = true,348 want_refresh_timestamp: bool = true,
348 files: std.ArrayListUnmanaged(File) = .{},349 files: std.ArrayListUnmanaged(File) = .{},
349 hex_digest: [hex_digest_len]u8,350 hex_digest: HexDigest,
350 /// Populated when hit() returns an error because of one351 /// Populated when hit() returns an error because of one
351 /// of the files listed in the manifest.352 /// of the files listed in the manifest.
352 failed_file_index: ?usize = null,353 failed_file_index: ?usize = null,
...@@ -829,7 +830,7 @@ pub const Manifest = struct {...@@ -829,7 +830,7 @@ pub const Manifest = struct {
829 }830 }
830831
831 /// Returns a hex encoded hash of the inputs.832 /// Returns a hex encoded hash of the inputs.
832 pub fn final(self: *Manifest) [hex_digest_len]u8 {833 pub fn final(self: *Manifest) HexDigest {
833 assert(self.manifest_file != null);834 assert(self.manifest_file != null);
834835
835 // We don't close the manifest file yet, because we want to836 // We don't close the manifest file yet, because we want to
...@@ -841,7 +842,7 @@ pub const Manifest = struct {...@@ -841,7 +842,7 @@ pub const Manifest = struct {
841 var bin_digest: BinDigest = undefined;842 var bin_digest: BinDigest = undefined;
842 self.hash.hasher.final(&bin_digest);843 self.hash.hasher.final(&bin_digest);
843844
844 var out_digest: [hex_digest_len]u8 = undefined;845 var out_digest: HexDigest = undefined;
845 _ = fmt.bufPrint(846 _ = fmt.bufPrint(
846 &out_digest,847 &out_digest,
847 "{s}",848 "{s}",
...@@ -1021,8 +1022,8 @@ test "cache file and then recall it" {...@@ -1021,8 +1022,8 @@ test "cache file and then recall it" {
1021 std.time.sleep(1);1022 std.time.sleep(1);
1022 }1023 }
10231024
1024 var digest1: [hex_digest_len]u8 = undefined;1025 var digest1: HexDigest = undefined;
1025 var digest2: [hex_digest_len]u8 = undefined;1026 var digest2: HexDigest = undefined;
10261027
1027 {1028 {
1028 var cache = Cache{1029 var cache = Cache{
...@@ -1089,8 +1090,8 @@ test "check that changing a file makes cache fail" {...@@ -1089,8 +1090,8 @@ test "check that changing a file makes cache fail" {
1089 std.time.sleep(1);1090 std.time.sleep(1);
1090 }1091 }
10911092
1092 var digest1: [hex_digest_len]u8 = undefined;1093 var digest1: HexDigest = undefined;
1093 var digest2: [hex_digest_len]u8 = undefined;1094 var digest2: HexDigest = undefined;
10941095
1095 {1096 {
1096 var cache = Cache{1097 var cache = Cache{
...@@ -1152,8 +1153,8 @@ test "no file inputs" {...@@ -1152,8 +1153,8 @@ test "no file inputs" {
11521153
1153 const temp_manifest_dir = "no_file_inputs_manifest_dir";1154 const temp_manifest_dir = "no_file_inputs_manifest_dir";
11541155
1155 var digest1: [hex_digest_len]u8 = undefined;1156 var digest1: HexDigest = undefined;
1156 var digest2: [hex_digest_len]u8 = undefined;1157 var digest2: HexDigest = undefined;
11571158
1158 var cache = Cache{1159 var cache = Cache{
1159 .gpa = testing.allocator,1160 .gpa = testing.allocator,
...@@ -1211,9 +1212,9 @@ test "Manifest with files added after initial hash work" {...@@ -1211,9 +1212,9 @@ test "Manifest with files added after initial hash work" {
1211 std.time.sleep(1);1212 std.time.sleep(1);
1212 }1213 }
12131214
1214 var digest1: [hex_digest_len]u8 = undefined;1215 var digest1: HexDigest = undefined;
1215 var digest2: [hex_digest_len]u8 = undefined;1216 var digest2: HexDigest = undefined;
1216 var digest3: [hex_digest_len]u8 = undefined;1217 var digest3: HexDigest = undefined;
12171218
1218 {1219 {
1219 var cache = Cache{1220 var cache = Cache{