| ... | ... | @@ -61,6 +61,16 @@ pub fn execute(args: [][]u8) !void { |
| 61 | 61 | try print_paths(w, list.items); |
| 62 | 62 | try w.writeAll("};\n"); |
| 63 | 63 | try w.writeAll("\n"); |
| 64 | try w.writeAll("pub const package_data = struct {\n"); |
| 65 | const duped = &std.ArrayList(u.Module).init(gpa); |
| 66 | for (list.items) |mod| { |
| 67 | if (mod.main.len > 0 and mod.clean_path.len > 0) { |
| 68 | try duped.append(mod); |
| 69 | } |
| 70 | } |
| 71 | try print_pkg_data_to(w, duped, &std.ArrayList(u.Module).init(gpa)); |
| 72 | try w.writeAll("};\n"); |
| 73 | try w.writeAll("\n"); |
| 64 | 74 | try w.writeAll("pub const packages = "); |
| 65 | 75 | try print_deps(w, dir, top_module, 0, true); |
| 66 | 76 | try w.writeAll(";\n"); |
| ... | ... | @@ -268,23 +278,16 @@ fn print_deps(w: fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32, array: |
| 268 | 278 | } |
| 269 | 279 | const t = " "; |
| 270 | 280 | const r = try u.repeat(t, tabs); |
| 271 | | var c: usize = 0; |
| 272 | | for (m.deps) |d| { |
| 281 | for (m.deps) |d, i| { |
| 273 | 282 | if (d.main.len == 0) { |
| 274 | 283 | continue; |
| 275 | 284 | } |
| 276 | | c += 1; |
| 277 | 285 | if (!array) { |
| 278 | | try w.print(" pub const {} = packages[{}];\n", .{d.name, c-1}); |
| 279 | | continue; |
| 286 | try w.print(" pub const {} = packages[{}];\n", .{d.name, i}); |
| 287 | } |
| 288 | else { |
| 289 | try w.print(" package_data._{},\n", .{d.id}); |
| 280 | 290 | } |
| 281 | | try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,"build.Pkg{"})}); |
| 282 | | try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,t,".name = \"",d.name,"\","})}); |
| 283 | | try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,t,".path = cache ++ \"/",d.clean_path,"/",d.main,"\","})}); |
| 284 | | try w.print("{}", .{try u.concat(&[_][]const u8{r,t,t,".dependencies = "})}); |
| 285 | | try print_deps(w, dir, d, tabs+2, array); |
| 286 | | try w.print("{}\n", .{","}); |
| 287 | | try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,"},"})}); |
| 288 | 291 | } |
| 289 | 292 | try w.print("{}", .{try u.concat(&[_][]const u8{r,"}"})}); |
| 290 | 293 | } |
| ... | ... | @@ -355,3 +358,36 @@ fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void { |
| 355 | 358 | try collect_pkgs(d, list); |
| 356 | 359 | } |
| 357 | 360 | } |
| 361 | |
| 362 | fn print_pkg_data_to(w: fs.File.Writer, list: *std.ArrayList(u.Module), list2: *std.ArrayList(u.Module)) anyerror!void { |
| 363 | var i: usize = 0; |
| 364 | while (i < list.items.len) : (i += 1) { |
| 365 | const mod = list.items[i]; |
| 366 | if (contains_all(mod.deps, list2)) { |
| 367 | try w.print(" pub const _{} = build.Pkg{{ .name = \"{}\", .path = cache ++ \"/{Z}/{}\", .dependencies = &[_]build.Pkg{{", .{mod.id, mod.name, mod.clean_path, mod.main}); |
| 368 | for (mod.deps) |d| { |
| 369 | if (d.main.len > 0) { |
| 370 | try w.print(" _{},", .{d.id}); |
| 371 | } |
| 372 | } |
| 373 | try w.print(" }} }};\n", .{}); |
| 374 | |
| 375 | try list2.append(mod); |
| 376 | _ = list.orderedRemove(i); |
| 377 | break; |
| 378 | } |
| 379 | } |
| 380 | if (list.items.len > 0) { |
| 381 | try print_pkg_data_to(w, list, list2); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | /// returns if all of the zig modules in needles are in haystack |
| 386 | fn contains_all(needles: []u.Module, haystack: *std.ArrayList(u.Module)) bool { |
| 387 | for (needles) |item| { |
| 388 | if (item.main.len > 0 and !u.list_contains_gen(u.Module, haystack, item)) { |
| 389 | return false; |
| 390 | } |
| 391 | } |
| 392 | return true; |
| 393 | } |