authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-02 00:35:08 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-02 00:35:08 -08:00
log24019b6f88c1f3a036112e91b18e3305f8aa32cf
treee1db0f6aa7ca15712452ce417ee79d69f00b3fcb
parentdece6237126be91aa6cf908acc2c4f7c3bd565ab

ModFile- allow dep_list_by_name to read from multiple arrays


1 files changed, 9 insertions(+), 6 deletions(-)

src/util/modfile.zig+9-6
......@@ -59,18 +59,21 @@ pub const ModFile = struct {
5959 .c_include_dirs = try mapping.get_string_array(alloc, "c_include_dirs"),
6060 .c_source_flags = try mapping.get_string_array(alloc, "c_source_flags"),
6161 .c_source_files = try mapping.get_string_array(alloc, "c_source_files"),
62 .deps = try dep_list_by_name(alloc, mapping, "dependencies"),
62 .deps = try dep_list_by_name(alloc, mapping, &.{"dependencies"}),
6363 .yaml = mapping,
64 .devdeps = try dep_list_by_name(alloc, mapping, "dev_dependencies"),
64 .devdeps = try dep_list_by_name(alloc, mapping, &.{"dev_dependencies"}),
6565 .root_files = try mapping.get_string_array(alloc, "root_files"),
6666 .files = try mapping.get_string_array(alloc, "files"),
6767 };
6868 }
6969
70 fn dep_list_by_name(alloc: *std.mem.Allocator, mapping: yaml.Mapping, prop: string) anyerror![]zigmod.Dep {
70 fn dep_list_by_name(alloc: *std.mem.Allocator, mapping: yaml.Mapping, props: []const string) anyerror![]zigmod.Dep {
7171 var dep_list = std.ArrayList(zigmod.Dep).init(alloc);
72 if (mapping.get(prop)) |dep_seq| {
73 if (dep_seq == .sequence) {
72 defer dep_list.deinit();
73
74 for (props) |prop| {
75 if (mapping.get(prop)) |dep_seq| {
76 if (dep_seq != .sequence) continue;
7477 for (dep_seq.sequence) |item| {
7578 var dtype: string = undefined;
7679 var path: string = undefined;
......@@ -121,7 +124,7 @@ pub const ModFile = struct {
121124 .only_os = try u.list_remove(alloc, try u.split(alloc, item.mapping.get_string("only_os"), ","), ""),
122125 .except_os = try u.list_remove(alloc, try u.split(alloc, item.mapping.get_string("except_os"), ","), ""),
123126 .yaml = item.mapping,
124 .deps = try dep_list_by_name(alloc, item.mapping, "dependencies"),
127 .deps = try dep_list_by_name(alloc, item.mapping, &.{"dependencies"}),
125128 });
126129 }
127130 }