authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-03-08 19:46:00 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-03-08 19:46:00 -08:00
logd680d06973dd0a13c9561ba7d01f1d7892653091
tree54c7340d08237082161ee4c1eb3ea171bf3fa05d
parent3a142ec8ec15b9d20600e42f3a997f7f6056a9da

make Dep not store an Allocator reference


5 files changed, 14 insertions(+), 18 deletions(-)

src/cmd/fetch.zig+1-1
......@@ -146,7 +146,7 @@ fn create_lockfile(alloc: std.mem.Allocator, list: *std.ArrayList(zigmod.Module)
146146 if (m.dep) |md| {
147147 if (md.type.isLocal()) continue;
148148 const mpath = try std.fs.path.join(alloc, &.{ path, m.clean_path });
149 const version = try md.exact_version(mpath);
149 const version = try md.exact_version(alloc, mpath);
150150 try wl.print("{s} {s} {s}\n", .{ @tagName(md.type), md.path, version });
151151 }
152152 }
src/common.zig+4-6
......@@ -107,8 +107,8 @@ pub fn collect_pkgs(mod: zigmod.Module, list: *std.ArrayList(zigmod.Module)) any
107107}
108108
109109pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !string {
110 const p = try std.fs.path.join(options.alloc, &.{ cachepath, try d.clean_path() });
111 const pv = try std.fs.path.join(options.alloc, &.{ cachepath, try d.clean_path_v() });
110 const p = try std.fs.path.join(options.alloc, &.{ cachepath, try d.clean_path(options.alloc) });
111 const pv = try std.fs.path.join(options.alloc, &.{ cachepath, try d.clean_path_v(options.alloc) });
112112
113113 const nocache = d.type.isLocal();
114114 if (!nocache and u.list_contains(options.already_fetched.items, p)) return p;
......@@ -213,7 +213,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
213213pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectOptions) anyerror!?zigmod.Module {
214214 if (options.lock) |lock| {
215215 for (lock) |item| {
216 if (std.mem.eql(u8, item[0], try d.clean_path())) {
216 if (std.mem.eql(u8, item[0], try d.clean_path(options.alloc))) {
217217 d.type = std.meta.stringToEnum(zigmod.DepType, item[1]).?;
218218 d.path = item[2];
219219 d.version = item[3];
......@@ -334,7 +334,6 @@ pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, pkg_name:
334334 }
335335
336336 var d: zigmod.Dep = .{
337 .alloc = alloc,
338337 .type = .local,
339338 .path = "files",
340339 .id = "",
......@@ -379,7 +378,6 @@ pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]str
379378 2 => {
380379 var iter = std.mem.split(u8, line, " ");
381380 const asdep = zigmod.Dep{
382 .alloc = alloc,
383381 .type = std.meta.stringToEnum(zigmod.DepType, iter.next().?).?,
384382 .path = iter.next().?,
385383 .version = iter.next().?,
......@@ -390,7 +388,7 @@ pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]str
390388 .deps = &.{},
391389 };
392390 try list.append([4]string{
393 try asdep.clean_path(),
391 try asdep.clean_path(alloc),
394392 @tagName(asdep.type),
395393 asdep.path,
396394 asdep.version,
src/util/dep.zig+8-9
......@@ -12,7 +12,6 @@ const yaml = @import("./yaml.zig");
1212pub const Dep = struct {
1313 const Self = @This();
1414
15 alloc: std.mem.Allocator,
1615 type: zigmod.DepType,
1716 path: string,
1817 id: string,
......@@ -30,7 +29,7 @@ pub const Dep = struct {
3029 vcpkg: bool = false,
3130 for_build: bool = false,
3231
33 pub fn clean_path(self: Dep) !string {
32 pub fn clean_path(self: Dep, alloc: std.mem.Allocator) !string {
3433 if (self.type == .local) {
3534 return if (self.path.len == 0) "../.." else self.path;
3635 }
......@@ -39,16 +38,16 @@ pub const Dep = struct {
3938 p = u.trim_prefix(p, "https://");
4039 p = u.trim_prefix(p, "git://");
4140 p = u.trim_suffix(p, ".git");
42 p = try std.mem.join(self.alloc, "/", &.{ @tagName(self.type), p });
41 p = try std.mem.join(alloc, "/", &.{ @tagName(self.type), p });
4342 return p;
4443 }
4544
46 pub fn clean_path_v(self: Dep) !string {
45 pub fn clean_path_v(self: Dep, alloc: std.mem.Allocator) !string {
4746 if (self.type == .http and self.version.len > 0) {
4847 const i = std.mem.indexOf(u8, self.version, "-").?;
49 return std.mem.join(self.alloc, "/", &.{ "v", try self.clean_path(), self.version[i + 1 .. 15] });
48 return std.mem.join(alloc, "/", &.{ "v", try self.clean_path(alloc), self.version[i + 1 .. 15] });
5049 }
51 return std.mem.join(self.alloc, "/", &.{ "v", try self.clean_path(), self.version });
50 return std.mem.join(alloc, "/", &.{ "v", try self.clean_path(alloc), self.version });
5251 }
5352
5453 pub fn is_for_this(self: Dep) bool {
......@@ -62,15 +61,15 @@ pub const Dep = struct {
6261 return true;
6362 }
6463
65 pub fn exact_version(self: Dep, dpath: string) !string {
64 pub fn exact_version(self: Dep, alloc: std.mem.Allocator, dpath: string) !string {
6665 if (self.version.len == 0) {
67 return try self.type.exact_version(self.alloc, dpath);
66 return try self.type.exact_version(alloc, dpath);
6867 }
6968 return switch (self.type) {
7069 .git => blk: {
7170 const vers = try u.parse_split(zigmod.DepType.GitVersion, "-").do(self.version);
7271 if (vers.id.frozen()) break :blk self.version;
73 break :blk try self.type.exact_version(self.alloc, dpath);
72 break :blk try self.type.exact_version(alloc, dpath);
7473 },
7574 else => self.version,
7675 };
src/util/modfile.zig-1
......@@ -123,7 +123,6 @@ pub const ModFile = struct {
123123 }
124124
125125 try dep_list.append(zigmod.Dep{
126 .alloc = alloc,
127126 .type = dep_type,
128127 .path = path,
129128 .id = item.mapping.get_string("id"),
src/util/module.zig+1-1
......@@ -50,7 +50,7 @@ pub const Module = struct {
5050 .c_source_flags = dep.c_source_flags,
5151 .c_source_files = dep.c_source_files,
5252 .deps = moddeps.toOwnedSlice(),
53 .clean_path = try dep.clean_path(),
53 .clean_path = try dep.clean_path(alloc),
5454 .only_os = dep.only_os,
5555 .except_os = dep.except_os,
5656 .yaml = dep.yaml,