| ... | ... | @@ -3,6 +3,7 @@ const gpa = std.heap.c_allocator; |
| 3 | 3 | |
| 4 | 4 | const u = @import("./util/index.zig"); |
| 5 | 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 | 12 | log: bool, |
| 12 | 13 | update: bool, |
| 13 | 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 | 25 | const m = try u.ModFile.init(gpa, mpath); |
| 26 | try options.init(); |
| 18 | 27 | const moduledeps = &std.ArrayList(u.Module).init(gpa); |
| 19 | 28 | defer moduledeps.deinit(); |
| 20 | 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 | 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 | 52 | const m = try u.ModFile.init(gpa, mpath); |
| 44 | 53 | const moduledeps = &std.ArrayList(u.Module).init(gpa); |
| 45 | 54 | defer moduledeps.deinit(); |
| ... | ... | @@ -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 | 89 | const p = try std.fs.path.join(gpa, &.{ basedir, try d.clean_path() }); |
| 81 | 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 | 95 | const tempdir = try std.fs.path.join(gpa, &.{ basedir, "temp" }); |
| 83 | 96 | if (options.log and d.type != .local) { |
| 84 | 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 | 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 | 191 | if (options.lock) |lock| { |
| 179 | 192 | for (lock) |item| { |
| 180 | 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 | 199 | } |
| 187 | 200 | } |
| 188 | 201 | const moddir = try get_moddir(dir, d.*, parent_name, options); |
| 202 | try options.already_fetched.append(moddir); |
| 189 | 203 | switch (d.type) { |
| 190 | 204 | .system_lib => { |
| 191 | 205 | return u.Module{ |
| ... | ... | @@ -286,10 +300,11 @@ fn add_files_package(pkg_name: []const u8, dirs: []const []const u8, parent_name |
| 286 | 300 | .yaml = null, |
| 287 | 301 | .deps = &.{}, |
| 288 | 302 | }; |
| 289 | | return (try get_module_from_dep(&d, destination, parent_name, .{ |
| 303 | var options = CollectOptions{ |
| 290 | 304 | .log = false, |
| 291 | 305 | .update = false, |
| 292 | | })).?; |
| 306 | }; |
| 307 | return (try get_module_from_dep(&d, destination, parent_name, &options)).?; |
| 293 | 308 | } |
| 294 | 309 | |
| 295 | 310 | pub fn parse_lockfile(path: []const u8) ![]const [4][]const u8 { |