| ... | @@ -3,6 +3,7 @@ const gpa = std.heap.c_allocator; | ... | @@ -3,6 +3,7 @@ const gpa = std.heap.c_allocator; |
| 3 | | 3 | |
| 4 | const u = @import("./util/index.zig"); | 4 | const u = @import("./util/index.zig"); |
| 5 | const yaml = @import("./util/yaml.zig"); | 5 | const yaml = @import("./util/yaml.zig"); |
| | 6 | const string = []const u8; |
| 6 | | 7 | |
| 7 | // | 8 | // |
| 8 | // | 9 | // |
| ... | @@ -11,10 +12,18 @@ pub const CollectOptions = struct { | ... | @@ -11,10 +12,18 @@ pub const CollectOptions = struct { |
| 11 | log: bool, | 12 | log: bool, |
| 12 | update: bool, | 13 | update: bool, |
| 13 | lock: ?[]const [4][]const u8 = null, | 14 | lock: ?[]const [4][]const u8 = null, |
| | 15 | alloc: *std.mem.Allocator = gpa, |
| | 16 | already_fetched: *std.ArrayList(string) = undefined, |
| | 17 | |
| | 18 | pub fn init(self: *CollectOptions) !void { |
| | 19 | self.already_fetched = try self.alloc.create(std.ArrayList(string)); |
| | 20 | self.already_fetched.* = std.ArrayList(string).init(self.alloc); |
| | 21 | } |
| 14 | }; | 22 | }; |
| 15 | | 23 | |
| 16 | pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: CollectOptions) !u.Module { | 24 | pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: *CollectOptions) !u.Module { |
| 17 | const m = try u.ModFile.init(gpa, mpath); | 25 | const m = try u.ModFile.init(gpa, mpath); |
| | 26 | try options.init(); |
| 18 | const moduledeps = &std.ArrayList(u.Module).init(gpa); | 27 | const moduledeps = &std.ArrayList(u.Module).init(gpa); |
| 19 | defer moduledeps.deinit(); | 28 | defer moduledeps.deinit(); |
| 20 | try std.fs.cwd().makePath(".zigmod/deps/files"); | 29 | try std.fs.cwd().makePath(".zigmod/deps/files"); |
| ... | @@ -39,7 +48,7 @@ pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: CollectOpt | ... | @@ -39,7 +48,7 @@ pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: CollectOpt |
| 39 | }; | 48 | }; |
| 40 | } | 49 | } |
| 41 | | 50 | |
| 42 | pub fn collect_deps(dir: []const u8, mpath: []const u8, options: CollectOptions) anyerror!u.Module { | 51 | pub fn collect_deps(dir: []const u8, mpath: []const u8, options: *CollectOptions) anyerror!u.Module { |
| 43 | const m = try u.ModFile.init(gpa, mpath); | 52 | const m = try u.ModFile.init(gpa, mpath); |
| 44 | const moduledeps = &std.ArrayList(u.Module).init(gpa); | 53 | const moduledeps = &std.ArrayList(u.Module).init(gpa); |
| 45 | defer moduledeps.deinit(); | 54 | defer moduledeps.deinit(); |
| ... | @@ -76,9 +85,13 @@ pub fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void | ... | @@ -76,9 +85,13 @@ pub fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void |
| 76 | } | 85 | } |
| 77 | } | 86 | } |
| 78 | | 87 | |
| 79 | fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, options: CollectOptions) ![]const u8 { | 88 | fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, options: *CollectOptions) ![]const u8 { |
| 80 | const p = try std.fs.path.join(gpa, &.{ basedir, try d.clean_path() }); | 89 | const p = try std.fs.path.join(gpa, &.{ basedir, try d.clean_path() }); |
| 81 | const pv = try std.fs.path.join(gpa, &.{ basedir, try d.clean_path_v() }); | 90 | const pv = try std.fs.path.join(gpa, &.{ basedir, try d.clean_path_v() }); |
| | 91 | |
| | 92 | if (u.list_contains(options.already_fetched.items, p)) return p; |
| | 93 | if (u.list_contains(options.already_fetched.items, pv)) return pv; |
| | 94 | |
| 82 | const tempdir = try std.fs.path.join(gpa, &.{ basedir, "temp" }); | 95 | const tempdir = try std.fs.path.join(gpa, &.{ basedir, "temp" }); |
| 83 | if (options.log and d.type != .local) { | 96 | if (options.log and d.type != .local) { |
| 84 | u.print("fetch: {s}: {s}: {s}", .{ parent_name, @tagName(d.type), d.path }); | 97 | u.print("fetch: {s}: {s}: {s}", .{ parent_name, @tagName(d.type), d.path }); |
| ... | @@ -174,7 +187,7 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, options: C | ... | @@ -174,7 +187,7 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, options: C |
| 174 | } | 187 | } |
| 175 | } | 188 | } |
| 176 | | 189 | |
| 177 | pub fn get_module_from_dep(d: *u.Dep, dir: []const u8, parent_name: []const u8, options: CollectOptions) anyerror!?u.Module { | 190 | pub fn get_module_from_dep(d: *u.Dep, dir: []const u8, parent_name: []const u8, options: *CollectOptions) anyerror!?u.Module { |
| 178 | if (options.lock) |lock| { | 191 | if (options.lock) |lock| { |
| 179 | for (lock) |item| { | 192 | for (lock) |item| { |
| 180 | if (std.mem.eql(u8, item[0], try d.clean_path())) { | 193 | if (std.mem.eql(u8, item[0], try d.clean_path())) { |
| ... | @@ -186,6 +199,7 @@ pub fn get_module_from_dep(d: *u.Dep, dir: []const u8, parent_name: []const u8, | ... | @@ -186,6 +199,7 @@ pub fn get_module_from_dep(d: *u.Dep, dir: []const u8, parent_name: []const u8, |
| 186 | } | 199 | } |
| 187 | } | 200 | } |
| 188 | const moddir = try get_moddir(dir, d.*, parent_name, options); | 201 | const moddir = try get_moddir(dir, d.*, parent_name, options); |
| | 202 | try options.already_fetched.append(moddir); |
| 189 | switch (d.type) { | 203 | switch (d.type) { |
| 190 | .system_lib => { | 204 | .system_lib => { |
| 191 | return u.Module{ | 205 | return u.Module{ |
| ... | @@ -286,10 +300,11 @@ fn add_files_package(pkg_name: []const u8, dirs: []const []const u8, parent_name | ... | @@ -286,10 +300,11 @@ fn add_files_package(pkg_name: []const u8, dirs: []const []const u8, parent_name |
| 286 | .yaml = null, | 300 | .yaml = null, |
| 287 | .deps = &.{}, | 301 | .deps = &.{}, |
| 288 | }; | 302 | }; |
| 289 | return (try get_module_from_dep(&d, destination, parent_name, .{ | 303 | var options = CollectOptions{ |
| 290 | .log = false, | 304 | .log = false, |
| 291 | .update = false, | 305 | .update = false, |
| 292 | })).?; | 306 | }; |
| | 307 | return (try get_module_from_dep(&d, destination, parent_name, &options)).?; |
| 293 | } | 308 | } |
| 294 | | 309 | |
| 295 | pub fn parse_lockfile(path: []const u8) ![]const [4][]const u8 { | 310 | pub fn parse_lockfile(path: []const u8) ![]const [4][]const u8 { |