| ... | ... | @@ -0,0 +1,56 @@ |
| 1 | const std = @import("std"); |
| 2 | const gpa = std.heap.c_allocator; |
| 3 | |
| 4 | const u = @import("./util/index.zig"); |
| 5 | |
| 6 | // |
| 7 | // |
| 8 | |
| 9 | pub fn collect_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 10 | const m = try u.ModFile.init(gpa, mpath); |
| 11 | const moduledeps = &std.ArrayList(u.Module).init(gpa); |
| 12 | var moddir: []const u8 = undefined; |
| 13 | for (m.deps) |d| { |
| 14 | const p = try u.concat(&[_][]const u8{dir, "/deps/", try d.clean_path()}); |
| 15 | const pv = try u.concat(&[_][]const u8{dir, "/v/", try d.clean_path(), "/", d.version}); |
| 16 | if (try u.does_file_exist(pv)) { |
| 17 | moddir = pv; |
| 18 | } else { |
| 19 | u.assert(try u.does_file_exist(p), "unable to find dep: {} {}, please run zigmod fetch", .{d.path, d.version}); |
| 20 | moddir = p; |
| 21 | } |
| 22 | switch (d.type) { |
| 23 | else => blk: { |
| 24 | var dd = try collect_deps(dir, try u.concat(&[_][]const u8{moddir, "/zig.mod"})) catch |e| switch (e) { |
| 25 | error.FileNotFound => { |
| 26 | if (d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { |
| 27 | var mod_from = try u.Module.from(d); |
| 28 | mod_from.clean_path = u.trim_prefix(moddir, dir)[1..]; |
| 29 | try moduledeps.append(mod_from); |
| 30 | } |
| 31 | break :blk; |
| 32 | }, |
| 33 | else => e, |
| 34 | }; |
| 35 | dd.clean_path = u.trim_prefix(moddir, dir)[1..]; |
| 36 | |
| 37 | if (d.name.len > 0) dd.name = d.name; |
| 38 | if (d.main.len > 0) dd.main = d.main; |
| 39 | if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs; |
| 40 | if (d.c_source_flags.len > 0) dd.c_source_flags = d.c_source_flags; |
| 41 | if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files; |
| 42 | |
| 43 | try moduledeps.append(dd); |
| 44 | }, |
| 45 | } |
| 46 | } |
| 47 | return u.Module{ |
| 48 | .name = m.name, |
| 49 | .main = m.main, |
| 50 | .c_include_dirs = m.c_include_dirs, |
| 51 | .c_source_flags = m.c_source_flags, |
| 52 | .c_source_files = m.c_source_files, |
| 53 | .deps = moduledeps.items, |
| 54 | .clean_path = "", |
| 55 | }; |
| 56 | } |