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 {...@@ -47,11 +47,11 @@ pub fn execute(args: [][]u8) !void {
47 try w.print(";\n", .{});47 try w.print(";\n", .{});
48 try w.print("\n", .{});48 try w.print("\n", .{});
49 try w.print("{}\n", .{"pub const c_include_dirs = &[_][]const u8{"});49 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));
51 try w.print("{};\n", .{"}"});51 try w.print("{};\n", .{"}"});
52 try w.print("\n", .{});52 try w.print("\n", .{});
53 try w.print("{}\n", .{"pub const c_source_files = &[_][]const u8{"});53 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));
55 try w.print("{};\n", .{"}"});55 try w.print("{};\n", .{"}"});
56}56}
5757
...@@ -119,20 +119,28 @@ fn print_deps(w: std.fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32) an...@@ -119,20 +119,28 @@ fn print_deps(w: std.fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32) an
119 try w.print("{}", .{try u.concat(&[_][]const u8{r,"}"})});119 try w.print("{}", .{try u.concat(&[_][]const u8{r,"}"})});
120}120}
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);
123 for (mod.c_include_dirs) |it| {127 for (mod.c_include_dirs) |it| {
124 try w.print(" cache ++ \"/{}/{}\",\n", .{mod.clean_path, it});128 try w.print(" cache ++ \"/{}/{}\",\n", .{mod.clean_path, it});
125 }129 }
126 for (mod.deps) |d| {130 for (mod.deps) |d| {
127 try print_incl_dirs_to(w, d);131 try print_incl_dirs_to(w, d, list);
128 }132 }
129}133}
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);
132 for (mod.c_source_files) |it| {140 for (mod.c_source_files) |it| {
133 try w.print(" cache ++ \"/{}/{}\",\n", .{mod.clean_path, it});141 try w.print(" cache ++ \"/{}/{}\",\n", .{mod.clean_path, it});
134 }142 }
135 for (mod.deps) |d| {143 for (mod.deps) |d| {
136 try print_csrc_dirs_to(w, d);144 try print_csrc_dirs_to(w, d, list);
137 }145 }
138}146}
src/util/funcs.zig+9
...@@ -106,3 +106,12 @@ pub fn print_all(w: std.fs.File.Writer, items: anytype, ln: bool) !void {...@@ -106,3 +106,12 @@ pub fn print_all(w: std.fs.File.Writer, items: anytype, ln: bool) !void {
106 try w.print("\n", .{});106 try w.print("\n", .{});
107 }107 }
108}108}
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}