diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2024-03-07 06:26:25 +0000 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2024-03-07 06:26:25 +0000 |
| commit | 38331b1cabf86586bdf70c80ed98f74c60305160 (patch) | |
| tree | 875824cf56e06fd8b4b38eb6d203ba829a35da6d /src/Package/Module.zig | |
| parent | b41a0b4768d368d81d0d33c779f919d8f315e622 (diff) | |
| download | zig-38331b1cabf86586bdf70c80ed98f74c60305160.tar.gz zig-38331b1cabf86586bdf70c80ed98f74c60305160.zip | |
Package.Module: actually set File.path_digest for builtin modules
Diffstat (limited to 'src/Package/Module.zig')
| -rw-r--r-- | src/Package/Module.zig | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/Package/Module.zig b/src/Package/Module.zig index e5376ed93a..c6eb1e8c90 100644 --- a/src/Package/Module.zig +++ b/src/Package/Module.zig @@ -381,8 +381,25 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { const new_file = try arena.create(File); - const digest = Cache.HashHelper.oneShot(generated_builtin_source); - const builtin_sub_path = try arena.dupe(u8, "b" ++ std.fs.path.sep_str ++ digest); + const bin_digest, const hex_digest = digest: { + var hasher: Cache.Hasher = Cache.hasher_init; + hasher.update(generated_builtin_source); + + var bin_digest: Cache.BinDigest = undefined; + hasher.final(&bin_digest); + + var hex_digest: Cache.HexDigest = undefined; + _ = std.fmt.bufPrint( + &hex_digest, + "{s}", + .{std.fmt.fmtSliceHexLower(&bin_digest)}, + ) catch unreachable; + + break :digest .{ bin_digest, hex_digest }; + }; + + const builtin_sub_path = try arena.dupe(u8, "b" ++ std.fs.path.sep_str ++ hex_digest); + new.* = .{ .root = .{ .root_dir = options.global_cache_directory, @@ -429,6 +446,9 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { .status = .never_loaded, .mod = new, .root_decl = .none, + // We might as well use this digest for the File `path digest`, since there's a + // one-to-one correspondence here between distinct paths and distinct contents. + .path_digest = bin_digest, }; break :b new; }; |
