diff --git a/src/cmd/fetch.zig b/src/cmd/fetch.zig index 1c11d063d4f457d12609fdd3e7ccc334e434625f..e121ac998df2f94956ca8d2383008495754f5454 100644 --- a/src/cmd/fetch.zig +++ b/src/cmd/fetch.zig @@ -146,7 +146,7 @@ fn create_lockfile(alloc: std.mem.Allocator, list: *std.ArrayList(zigmod.Module) if (m.dep) |md| { if (md.type.isLocal()) continue; const mpath = try std.fs.path.join(alloc, &.{ path, m.clean_path }); - const version = try md.exact_version(mpath); + const version = try md.exact_version(alloc, mpath); try wl.print("{s} {s} {s}\n", .{ @tagName(md.type), md.path, version }); } } diff --git a/src/common.zig b/src/common.zig index f055fdac778fed296460432b867aca941fe02327..b8f2e84fc48293d19f10856b983324f27be8bdb1 100644 --- a/src/common.zig +++ b/src/common.zig @@ -107,8 +107,8 @@ pub fn collect_pkgs(mod: zigmod.Module, list: *std.ArrayList(zigmod.Module)) any } pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !string { - const p = try std.fs.path.join(options.alloc, &.{ cachepath, try d.clean_path() }); - const pv = try std.fs.path.join(options.alloc, &.{ cachepath, try d.clean_path_v() }); + const p = try std.fs.path.join(options.alloc, &.{ cachepath, try d.clean_path(options.alloc) }); + const pv = try std.fs.path.join(options.alloc, &.{ cachepath, try d.clean_path_v(options.alloc) }); const nocache = d.type.isLocal(); 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) ! pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectOptions) anyerror!?zigmod.Module { if (options.lock) |lock| { for (lock) |item| { - if (std.mem.eql(u8, item[0], try d.clean_path())) { + if (std.mem.eql(u8, item[0], try d.clean_path(options.alloc))) { d.type = std.meta.stringToEnum(zigmod.DepType, item[1]).?; d.path = item[2]; d.version = item[3]; @@ -334,7 +334,6 @@ pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, pkg_name: } var d: zigmod.Dep = .{ - .alloc = alloc, .type = .local, .path = "files", .id = "", @@ -379,7 +378,6 @@ pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]str 2 => { var iter = std.mem.split(u8, line, " "); const asdep = zigmod.Dep{ - .alloc = alloc, .type = std.meta.stringToEnum(zigmod.DepType, iter.next().?).?, .path = iter.next().?, .version = iter.next().?, @@ -390,7 +388,7 @@ pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]str .deps = &.{}, }; try list.append([4]string{ - try asdep.clean_path(), + try asdep.clean_path(alloc), @tagName(asdep.type), asdep.path, asdep.version, diff --git a/src/util/dep.zig b/src/util/dep.zig index c29e57b0dc99525c61c00b25d9e2d7f7eb0c8c18..a7455997306c3bcd0f0098e54c5ad6f9d5c21a1d 100644 --- a/src/util/dep.zig +++ b/src/util/dep.zig @@ -12,7 +12,6 @@ const yaml = @import("./yaml.zig"); pub const Dep = struct { const Self = @This(); - alloc: std.mem.Allocator, type: zigmod.DepType, path: string, id: string, @@ -30,7 +29,7 @@ pub const Dep = struct { vcpkg: bool = false, for_build: bool = false, - pub fn clean_path(self: Dep) !string { + pub fn clean_path(self: Dep, alloc: std.mem.Allocator) !string { if (self.type == .local) { return if (self.path.len == 0) "../.." else self.path; } @@ -39,16 +38,16 @@ pub const Dep = struct { p = u.trim_prefix(p, "https://"); p = u.trim_prefix(p, "git://"); p = u.trim_suffix(p, ".git"); - p = try std.mem.join(self.alloc, "/", &.{ @tagName(self.type), p }); + p = try std.mem.join(alloc, "/", &.{ @tagName(self.type), p }); return p; } - pub fn clean_path_v(self: Dep) !string { + pub fn clean_path_v(self: Dep, alloc: std.mem.Allocator) !string { if (self.type == .http and self.version.len > 0) { const i = std.mem.indexOf(u8, self.version, "-").?; - return std.mem.join(self.alloc, "/", &.{ "v", try self.clean_path(), self.version[i + 1 .. 15] }); + return std.mem.join(alloc, "/", &.{ "v", try self.clean_path(alloc), self.version[i + 1 .. 15] }); } - return std.mem.join(self.alloc, "/", &.{ "v", try self.clean_path(), self.version }); + return std.mem.join(alloc, "/", &.{ "v", try self.clean_path(alloc), self.version }); } pub fn is_for_this(self: Dep) bool { @@ -62,15 +61,15 @@ pub const Dep = struct { return true; } - pub fn exact_version(self: Dep, dpath: string) !string { + pub fn exact_version(self: Dep, alloc: std.mem.Allocator, dpath: string) !string { if (self.version.len == 0) { - return try self.type.exact_version(self.alloc, dpath); + return try self.type.exact_version(alloc, dpath); } return switch (self.type) { .git => blk: { const vers = try u.parse_split(zigmod.DepType.GitVersion, "-").do(self.version); if (vers.id.frozen()) break :blk self.version; - break :blk try self.type.exact_version(self.alloc, dpath); + break :blk try self.type.exact_version(alloc, dpath); }, else => self.version, }; diff --git a/src/util/modfile.zig b/src/util/modfile.zig index e3cda2deefa877de5a57a02d6f10ae9959853e8d..263b9619a61a541beb733d694a577148a2b73108 100644 --- a/src/util/modfile.zig +++ b/src/util/modfile.zig @@ -123,7 +123,6 @@ pub const ModFile = struct { } try dep_list.append(zigmod.Dep{ - .alloc = alloc, .type = dep_type, .path = path, .id = item.mapping.get_string("id"), diff --git a/src/util/module.zig b/src/util/module.zig index a3890466d0bbdd042436eaac2720a6395d33cc25..9f5401fe8e17a225f864bd9711bfe6983b6e4403 100644 --- a/src/util/module.zig +++ b/src/util/module.zig @@ -50,7 +50,7 @@ pub const Module = struct { .c_source_flags = dep.c_source_flags, .c_source_files = dep.c_source_files, .deps = moddeps.toOwnedSlice(), - .clean_path = try dep.clean_path(), + .clean_path = try dep.clean_path(alloc), .only_os = dep.only_os, .except_os = dep.except_os, .yaml = dep.yaml,