authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-02-15 09:11:22 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-02-15 09:11:22 -08:00
log2c4c64ccac506ac46acfcc7bde57409dceef2a6f
treea9e09cc1175d848d68c548e136d63e426f4aca95
parent8e57f30531510eea3ba45e7e5f2fc789b7c40ba9

move collect_pkgs from cmd/fetch to common


2 files changed, 11 insertions(+), 12 deletions(-)

src/cmd_fetch.zig+1-12
...@@ -55,7 +55,7 @@ pub fn execute(args: [][]u8) !void {...@@ -55,7 +55,7 @@ pub fn execute(args: [][]u8) !void {
55 });55 });
5656
57 const list = &std.ArrayList(u.Module).init(gpa);57 const list = &std.ArrayList(u.Module).init(gpa);
58 try collect_pkgs(top_module, list);58 try common.collect_pkgs(top_module, list);
5959
60 try w.writeAll("pub const _ids = .{\n");60 try w.writeAll("pub const _ids = .{\n");
61 try print_ids(w, list.items);61 try print_ids(w, list.items);
...@@ -202,17 +202,6 @@ fn print_sys_libs_to(w: fs.File.Writer, list: []u.Module, list2: *std.ArrayList(...@@ -202,17 +202,6 @@ fn print_sys_libs_to(w: fs.File.Writer, list: []u.Module, list2: *std.ArrayList(
202 }202 }
203}203}
204204
205fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void {
206 //
207 if (u.list_contains_gen(u.Module, list, mod)) {
208 return;
209 }
210 try list.append(mod);
211 for (mod.deps) |d| {
212 try collect_pkgs(d, list);
213 }
214}
215
216fn print_pkg_data_to(w: fs.File.Writer, list: *std.ArrayList(u.Module), list2: *std.ArrayList(u.Module)) anyerror!void {205fn print_pkg_data_to(w: fs.File.Writer, list: *std.ArrayList(u.Module), list2: *std.ArrayList(u.Module)) anyerror!void {
217 var i: usize = 0;206 var i: usize = 0;
218 while (i < list.items.len) : (i += 1) {207 while (i < list.items.len) : (i += 1) {
src/common.zig+10
...@@ -154,3 +154,13 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8, comptime options: Collec...@@ -154,3 +154,13 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8, comptime options: Collec
154 .except_os = &[_][]const u8{},154 .except_os = &[_][]const u8{},
155 };155 };
156}156}
157
158pub fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void {
159 if (u.list_contains_gen(u.Module, list, mod)) {
160 return;
161 }
162 try list.append(mod);
163 for (mod.deps) |d| {
164 try collect_pkgs(d, list);
165 }
166}