authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-06-05 21:27:56 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-06-05 21:27:56 -07:00
logfcd70831ae5913e52ccc87149bcc99859eb0e81d
tree05054c8882240edaccf134725317f05d7b4567f9
parent0a970854c1f5c8c11b6ab3ec50328ab8ec137fe5

u.Modfile- deps and devdeps are now const arrays


1 files changed, 7 insertions(+), 12 deletions(-)

src/util/modfile.zig+7-12
......@@ -20,9 +20,9 @@ pub const ModFile = struct {
2020 c_include_dirs: [][]const u8,
2121 c_source_flags: [][]const u8,
2222 c_source_files: [][]const u8,
23 deps: []u.Dep,
23 deps: []const u.Dep,
2424 yaml: yaml.Mapping,
25 devdeps: []u.Dep,
25 devdeps: []const u.Dep,
2626 root_files: [][]const u8,
2727 files: [][]const u8,
2828
......@@ -45,10 +45,6 @@ pub const ModFile = struct {
4545 u.assert(false, "name may not contain any '/'", .{});
4646 }
4747
48 const dep_list = try dep_list_by_name(alloc, mapping, "dependencies");
49 defer dep_list.deinit();
50 const devdep_list = try dep_list_by_name(alloc, mapping, "dev_dependencies");
51 defer devdep_list.deinit();
5248
5349 return Self{
5450 .alloc = alloc,
......@@ -58,17 +54,16 @@ pub const ModFile = struct {
5854 .c_include_dirs = try mapping.get_string_array(alloc, "c_include_dirs"),
5955 .c_source_flags = try mapping.get_string_array(alloc, "c_source_flags"),
6056 .c_source_files = try mapping.get_string_array(alloc, "c_source_files"),
61 .deps = dep_list.toOwnedSlice(),
57 .deps = try dep_list_by_name(alloc, mapping, "dependencies"),
6258 .yaml = mapping,
63 .devdeps = devdep_list.toOwnedSlice(),
59 .devdeps = try dep_list_by_name(alloc, mapping, "dev_dependencies"),
6460 .root_files = try mapping.get_string_array(alloc, "root_files"),
6561 .files = try mapping.get_string_array(alloc, "files"),
6662 };
6763 }
6864
69 fn dep_list_by_name(alloc: *std.mem.Allocator, mapping: yaml.Mapping, prop: []const u8) !*std.ArrayList(u.Dep) {
70 const dep_list = try alloc.create(std.ArrayList(u.Dep));
71 dep_list.* = std.ArrayList(u.Dep).init(alloc);
65 fn dep_list_by_name(alloc: *std.mem.Allocator, mapping: yaml.Mapping, prop: []const u8) ![]const u.Dep {
66 const dep_list = &std.ArrayList(u.Dep).init(alloc);
7267 if (mapping.get(prop)) |dep_seq| {
7368 if (dep_seq == .sequence) {
7469 for (dep_seq.sequence) |item| {
......@@ -124,6 +119,6 @@ pub const ModFile = struct {
124119 }
125120 }
126121 }
127 return dep_list;
122 return dep_list.toOwnedSlice();
128123 }
129124};