diff --git a/src/cmd/fetch.zig b/src/cmd/fetch.zig index 2a839a1f8840b31a339825e1844f034aa06e150d..b75f94fb298e4eb2b4767558b10e644b2bb8811f 100644 --- a/src/cmd/fetch.zig +++ b/src/cmd/fetch.zig @@ -13,7 +13,7 @@ pub fn execute(args: [][]u8) !void { // const dir = try fs.path.join(gpa, &.{".zigmod", "deps"}); - const top_module = try common.collect_deps(dir, "zig.mod", .{ + const top_module = try common.collect_deps_deep(dir, "zig.mod", .{ .log = true, .update = true, }); @@ -67,6 +67,10 @@ pub fn execute(args: [][]u8) !void { try w.writeAll("pub const package_data = struct {\n"); const duped = &std.ArrayList(u.Module).init(gpa); for (list.items) |mod| { + if (std.mem.eql(u8, mod.id, "root")) { + continue; + } + try duped.append(mod); } try print_pkg_data_to(w, duped, &std.ArrayList(u.Module).init(gpa)); try w.writeAll("};\n\n"); diff --git a/src/cmd/license.zig b/src/cmd/license.zig index c477db0d0e4c268b46d6a23c0fdc39310546faff..5d05685561787f048c86a4583303f966ca5924aa 100644 --- a/src/cmd/license.zig +++ b/src/cmd/license.zig @@ -20,7 +20,7 @@ pub fn execute(args: [][]u8) !void { // const dir = try std.fs.path.join(gpa, &.{".zigmod", "deps"}); - const top_module = try common.collect_deps(dir, "zig.mod", .{ + const top_module = try common.collect_deps_deep(dir, "zig.mod", .{ .log = false, .update = false, }); @@ -33,6 +33,9 @@ pub fn execute(args: [][]u8) !void { const unspecified_list = &List.init(gpa); for (master_list.items) |item| { + if (item.clean_path.len == 0) { + continue; + } if (item.yaml == null) { try unspecified_list.append(item); continue; @@ -60,7 +63,7 @@ pub fn execute(args: [][]u8) !void { } std.debug.print(style.ResetIntensity, .{}); for (entry.value.items) |item| { - std.debug.print("- {s}\n", .{if (item.clean_path.len > 0) item.clean_path else "This"}); + std.debug.print("- {s}\n", .{if (!std.mem.eql(u8, item.clean_path, "../..")) item.clean_path else "This"}); } std.debug.print("\n", .{}); } @@ -68,7 +71,7 @@ pub fn execute(args: [][]u8) !void { std.debug.print(style.Bold ++ "Unspecified:\n", .{}); std.debug.print(style.ResetIntensity, .{}); for (unspecified_list.items) |item| { - std.debug.print("- {s}\n", .{if (item.clean_path.len > 0) item.clean_path else "This"}); + std.debug.print("- {s}\n", .{if (!std.mem.eql(u8, item.clean_path, "../..")) item.clean_path else "This"}); } } } diff --git a/src/cmd/sum.zig b/src/cmd/sum.zig index fdea85455bd2072bb914604bbc78d2612b14a554..74a6f0fd431d03d9d589c0e3a924216c7a3acd7a 100644 --- a/src/cmd/sum.zig +++ b/src/cmd/sum.zig @@ -12,7 +12,7 @@ pub fn execute(args: [][]u8) !void { // const dir = try std.fs.path.join(gpa, &.{".zigmod", "deps"}); - const top_module = try common.collect_deps(dir, "zig.mod", .{ + const top_module = try common.collect_deps_deep(dir, "zig.mod", .{ .log = false, .update = false, }); @@ -28,6 +28,7 @@ pub fn execute(args: [][]u8) !void { for (module_list.items) |m| { if (m.clean_path.len == 0) { continue; } + if (std.mem.eql(u8, m.clean_path, "../..")) { continue; } const hash = try m.get_hash(dir); try w.print("{s} {s}\n", .{hash, m.clean_path}); } diff --git a/src/common.zig b/src/common.zig index 124f4ecc8bc9a8fb8ae54cf30af37b918e609c53..ee99f04ed2184b23e1ff59e08db6c6f7abf74fba 100644 --- a/src/common.zig +++ b/src/common.zig @@ -12,6 +12,29 @@ pub const CollectOptions = struct { update: bool, }; +pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, comptime options: CollectOptions) !u.Module { + const m = try u.ModFile.init(gpa, mpath); + const moduledeps = &std.ArrayList(u.Module).init(gpa); + try moduledeps.append(try collect_deps(dir, mpath, options)); + for (m.devdeps) |d| { + try get_module_from_dep(moduledeps, d, dir, m.name, options); + } + return u.Module{ + .is_sys_lib = false, + .id = "root", + .name = "root", + .main = m.main, + .c_include_dirs = &.{}, + .c_source_flags = &.{}, + .c_source_files = &.{}, + .deps = moduledeps.items, + .clean_path = "", + .only_os = &.{}, + .except_os = &.{}, + .yaml = m.yaml, + }; +} + pub fn collect_deps(dir: []const u8, mpath: []const u8, comptime options: CollectOptions) anyerror!u.Module { const m = try u.ModFile.init(gpa, mpath); const moduledeps = &std.ArrayList(u.Module).init(gpa); @@ -27,7 +50,7 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8, comptime options: Collec .c_source_flags = m.c_source_flags, .c_source_files = m.c_source_files, .deps = moduledeps.items, - .clean_path = "", + .clean_path = "../..", .only_os = &.{}, .except_os = &.{}, .yaml = m.yaml, diff --git a/src/util/modfile.zig b/src/util/modfile.zig index 8538b0b9a5c8db064ece9d10e29ce86837b8cda9..0d8ccacf51e9161fb7802cf3254fc31ef1624793 100644 --- a/src/util/modfile.zig +++ b/src/util/modfile.zig @@ -22,6 +22,7 @@ pub const ModFile = struct { c_source_files: [][]const u8, deps: []u.Dep, yaml: yaml.Mapping, + devdeps: []u.Dep, pub fn init(alloc: *std.mem.Allocator, fpath: []const u8) !Self { // @@ -39,6 +40,7 @@ pub const ModFile = struct { const main = mapping.get_string("main"); const dep_list = try dep_list_by_name(alloc, mapping, "dependencies"); + const devdep_list = try dep_list_by_name(alloc, mapping, "dev_dependencies"); return Self{ .alloc = alloc, @@ -50,6 +52,7 @@ pub const ModFile = struct { .c_source_files = try mapping.get_string_array(alloc, "c_source_files"), .deps = dep_list.items, .yaml = mapping, + .devdeps = devdep_list.items, }; }