| ... | ... | @@ -49,6 +49,14 @@ pub fn execute(args: [][]u8) !void { |
| 49 | 49 | \\} |
| 50 | 50 | }); |
| 51 | 51 | try w.print("\n", .{}); |
| 52 | try w.print("pub const _ids = {}\n", .{".{"}); |
| 53 | try print_ids(w, top_module, &std.ArrayList([]const u8).init(gpa)); |
| 54 | try w.print("{}\n", .{"};"}); |
| 55 | try w.print("\n", .{}); |
| 56 | try w.print("pub const _paths = {}\n", .{".{"}); |
| 57 | try print_paths(w, top_module, &std.ArrayList([]const u8).init(gpa)); |
| 58 | try w.print("{}\n", .{"};"}); |
| 59 | try w.print("\n", .{}); |
| 52 | 60 | try w.print("pub const packages = ", .{}); |
| 53 | 61 | try print_deps(w, dir, top_module, 0, true); |
| 54 | 62 | try w.print(";\n", .{}); |
| ... | ... | @@ -162,6 +170,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 162 | 170 | .system_lib => { |
| 163 | 171 | if (d.is_for_this()) try moduledeps.append(u.Module{ |
| 164 | 172 | .is_sys_lib = true, |
| 173 | .id = "", |
| 165 | 174 | .name = d.path, |
| 166 | 175 | .only_os = d.only_os, |
| 167 | 176 | .except_os = d.except_os, |
| ... | ... | @@ -178,6 +187,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 178 | 187 | error.FileNotFound => { |
| 179 | 188 | if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { |
| 180 | 189 | var mod_from = try u.Module.from(d); |
| 190 | mod_from.id = try u.random_string(48); |
| 181 | 191 | mod_from.clean_path = u.trim_prefix(moddir, dir)[1..]; |
| 182 | 192 | if (mod_from.is_for_this()) try moduledeps.append(mod_from); |
| 183 | 193 | } |
| ... | ... | @@ -187,6 +197,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 187 | 197 | }; |
| 188 | 198 | dd.clean_path = u.trim_prefix(moddir, dir)[1..]; |
| 189 | 199 | |
| 200 | if (dd.id.len == 0) dd.id = try u.random_string(48); |
| 190 | 201 | if (d.name.len > 0) dd.name = d.name; |
| 191 | 202 | if (d.main.len > 0) dd.main = d.main; |
| 192 | 203 | if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs; |
| ... | ... | @@ -201,6 +212,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 201 | 212 | } |
| 202 | 213 | return u.Module{ |
| 203 | 214 | .is_sys_lib = false, |
| 215 | .id = m.id, |
| 204 | 216 | .name = m.name, |
| 205 | 217 | .main = m.main, |
| 206 | 218 | .c_include_dirs = m.c_include_dirs, |
| ... | ... | @@ -213,6 +225,43 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 213 | 225 | }; |
| 214 | 226 | } |
| 215 | 227 | |
| 228 | fn print_ids(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]const u8)) anyerror!void { |
| 229 | if (u.list_contains(list.items, mod.clean_path)) { |
| 230 | return; |
| 231 | } |
| 232 | try list.append(mod.clean_path); |
| 233 | // |
| 234 | if (mod.clean_path.len == 0) { |
| 235 | try w.print(" \"\",\n", .{}); |
| 236 | } else { |
| 237 | try w.print(" \"{}\",\n", .{mod.id}); |
| 238 | } |
| 239 | // |
| 240 | for (mod.deps) |d| { |
| 241 | if (d.is_sys_lib) continue; |
| 242 | try print_ids(w, d, list); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | fn print_paths(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]const u8)) anyerror!void { |
| 247 | if (u.list_contains(list.items, mod.clean_path)) { |
| 248 | return; |
| 249 | } |
| 250 | try list.append(mod.clean_path); |
| 251 | // |
| 252 | if (mod.clean_path.len == 0) { |
| 253 | try w.print(" \"\",\n", .{}); |
| 254 | } else { |
| 255 | const s = std.fs.path.sep_str; |
| 256 | try w.print(" \"{Z}{Z}{Z}\",\n", .{s, mod.clean_path, s}); |
| 257 | } |
| 258 | // |
| 259 | for (mod.deps) |d| { |
| 260 | if (d.is_sys_lib) continue; |
| 261 | try print_paths(w, d, list); |
| 262 | } |
| 263 | } |
| 264 | |
| 216 | 265 | fn print_deps(w: fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32, array: bool) anyerror!void { |
| 217 | 266 | if (m.deps.len == 0 and tabs > 0) { |
| 218 | 267 | try w.print("null", .{}); |
| ... | ... | @@ -253,9 +302,9 @@ fn print_incl_dirs_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]c |
| 253 | 302 | try list.append(mod.clean_path); |
| 254 | 303 | for (mod.c_include_dirs) |it| { |
| 255 | 304 | if (!local) { |
| 256 | | try w.print(" cache ++ \"/{}/{}\",\n", .{mod.clean_path, it}); |
| 305 | try w.print(" cache ++ _paths[{}] ++ \"{Z}\",\n", .{list.items.len-1, it}); |
| 257 | 306 | } else { |
| 258 | | try w.print(" \".{}/{}\",\n", .{mod.clean_path, it}); |
| 307 | // try w.print(" ,\n", .{mod.clean_path, it}); |
| 259 | 308 | } |
| 260 | 309 | } |
| 261 | 310 | for (mod.deps) |d| { |
| ... | ... | @@ -271,9 +320,9 @@ fn print_csrc_dirs_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]c |
| 271 | 320 | try list.append(mod.clean_path); |
| 272 | 321 | for (mod.c_source_files) |it| { |
| 273 | 322 | if (!local) { |
| 274 | | try w.print(" {}comptime get_flags({}), cache ++ \"/{}/{}\"{},\n", .{"[_][]const u8{", list.items.len-1, mod.clean_path, it, "}"}); |
| 323 | try w.print(" {}_ids[{}], cache ++ _paths[{}] ++ \"{}\"{},\n", .{"[_][]const u8{", list.items.len-1, list.items.len-1, it, "}"}); |
| 275 | 324 | } else { |
| 276 | | try w.print(" {}comptime get_flags({}), \".{}/{}\"{},\n", .{"[_][]const u8{", list.items.len-1, mod.clean_path, it, "}"}); |
| 325 | try w.print(" {}\"{}\", \".{}/{}\"{},\n", .{"[_][]const u8{", mod.clean_path, mod.clean_path, it, "}"}); |
| 277 | 326 | } |
| 278 | 327 | } |
| 279 | 328 | for (mod.deps) |d| { |
| ... | ... | @@ -291,7 +340,7 @@ fn print_csrc_flags_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([] |
| 291 | 340 | try w.print(" pub const @\"{}\" = {};\n", .{"", "&[_][]const u8{}"}); |
| 292 | 341 | } |
| 293 | 342 | else { |
| 294 | | try w.print(" pub const @\"{}\" = {}", .{mod.clean_path, "&[_][]const u8{"}); |
| 343 | try w.print(" pub const @\"{}\" = {}", .{mod.id, "&[_][]const u8{"}); |
| 295 | 344 | for (mod.c_source_flags) |it| { |
| 296 | 345 | try w.print("\"{Z}\",", .{it}); |
| 297 | 346 | } |