| ... | ... | @@ -12,7 +12,7 @@ pub fn execute(args: [][]u8) !void { |
| 12 | 12 | const home = try known_folders.getPath(gpa, .home); |
| 13 | 13 | const dir = try std.fmt.allocPrint(gpa, "{}{}", .{home, "/.cache/zigmod/deps"}); |
| 14 | 14 | |
| 15 | | try fetch_deps(dir, "./zig.mod"); |
| 15 | const top_module = try fetch_deps(dir, "./zig.mod"); |
| 16 | 16 | |
| 17 | 17 | // |
| 18 | 18 | const f = try std.fs.cwd().createFile("./deps.zig", .{}); |
| ... | ... | @@ -34,12 +34,13 @@ pub fn execute(args: [][]u8) !void { |
| 34 | 34 | }); |
| 35 | 35 | try w.print("\n", .{}); |
| 36 | 36 | try w.print("pub const packages = ", .{}); |
| 37 | | try print_deps(w, dir, try u.ModFile.init(gpa, "./zig.mod"), 0); |
| 37 | try print_deps(w, dir, top_module, 0); |
| 38 | 38 | try w.print(";\n", .{}); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | | fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!void { |
| 41 | fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 42 | 42 | const m = try u.ModFile.init(gpa, mpath); |
| 43 | const moduledeps = &std.ArrayList(u.Module).init(gpa); |
| 43 | 44 | for (m.deps) |d| { |
| 44 | 45 | const p = try std.fmt.allocPrint(gpa, "{}{}{}", .{dir, "/", try d.clean_path()}); |
| 45 | 46 | switch (d.type) { |
| ... | ... | @@ -56,10 +57,18 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!void { |
| 56 | 57 | } |
| 57 | 58 | switch (d.type) { |
| 58 | 59 | else => { |
| 59 | | try fetch_deps(dir, try std.fmt.allocPrint(gpa, "{}{}", .{p, "/zig.mod"})); |
| 60 | var dd = try fetch_deps(dir, try std.fmt.allocPrint(gpa, "{}{}", .{p, "/zig.mod"})); |
| 61 | dd.clean_path = try d.clean_path(); |
| 62 | try moduledeps.append(dd); |
| 60 | 63 | }, |
| 61 | 64 | } |
| 62 | 65 | } |
| 66 | return u.Module{ |
| 67 | .name = m.name, |
| 68 | .main = m.main, |
| 69 | .deps = moduledeps.items, |
| 70 | .clean_path = "", |
| 71 | }; |
| 63 | 72 | } |
| 64 | 73 | |
| 65 | 74 | fn run_cmd(dir: ?[]const u8, args: []const []const u8) !void { |
| ... | ... | @@ -71,7 +80,7 @@ fn run_cmd(dir: ?[]const u8, args: []const []const u8) !void { |
| 71 | 80 | }; |
| 72 | 81 | } |
| 73 | 82 | |
| 74 | | fn print_deps(w: std.fs.File.Writer, dir: []const u8, m: u.ModFile, tabs: i32) anyerror!void { |
| 83 | fn print_deps(w: std.fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32) anyerror!void { |
| 75 | 84 | if (m.deps.len == 0 and tabs > 0) { |
| 76 | 85 | try w.print("null", .{}); |
| 77 | 86 | return; |
| ... | ... | @@ -80,16 +89,11 @@ fn print_deps(w: std.fs.File.Writer, dir: []const u8, m: u.ModFile, tabs: i32) a |
| 80 | 89 | const t = " "; |
| 81 | 90 | const r = try u.repeat(t, tabs); |
| 82 | 91 | for (m.deps) |d| { |
| 83 | | const dcpath = try d.clean_path(); |
| 84 | | const p = try u.concat(&[_][]const u8{dir, "/", dcpath}); |
| 85 | | const np = try u.concat(&[_][]const u8{p, "/zig.mod"}); |
| 86 | | const n = try u.ModFile.init(gpa, np); |
| 87 | | |
| 88 | 92 | try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,"build.Pkg{"})}); |
| 89 | | try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,t,".name = \"",n.name,"\","})}); |
| 90 | | try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,t,".path = cache ++ \"/",dcpath,"/",n.main,"\","})}); |
| 93 | try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,t,".name = \"",d.name,"\","})}); |
| 94 | try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,t,".path = cache ++ \"/",d.clean_path,"/",d.main,"\","})}); |
| 91 | 95 | try w.print("{}", .{try u.concat(&[_][]const u8{r,t,t,".dependencies = "})}); |
| 92 | | try print_deps(w, dir, n, tabs+2); |
| 96 | try print_deps(w, dir, d, tabs+2); |
| 93 | 97 | try w.print("{}\n", .{","}); |
| 94 | 98 | try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,"},"})}); |
| 95 | 99 | } |