| ... | ... | @@ -47,14 +47,21 @@ pub fn execute(args: [][]u8) !void { |
| 47 | 47 | \\fn get_flags(comptime index: usize) []const u8 { |
| 48 | 48 | \\ return @field(c_source_flags, _paths[index]); |
| 49 | 49 | \\} |
| 50 | \\ |
| 50 | 51 | }); |
| 51 | | try w.writeAll("\n"); |
| 52 | |
| 53 | const list = &std.ArrayList(u.Module).init(gpa); |
| 54 | try collect_pkgs(top_module, list); |
| 55 | for (list.items) |m, i| { |
| 56 | std.debug.print("module: {} {}\n", .{i, m.clean_path}); |
| 57 | } |
| 58 | |
| 52 | 59 | try w.writeAll("pub const _ids = .{\n"); |
| 53 | | try print_ids(w, top_module, &std.ArrayList([]const u8).init(gpa)); |
| 60 | try print_ids(w, list.items); |
| 54 | 61 | try w.writeAll("};\n"); |
| 55 | 62 | try w.writeAll("\n"); |
| 56 | 63 | try w.print("pub const _paths = {}\n", .{".{"}); |
| 57 | | try print_paths(w, top_module, &std.ArrayList([]const u8).init(gpa)); |
| 64 | try print_paths(w, list.items); |
| 58 | 65 | try w.writeAll("};\n"); |
| 59 | 66 | try w.writeAll("\n"); |
| 60 | 67 | try w.writeAll("pub const packages = "); |
| ... | ... | @@ -66,19 +73,20 @@ pub fn execute(args: [][]u8) !void { |
| 66 | 73 | try w.writeAll(";\n"); |
| 67 | 74 | try w.writeAll("\n"); |
| 68 | 75 | try w.writeAll("pub const c_include_dirs = &[_][]const u8{\n"); |
| 69 | | try print_incl_dirs_to(w, top_module, &std.ArrayList([]const u8).init(gpa), true); |
| 76 | try print_incl_dirs_to(w, list.items); |
| 70 | 77 | try w.writeAll("};\n"); |
| 71 | 78 | try w.writeAll("\n"); |
| 72 | 79 | try w.writeAll("pub const c_source_flags = struct {\n"); |
| 73 | | try print_csrc_flags_to(w, top_module, &std.ArrayList([]const u8).init(gpa), true); |
| 80 | try print_csrc_flags_to(w, list.items); |
| 74 | 81 | try w.writeAll("};\n"); |
| 75 | 82 | try w.writeAll("\n"); |
| 76 | 83 | try w.writeAll("pub const c_source_files = &[_][2][]const u8{\n"); |
| 77 | | try print_csrc_dirs_to(w, top_module, &std.ArrayList([]const u8).init(gpa), true); |
| 84 | try print_csrc_dirs_to(w, list.items); |
| 78 | 85 | try w.writeAll("};\n"); |
| 79 | 86 | try w.writeAll("\n"); |
| 80 | 87 | try w.writeAll("pub const system_libs = &[_][]const u8{\n"); |
| 81 | | try print_sys_libs_to(w, top_module, &std.ArrayList([]const u8).init(gpa), &std.ArrayList([]const u8).init(gpa)); |
| 88 | try print_sys_libs_to(w, list.items, &std.ArrayList([]const u8).init(gpa)); |
| 89 | try w.writeAll("};\n"); |
| 82 | 90 | try w.writeAll("};\n"); |
| 83 | 91 | } |
| 84 | 92 | |
| ... | ... | @@ -225,40 +233,30 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 225 | 233 | }; |
| 226 | 234 | } |
| 227 | 235 | |
| 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); |
| 236 | fn print_ids(w: fs.File.Writer, list: []u.Module) !void { |
| 237 | for (list) |mod| { |
| 238 | if (mod.is_sys_lib) { |
| 239 | continue; |
| 240 | } |
| 241 | if (mod.clean_path.len == 0) { |
| 242 | try w.print(" \"\",\n", .{}); |
| 243 | } else { |
| 244 | try w.print(" \"{}\",\n", .{mod.id}); |
| 245 | } |
| 243 | 246 | } |
| 244 | 247 | } |
| 245 | 248 | |
| 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); |
| 249 | fn print_paths(w: fs.File.Writer, list: []u.Module) !void { |
| 250 | for (list) |mod| { |
| 251 | if (mod.is_sys_lib) { |
| 252 | continue; |
| 253 | } |
| 254 | if (mod.clean_path.len == 0) { |
| 255 | try w.print(" \"\",\n", .{}); |
| 256 | } else { |
| 257 | const s = std.fs.path.sep_str; |
| 258 | try w.print(" \"{Z}{Z}{Z}\",\n", .{s, mod.clean_path, s}); |
| 259 | } |
| 262 | 260 | } |
| 263 | 261 | } |
| 264 | 262 | |
| ... | ... | @@ -295,77 +293,69 @@ fn print_deps(w: fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32, array: |
| 295 | 293 | try w.print("{}", .{try u.concat(&[_][]const u8{r,"}"})}); |
| 296 | 294 | } |
| 297 | 295 | |
| 298 | | fn print_incl_dirs_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]const u8), local: bool) anyerror!void { |
| 299 | | if (u.list_contains(list.items, mod.clean_path)) { |
| 300 | | return; |
| 301 | | } |
| 302 | | try list.append(mod.clean_path); |
| 303 | | for (mod.c_include_dirs) |it| { |
| 304 | | if (!local) { |
| 305 | | try w.print(" cache ++ _paths[{}] ++ \"{Z}\",\n", .{list.items.len-1, it}); |
| 306 | | } else { |
| 307 | | try w.print(" \"\",\n", .{}); |
| 296 | fn print_incl_dirs_to(w: fs.File.Writer, list: []u.Module) !void { |
| 297 | for (list) |mod, i| { |
| 298 | if (mod.is_sys_lib) { |
| 299 | continue; |
| 300 | } |
| 301 | for (mod.c_include_dirs) |it| { |
| 302 | if (i > 0) { |
| 303 | try w.print(" cache ++ _paths[{}] ++ \"{Z}\",\n", .{i, it}); |
| 304 | } else { |
| 305 | try w.print(" \"\",\n", .{}); |
| 306 | } |
| 308 | 307 | } |
| 309 | | } |
| 310 | | for (mod.deps) |d| { |
| 311 | | if (d.is_sys_lib) continue; |
| 312 | | try print_incl_dirs_to(w, d, list, false); |
| 313 | 308 | } |
| 314 | 309 | } |
| 315 | 310 | |
| 316 | | fn print_csrc_dirs_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]const u8), local: bool) anyerror!void { |
| 317 | | if (u.list_contains(list.items, mod.clean_path)) { |
| 318 | | return; |
| 311 | fn print_csrc_dirs_to(w: fs.File.Writer, list: []u.Module) !void { |
| 312 | for (list) |mod, i| { |
| 313 | if (mod.is_sys_lib) { |
| 314 | continue; |
| 315 | } |
| 316 | for (mod.c_source_files) |it| { |
| 317 | if (i > 0) { |
| 318 | try w.print(" {}_ids[{}], cache ++ _paths[{}] ++ \"{}\"{},\n", .{"[_][]const u8{", i, i, it, "}"}); |
| 319 | } else { |
| 320 | try w.print(" {}\"{}\", \".{}/{}\"{},\n", .{"[_][]const u8{", mod.clean_path, mod.clean_path, it, "}"}); |
| 321 | } |
| 322 | } |
| 319 | 323 | } |
| 320 | | try list.append(mod.clean_path); |
| 321 | | for (mod.c_source_files) |it| { |
| 322 | | if (!local) { |
| 323 | | try w.print(" {}_ids[{}], cache ++ _paths[{}] ++ \"{}\"{},\n", .{"[_][]const u8{", list.items.len-1, list.items.len-1, it, "}"}); |
| 324 | } |
| 325 | |
| 326 | fn print_csrc_flags_to(w: fs.File.Writer, list: []u.Module) !void { |
| 327 | for (list) |mod, i| { |
| 328 | if (mod.is_sys_lib) { |
| 329 | continue; |
| 330 | } |
| 331 | if (i == 0) { |
| 332 | try w.print(" pub const @\"{}\" = {};\n", .{"", "&[_][]const u8{}"}); |
| 324 | 333 | } else { |
| 325 | | try w.print(" {}\"{}\", \".{}/{}\"{},\n", .{"[_][]const u8{", mod.clean_path, mod.clean_path, it, "}"}); |
| 334 | try w.print(" pub const @\"{}\" = {}", .{mod.id, "&[_][]const u8{"}); |
| 335 | for (mod.c_source_flags) |it| { |
| 336 | try w.print("\"{Z}\",", .{it}); |
| 337 | } |
| 338 | try w.print("{};\n", .{"}"}); |
| 326 | 339 | } |
| 327 | 340 | } |
| 328 | | for (mod.deps) |d| { |
| 329 | | if (d.is_sys_lib) continue; |
| 330 | | try print_csrc_dirs_to(w, d, list, false); |
| 331 | | } |
| 332 | 341 | } |
| 333 | 342 | |
| 334 | | fn print_csrc_flags_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]const u8), local: bool) anyerror!void { |
| 335 | | if (u.list_contains(list.items, mod.clean_path)) { |
| 336 | | return; |
| 337 | | } |
| 338 | | try list.append(mod.clean_path); |
| 339 | | if (local) { |
| 340 | | try w.print(" pub const @\"{}\" = {};\n", .{"", "&[_][]const u8{}"}); |
| 341 | | } |
| 342 | | else { |
| 343 | | try w.print(" pub const @\"{}\" = {}", .{mod.id, "&[_][]const u8{"}); |
| 344 | | for (mod.c_source_flags) |it| { |
| 345 | | try w.print("\"{Z}\",", .{it}); |
| 343 | fn print_sys_libs_to(w: fs.File.Writer, list: []u.Module, list2: *std.ArrayList([]const u8)) !void { |
| 344 | for (list) |mod| { |
| 345 | if (!mod.is_sys_lib) { |
| 346 | continue; |
| 346 | 347 | } |
| 347 | | try w.print("{};\n", .{"}"}); |
| 348 | | } |
| 349 | | for (mod.deps) |d| { |
| 350 | | if (d.is_sys_lib) continue; |
| 351 | | try print_csrc_flags_to(w, d, list, false); |
| 348 | try w.print(" \"{}\",\n", .{mod.name}); |
| 352 | 349 | } |
| 353 | 350 | } |
| 354 | 351 | |
| 355 | | fn print_sys_libs_to(w: fs.File.Writer, mod: u.Module, list: *std.ArrayList([]const u8), list2: *std.ArrayList([]const u8)) anyerror!void { |
| 356 | | if (u.list_contains(list.items, mod.clean_path)) { |
| 352 | fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void { |
| 353 | // |
| 354 | if (u.list_contains_gen(u.Module, list, mod)) { |
| 357 | 355 | return; |
| 358 | 356 | } |
| 359 | | try list.append(mod.clean_path); |
| 360 | | // |
| 357 | try list.append(mod); |
| 361 | 358 | for (mod.deps) |d| { |
| 362 | | if (!d.is_sys_lib) continue; |
| 363 | | // |
| 364 | | if (!u.list_contains(list2.items, d.name)) { |
| 365 | | try w.print(" \"{}\",\n", .{d.name}); |
| 366 | | try list2.append(d.name); |
| 367 | | } |
| 368 | | // |
| 369 | | try print_sys_libs_to(w, d, list, list2); |
| 359 | try collect_pkgs(d, list); |
| 370 | 360 | } |
| 371 | 361 | } |