authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-06-20 13:43:38 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-06-20 13:43:38 -07:00
log21e9824c43eb8d7b4bee9b3d07e80dbca623b82f
tree03d5d69371056aaf8929c8d64aee533679300864
parent0d3e261e8a6b3de11f42fe209c1a5822de0d7df8

allow defining dependencies when dep doesnt have a zig.mod


4 files changed, 14 insertions(+), 6 deletions(-)

src/common.zig+3-2
......@@ -180,7 +180,7 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, options: C
180180 }
181181}
182182
183fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8, parent_name: []const u8, options: CollectOptions) !void {
183pub fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8, parent_name: []const u8, options: CollectOptions) anyerror!void {
184184 const moddir = try get_moddir(dir, d, parent_name, options);
185185 switch (d.type) {
186186 .system_lib => {
......@@ -203,7 +203,7 @@ fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8
203203 var dd = try collect_deps(dir, try u.concat(&.{ moddir, "/zig.mod" }), options) catch |e| switch (e) {
204204 error.FileNotFound => {
205205 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) {
206 var mod_from = try u.Module.from(d);
206 var mod_from = try u.Module.from(d, dir, options);
207207 if (d.type != .local) mod_from.clean_path = u.trim_prefix(moddir, dir)[1..];
208208 if (mod_from.is_for_this()) try list.append(mod_from);
209209 }
......@@ -283,6 +283,7 @@ fn add_files_package(pkg_name: []const u8, dirs: []const []const u8, list: *std.
283283 .only_os = &.{},
284284 .except_os = &.{},
285285 .yaml = null,
286 .deps = &.{},
286287 };
287288 try get_module_from_dep(list, d, destination, parent_name, .{
288289 .log = false,
src/util/dep.zig+1
......@@ -24,6 +24,7 @@ pub const Dep = struct {
2424 only_os: []const []const u8,
2525 except_os: []const []const u8,
2626 yaml: ?yaml.Mapping,
27 deps: []const u.Dep,
2728
2829 pub fn clean_path(self: Dep) ![]const u8 {
2930 if (self.type == .local) {
src/util/modfile.zig+2-2
......@@ -45,7 +45,6 @@ pub const ModFile = struct {
4545 u.assert(false, "name may not contain any '/'", .{});
4646 }
4747
48
4948 return Self{
5049 .alloc = alloc,
5150 .id = if (id.len == 0) try u.random_string(48) else id,
......@@ -62,7 +61,7 @@ pub const ModFile = struct {
6261 };
6362 }
6463
65 fn dep_list_by_name(alloc: *std.mem.Allocator, mapping: yaml.Mapping, prop: []const u8) ![]const u.Dep {
64 fn dep_list_by_name(alloc: *std.mem.Allocator, mapping: yaml.Mapping, prop: []const u8) anyerror![]const u.Dep {
6665 const dep_list = &std.ArrayList(u.Dep).init(alloc);
6766 if (mapping.get(prop)) |dep_seq| {
6867 if (dep_seq == .sequence) {
......@@ -115,6 +114,7 @@ pub const ModFile = struct {
115114 .only_os = try u.list_remove(try u.split(item.mapping.get_string("only_os"), ","), ""),
116115 .except_os = try u.list_remove(try u.split(item.mapping.get_string("except_os"), ","), ""),
117116 .yaml = item.mapping,
117 .deps = try dep_list_by_name(alloc, item.mapping, "dependencies"),
118118 });
119119 }
120120 }
src/util/module.zig+8-2
......@@ -4,6 +4,7 @@ const builtin = std.builtin;
44
55const u = @import("index.zig");
66const yaml = @import("./yaml.zig");
7const common = @import("./../common.zig");
78
89//
910//
......@@ -23,7 +24,12 @@ pub const Module = struct {
2324 deps: []Module,
2425 clean_path: []const u8,
2526
26 pub fn from(dep: u.Dep) !Module {
27 pub fn from(dep: u.Dep, dir: []const u8, options: common.CollectOptions) !Module {
28 const moddeps = &std.ArrayList(Module).init(gpa);
29 defer moddeps.deinit();
30 for (dep.deps) |d| {
31 try common.get_module_from_dep(moddeps, d, dir, dep.name, options);
32 }
2733 return Module{
2834 .is_sys_lib = false,
2935 .id = if (dep.id.len > 0) dep.id else try u.random_string(48),
......@@ -32,7 +38,7 @@ pub const Module = struct {
3238 .c_include_dirs = dep.c_include_dirs,
3339 .c_source_flags = dep.c_source_flags,
3440 .c_source_files = dep.c_source_files,
35 .deps = &.{},
41 .deps = moddeps.toOwnedSlice(),
3642 .clean_path = try dep.clean_path(),
3743 .only_os = dep.only_os,
3844 .except_os = dep.except_os,