authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-03-08 20:26:03 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-03-08 20:26:03 -08:00
log7d322ed64d0f4ff70634dd8a268b2f9d352a814d
tree2aabf259e4cbec7c55d589b8451695d847454f8d
parentd680d06973dd0a13c9561ba7d01f1d7892653091

make Module not store an Allocator reference


3 files changed, 7 insertions(+), 12 deletions(-)

src/cmd/sum.zig+1-1
......@@ -37,7 +37,7 @@ pub fn execute(args: [][]u8) !void {
3737 continue;
3838 }
3939 if (m.is_sys_lib or m.is_framework) continue;
40 const hash = try m.get_hash(cachepath);
40 const hash = try m.get_hash(gpa, cachepath);
4141 try w.print("{s} {s}\n", .{ hash, m.clean_path });
4242 }
4343}
src/common.zig-3
......@@ -48,7 +48,6 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO
4848 }
4949 }
5050 return zigmod.Module{
51 .alloc = options.alloc,
5251 .is_sys_lib = false,
5352 .is_framework = false,
5453 .id = "root",
......@@ -78,7 +77,6 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOption
7877 }
7978 }
8079 return zigmod.Module{
81 .alloc = options.alloc,
8280 .is_sys_lib = false,
8381 .is_framework = false,
8482 .id = m.id,
......@@ -231,7 +229,6 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
231229 switch (d.type) {
232230 .system_lib, .framework => {
233231 return zigmod.Module{
234 .alloc = options.alloc,
235232 .is_sys_lib = d.type == .system_lib,
236233 .is_framework = d.type == .framework,
237234 .id = try u.do_hash(options.alloc, std.crypto.hash.sha3.Sha3_384, d.path),
src/util/module.zig+6-8
......@@ -11,7 +11,6 @@ const common = @import("./../common.zig");
1111//
1212
1313pub const Module = struct {
14 alloc: std.mem.Allocator,
1514 is_sys_lib: bool,
1615 is_framework: bool,
1716 id: string,
......@@ -40,7 +39,6 @@ pub const Module = struct {
4039 }
4140 }
4241 return Module{
43 .alloc = alloc,
4442 .is_sys_lib = false,
4543 .is_framework = false,
4644 .id = if (dep.id.len > 0) dep.id else try u.random_string(alloc, 48),
......@@ -65,10 +63,10 @@ pub const Module = struct {
6563 return std.mem.eql(u8, self.id, another.id);
6664 }
6765
68 pub fn get_hash(self: Module, cdpath: string) !string {
69 const file_list_1 = try u.file_list(self.alloc, try std.mem.concat(self.alloc, u8, &.{ cdpath, "/", self.clean_path }));
66 pub fn get_hash(self: Module, alloc: std.mem.Allocator, cdpath: string) !string {
67 const file_list_1 = try u.file_list(alloc, try std.mem.concat(alloc, u8, &.{ cdpath, "/", self.clean_path }));
7068
71 var file_list_2 = std.ArrayList(string).init(self.alloc);
69 var file_list_2 = std.ArrayList(string).init(alloc);
7270 defer file_list_2.deinit();
7371 for (file_list_1) |item| {
7472 const _a = u.trim_prefix(item, cdpath);
......@@ -86,15 +84,15 @@ pub const Module = struct {
8684
8785 const h = &std.crypto.hash.Blake3.init(.{});
8886 for (file_list_2.items) |item| {
89 const abs_path = try std.fs.path.join(self.alloc, &.{ cdpath, self.clean_path, item });
87 const abs_path = try std.fs.path.join(alloc, &.{ cdpath, self.clean_path, item });
9088 const file = try std.fs.cwd().openFile(abs_path, .{});
9189 defer file.close();
92 const input = try file.reader().readAllAlloc(self.alloc, u.mb * 100);
90 const input = try file.reader().readAllAlloc(alloc, u.mb * 100);
9391 h.update(input);
9492 }
9593 var out: [32]u8 = undefined;
9694 h.final(&out);
97 const hex = try std.fmt.allocPrint(self.alloc, "blake3-{x}", .{std.fmt.fmtSliceHexLower(out[0..])});
95 const hex = try std.fmt.allocPrint(alloc, "blake3-{x}", .{std.fmt.fmtSliceHexLower(out[0..])});
9896 return hex;
9997 }
10098