authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-04-08 23:24:18 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-04-08 23:24:18 -07:00
log85d569f3566f932cdd6b6e9a04e6b117341f956c
tree7ff7d43b11b17f4431aab6377f1359dfdc6a9aec
parent5d364ed5b994a50318d4350670451eeb09d40324
signaturelock-open Commit is signed but in an unrecognized format.

common- move get_module_from_dep into its own function


1 files changed, 49 insertions(+), 45 deletions(-)

src/common.zig+49-45
......@@ -16,51 +16,7 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8, comptime options: Collec
1616 const m = try u.ModFile.init(gpa, mpath);
1717 const moduledeps = &std.ArrayList(u.Module).init(gpa);
1818 for (m.deps) |d| {
19 const moddir = try get_moddir(dir, d, m.name, options);
20 switch (d.type) {
21 .system_lib => {
22 if (d.is_for_this()) try moduledeps.append(u.Module{
23 .is_sys_lib = true,
24 .id = "",
25 .name = d.path,
26 .only_os = d.only_os,
27 .except_os = d.except_os,
28 .main = "",
29 .c_include_dirs = &.{},
30 .c_source_flags = &.{},
31 .c_source_files = &.{},
32 .deps = &[_]u.Module{},
33 .clean_path = d.path,
34 .yaml = null,
35 });
36 },
37 else => blk: {
38 var dd = try collect_deps(dir, try u.concat(&.{moddir, "/zig.mod"}), options) catch |e| switch (e) {
39 error.FileNotFound => {
40 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) {
41 var mod_from = try u.Module.from(d);
42 if (mod_from.id.len == 0) mod_from.id = try u.random_string(48);
43 mod_from.clean_path = u.trim_prefix(moddir, dir)[1..];
44 if (mod_from.is_for_this()) try moduledeps.append(mod_from);
45 }
46 break :blk;
47 },
48 else => e,
49 };
50 dd.clean_path = u.trim_prefix(moddir, dir)[1..];
51
52 if (dd.id.len == 0) dd.id = try u.random_string(48);
53 if (d.name.len > 0) dd.name = d.name;
54 if (d.main.len > 0) dd.main = d.main;
55 if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs;
56 if (d.c_source_flags.len > 0) dd.c_source_flags = d.c_source_flags;
57 if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files;
58 if (d.only_os.len > 0) dd.only_os = d.only_os;
59 if (d.except_os.len > 0) dd.except_os = d.except_os;
60
61 if (dd.is_for_this()) try moduledeps.append(dd);
62 },
63 }
19 try get_module_from_dep(moduledeps, d, dir, m.name, options);
6420 }
6521 return u.Module{
6622 .is_sys_lib = false,
......@@ -173,3 +129,51 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime o
173129 },
174130 }
175131}
132
133fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8, parent_name: []const u8, comptime options: CollectOptions) !void {
134 const moddir = try get_moddir(dir, d, parent_name, options);
135 switch (d.type) {
136 .system_lib => {
137 if (d.is_for_this()) try list.append(u.Module{
138 .is_sys_lib = true,
139 .id = "",
140 .name = d.path,
141 .only_os = d.only_os,
142 .except_os = d.except_os,
143 .main = "",
144 .c_include_dirs = &.{},
145 .c_source_flags = &.{},
146 .c_source_files = &.{},
147 .deps = &[_]u.Module{},
148 .clean_path = d.path,
149 .yaml = null,
150 });
151 },
152 else => blk: {
153 var dd = try collect_deps(dir, try u.concat(&.{moddir, "/zig.mod"}), options) catch |e| switch (e) {
154 error.FileNotFound => {
155 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) {
156 var mod_from = try u.Module.from(d);
157 if (mod_from.id.len == 0) mod_from.id = try u.random_string(48);
158 mod_from.clean_path = u.trim_prefix(moddir, dir)[1..];
159 if (mod_from.is_for_this()) try list.append(mod_from);
160 }
161 break :blk;
162 },
163 else => e,
164 };
165 dd.clean_path = u.trim_prefix(moddir, dir)[1..];
166
167 if (dd.id.len == 0) dd.id = try u.random_string(48);
168 if (d.name.len > 0) dd.name = d.name;
169 if (d.main.len > 0) dd.main = d.main;
170 if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs;
171 if (d.c_source_flags.len > 0) dd.c_source_flags = d.c_source_flags;
172 if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files;
173 if (d.only_os.len > 0) dd.only_os = d.only_os;
174 if (d.except_os.len > 0) dd.except_os = d.except_os;
175
176 if (dd.is_for_this()) try list.append(dd);
177 },
178 }
179}