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 {...@@ -37,7 +37,7 @@ pub fn execute(args: [][]u8) !void {
37 continue;37 continue;
38 }38 }
39 if (m.is_sys_lib or m.is_framework) continue;39 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);
41 try w.print("{s} {s}\n", .{ hash, m.clean_path });41 try w.print("{s} {s}\n", .{ hash, m.clean_path });
42 }42 }
43}43}
src/common.zig-3
...@@ -48,7 +48,6 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO...@@ -48,7 +48,6 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO
48 }48 }
49 }49 }
50 return zigmod.Module{50 return zigmod.Module{
51 .alloc = options.alloc,
52 .is_sys_lib = false,51 .is_sys_lib = false,
53 .is_framework = false,52 .is_framework = false,
54 .id = "root",53 .id = "root",
...@@ -78,7 +77,6 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOption...@@ -78,7 +77,6 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOption
78 }77 }
79 }78 }
80 return zigmod.Module{79 return zigmod.Module{
81 .alloc = options.alloc,
82 .is_sys_lib = false,80 .is_sys_lib = false,
83 .is_framework = false,81 .is_framework = false,
84 .id = m.id,82 .id = m.id,
...@@ -231,7 +229,6 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO...@@ -231,7 +229,6 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
231 switch (d.type) {229 switch (d.type) {
232 .system_lib, .framework => {230 .system_lib, .framework => {
233 return zigmod.Module{231 return zigmod.Module{
234 .alloc = options.alloc,
235 .is_sys_lib = d.type == .system_lib,232 .is_sys_lib = d.type == .system_lib,
236 .is_framework = d.type == .framework,233 .is_framework = d.type == .framework,
237 .id = try u.do_hash(options.alloc, std.crypto.hash.sha3.Sha3_384, d.path),234 .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");...@@ -11,7 +11,6 @@ const common = @import("./../common.zig");
11//11//
1212
13pub const Module = struct {13pub const Module = struct {
14 alloc: std.mem.Allocator,
15 is_sys_lib: bool,14 is_sys_lib: bool,
16 is_framework: bool,15 is_framework: bool,
17 id: string,16 id: string,
...@@ -40,7 +39,6 @@ pub const Module = struct {...@@ -40,7 +39,6 @@ pub const Module = struct {
40 }39 }
41 }40 }
42 return Module{41 return Module{
43 .alloc = alloc,
44 .is_sys_lib = false,42 .is_sys_lib = false,
45 .is_framework = false,43 .is_framework = false,
46 .id = if (dep.id.len > 0) dep.id else try u.random_string(alloc, 48),44 .id = if (dep.id.len > 0) dep.id else try u.random_string(alloc, 48),
...@@ -65,10 +63,10 @@ pub const Module = struct {...@@ -65,10 +63,10 @@ pub const Module = struct {
65 return std.mem.eql(u8, self.id, another.id);63 return std.mem.eql(u8, self.id, another.id);
66 }64 }
6765
68 pub fn get_hash(self: Module, cdpath: string) !string {66 pub fn get_hash(self: Module, alloc: std.mem.Allocator, 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 }));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);
72 defer file_list_2.deinit();70 defer file_list_2.deinit();
73 for (file_list_1) |item| {71 for (file_list_1) |item| {
74 const _a = u.trim_prefix(item, cdpath);72 const _a = u.trim_prefix(item, cdpath);
...@@ -86,15 +84,15 @@ pub const Module = struct {...@@ -86,15 +84,15 @@ pub const Module = struct {
8684
87 const h = &std.crypto.hash.Blake3.init(.{});85 const h = &std.crypto.hash.Blake3.init(.{});
88 for (file_list_2.items) |item| {86 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 });
90 const file = try std.fs.cwd().openFile(abs_path, .{});88 const file = try std.fs.cwd().openFile(abs_path, .{});
91 defer file.close();89 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);
93 h.update(input);91 h.update(input);
94 }92 }
95 var out: [32]u8 = undefined;93 var out: [32]u8 = undefined;
96 h.final(&out);94 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..])});
98 return hex;96 return hex;
99 }97 }
10098