authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-29 04:04:52 -08:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-29 04:04:52 -08:00
log8e4624ad4051d31d793822cff9a03aad2a675abf
treec11674aa6229de99ac117df54dce822a90187c6e
parent76953c858cf2de793a44add7a50a1ae47067a3a7

add only_os and except_os props to dependencies


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

src/cmd_fetch.zig+6-2
......@@ -127,7 +127,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
127127 if (d.c_include_dirs.len > 0 or d.c_source_files.len > 0) {
128128 var mod_from = try u.Module.from(d);
129129 mod_from.clean_path = u.trim_prefix(moddir, dir)[1..];
130 try moduledeps.append(mod_from);
130 if (mod_from.is_for_this()) try moduledeps.append(mod_from);
131131 }
132132 break :blk;
133133 },
......@@ -140,8 +140,10 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
140140 if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs;
141141 if (d.c_source_flags.len > 0) dd.c_source_flags = d.c_source_flags;
142142 if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files;
143 if (d.only_os.len > 0) dd.only_os = d.only_os;
144 if (d.except_os.len > 0) dd.except_os = d.except_os;
143145
144 try moduledeps.append(dd);
146 if (dd.is_for_this()) try moduledeps.append(dd);
145147 },
146148 }
147149 }
......@@ -153,6 +155,8 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
153155 .c_source_files = m.c_source_files,
154156 .deps = moduledeps.items,
155157 .clean_path = "",
158 .only_os = &[_][]const u8{},
159 .except_os = &[_][]const u8{},
156160 };
157161}
158162
src/common.zig+6-2
......@@ -27,7 +27,7 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
2727 if (d.c_include_dirs.len > 0 or d.c_source_files.len > 0) {
2828 var mod_from = try u.Module.from(d);
2929 mod_from.clean_path = u.trim_prefix(moddir, dir)[1..];
30 try moduledeps.append(mod_from);
30 if (mod_from.is_for_this()) try moduledeps.append(mod_from);
3131 }
3232 break :blk;
3333 },
......@@ -40,8 +40,10 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
4040 if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs;
4141 if (d.c_source_flags.len > 0) dd.c_source_flags = d.c_source_flags;
4242 if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files;
43 if (d.only_os.len > 0) dd.only_os = d.only_os;
44 if (d.except_os.len > 0) dd.except_os = d.except_os;
4345
44 try moduledeps.append(dd);
46 if (dd.is_for_this()) try moduledeps.append(dd);
4547 },
4648 }
4749 }
......@@ -53,5 +55,7 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
5355 .c_source_files = m.c_source_files,
5456 .deps = moduledeps.items,
5557 .clean_path = "",
58 .only_os = &[_][]const u8{},
59 .except_os = &[_][]const u8{},
5660 };
5761}
src/util/dep.zig+2
......@@ -18,6 +18,8 @@ pub const Dep = struct {
1818 c_include_dirs: [][]const u8,
1919 c_source_flags: [][]const u8,
2020 c_source_files: [][]const u8,
21 only_os: [][]const u8,
22 except_os: [][]const u8,
2123
2224 pub fn clean_path(self: Dep) ![]const u8 {
2325 var p = self.path;
src/util/funcs.zig+10
......@@ -156,3 +156,13 @@ pub fn run_cmd(dir: ?[]const u8, args: []const []const u8) !u32 {
156156 };
157157 return result.term.Exited;
158158}
159
160pub fn list_remove(input: [][]const u8, search: []const u8) ![][]const u8 {
161 const list = &std.ArrayList([]const u8).init(gpa);
162 for (input) |item| {
163 if (!std.mem.eql(u8, item, search)) {
164 try list.append(item);
165 }
166 }
167 return list.items;
168}
src/util/modfile.zig+2
......@@ -49,6 +49,8 @@ pub const ModFile = struct {
4949 .c_include_dirs = try item.mapping.get_string_array(alloc, "c_include_dirs"),
5050 .c_source_flags = try item.mapping.get_string_array(alloc, "c_source_flags"),
5151 .c_source_files = try item.mapping.get_string_array(alloc, "c_source_files"),
52 .only_os = try u.list_remove(try u.split(item.mapping.get_string("only_os"), ","), ""),
53 .except_os = try u.list_remove(try u.split(item.mapping.get_string("except_os"), ","), ""),
5254 });
5355 }
5456 }
src/util/module.zig+16
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const gpa = std.heap.c_allocator;
3const builtin = @import("builtin");
34
45const u = @import("index.zig");
56
......@@ -16,6 +17,8 @@ pub const Module = struct {
1617 c_include_dirs: [][]const u8,
1718 c_source_flags: [][]const u8,
1819 c_source_files: [][]const u8,
20 only_os: [][]const u8,
21 except_os: [][]const u8,
1922
2023 deps: []Module,
2124 clean_path: []const u8,
......@@ -29,6 +32,8 @@ pub const Module = struct {
2932 .c_source_files = dep.c_source_files,
3033 .deps = &[_]Module{},
3134 .clean_path = try dep.clean_path(),
35 .only_os = dep.only_os,
36 .except_os = dep.except_os,
3237 };
3338 }
3439
......@@ -67,4 +72,15 @@ pub const Module = struct {
6772 const hex = try std.fmt.allocPrint(gpa, "{x}", .{out});
6873 return hex;
6974 }
75
76 pub fn is_for_this(self: Module) bool {
77 const os = @tagName(builtin.os.tag);
78 if (self.only_os.len > 0) {
79 return u.list_contains(self.only_os, os);
80 }
81 if (self.except_os.len > 0) {
82 return !u.list_contains(self.except_os, os);
83 }
84 return true;
85 }
7086};