authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-16 23:30:10 -08:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-16 23:30:10 -08:00
loga3772eac0fda962d3fbdf5ef73dcc7aa936a493e
tree1898c667c168651e088c054e6e9d411ca7d0ca3d
parent313f98c4a8495cb252cd3bd55531c691ccd13e32

fetch: only print c/h files once even if dep shows up in tree twice


2 files changed, 23 insertions(+), 6 deletions(-)

src/cmd_fetch.zig+14-6
......@@ -47,11 +47,11 @@ pub fn execute(args: [][]u8) !void {
4747 try w.print(";\n", .{});
4848 try w.print("\n", .{});
4949 try w.print("{}\n", .{"pub const c_include_dirs = &[_][]const u8{"});
50 try print_incl_dirs_to(w, top_module);
50 try print_incl_dirs_to(w, top_module, &std.ArrayList([]const u8).init(gpa));
5151 try w.print("{};\n", .{"}"});
5252 try w.print("\n", .{});
5353 try w.print("{}\n", .{"pub const c_source_files = &[_][]const u8{"});
54 try print_csrc_dirs_to(w, top_module);
54 try print_csrc_dirs_to(w, top_module, &std.ArrayList([]const u8).init(gpa));
5555 try w.print("{};\n", .{"}"});
5656}
5757
......@@ -119,20 +119,28 @@ fn print_deps(w: std.fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32) an
119119 try w.print("{}", .{try u.concat(&[_][]const u8{r,"}"})});
120120}
121121
122fn print_incl_dirs_to(w: std.fs.File.Writer, mod: u.Module) anyerror!void {
122fn print_incl_dirs_to(w: std.fs.File.Writer, mod: u.Module, list: *std.ArrayList([]const u8)) anyerror!void {
123 if (u.list_contains(list, mod.clean_path)) {
124 return;
125 }
126 try list.append(mod.clean_path);
123127 for (mod.c_include_dirs) |it| {
124128 try w.print(" cache ++ \"/{}/{}\",\n", .{mod.clean_path, it});
125129 }
126130 for (mod.deps) |d| {
127 try print_incl_dirs_to(w, d);
131 try print_incl_dirs_to(w, d, list);
128132 }
129133}
130134
131fn print_csrc_dirs_to(w: std.fs.File.Writer, mod: u.Module) anyerror!void {
135fn print_csrc_dirs_to(w: std.fs.File.Writer, mod: u.Module, list: *std.ArrayList([]const u8)) anyerror!void {
136 if (u.list_contains(list, mod.clean_path)) {
137 return;
138 }
139 try list.append(mod.clean_path);
132140 for (mod.c_source_files) |it| {
133141 try w.print(" cache ++ \"/{}/{}\",\n", .{mod.clean_path, it});
134142 }
135143 for (mod.deps) |d| {
136 try print_csrc_dirs_to(w, d);
144 try print_csrc_dirs_to(w, d, list);
137145 }
138146}
src/util/funcs.zig+9
......@@ -106,3 +106,12 @@ pub fn print_all(w: std.fs.File.Writer, items: anytype, ln: bool) !void {
106106 try w.print("\n", .{});
107107 }
108108}
109
110pub fn list_contains(haystack: *std.ArrayList([]const u8), needle: []const u8) bool {
111 for (haystack.items) |item| {
112 if (std.mem.eql(u8, item, needle)) {
113 return true;
114 }
115 }
116 return false;
117}