authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-19 04:31:40 -08:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-19 04:31:40 -08:00
log868105a6cf4c075037d365f18171a52b75f61a3f
tree4a8143c3e09b219f8be0fabb6c2cdcacccd0cd53
parent2ce1b0d0d0d41d4858f2f5481fc299078cf5d44d

be able to override dep properties in zig.mod


6 files changed, 51 insertions(+), 0 deletions(-)

src/cmd_add.zig+5
......@@ -29,6 +29,11 @@ pub fn execute(args: [][]u8) !void {
2929 try ndl.append(u.Dep{
3030 .type = dep_type.?,
3131 .path = path,
32 .name = "",
33 .main = "",
34 .c_include_dirs = &[_][]const u8{},
35 .c_source_flags = &[_][]const u8{},
36 .c_source_files = &[_][]const u8{},
3237 });
3338
3439 //
src/cmd_fetch.zig+16
......@@ -86,8 +86,21 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
8686 }
8787 switch (d.type) {
8888 else => {
89 if (d.main.len == 0) {
90 if (d.c_include_dirs.len > 0 or d.c_source_files.len > 0) {
91 try moduledeps.append(try u.Module.from(d));
92 }
93 break;
94 }
8995 var dd = try fetch_deps(dir, try std.fmt.allocPrint(gpa, "{}{}", .{p, "/zig.mod"}));
9096 dd.clean_path = try d.clean_path();
97
98 if (d.name.len > 0) dd.name = d.name;
99 if (d.main.len > 0) dd.main = d.main;
100 if (d.c_include_dirs.len > 0) dd.c_include_dirs = d.c_include_dirs;
101 if (d.c_source_flags.len > 0) dd.c_source_flags = d.c_source_flags;
102 if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files;
103
91104 try moduledeps.append(dd);
92105 },
93106 }
......@@ -121,6 +134,9 @@ fn print_deps(w: std.fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32) an
121134 const t = " ";
122135 const r = try u.repeat(t, tabs);
123136 for (m.deps) |d| {
137 if (d.main.len == 0) {
138 continue;
139 }
124140 try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,"build.Pkg{"})});
125141 try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,t,".name = \"",d.name,"\","})});
126142 try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,t,".path = cache ++ \"/",d.clean_path,"/",d.main,"\","})});
src/util/dep.zig+6
......@@ -12,6 +12,12 @@ pub const Dep = struct {
1212 type: u.DepType,
1313 path: []const u8,
1414
15 name: []const u8,
16 main: []const u8,
17 c_include_dirs: [][]const u8,
18 c_source_flags: [][]const u8,
19 c_source_files: [][]const u8,
20
1521 pub fn clean_path(self: Dep) ![]const u8 {
1622 var p = self.path;
1723 p = u.trim_prefix(p, "https://");
src/util/modfile.zig+5
......@@ -43,6 +43,11 @@ pub const ModFile = struct {
4343 try dep_list.append(u.Dep{
4444 .type = dep_type,
4545 .path = path,
46 .name = item.mapping.get_string("name"),
47 .main = item.mapping.get_string("main"),
48 .c_include_dirs = try item.mapping.get_string_array(alloc, "c_include_dirs"),
49 .c_source_flags = try item.mapping.get_string_array(alloc, "c_source_flags"),
50 .c_source_files = try item.mapping.get_string_array(alloc, "c_source_files"),
4651 });
4752 }
4853 }
src/util/module.zig+15
......@@ -1,5 +1,7 @@
11const std = @import("std");
22
3const u = @import("index.zig");
4
35//
46//
57
......@@ -7,8 +9,21 @@ pub const Module = struct {
79 name: []const u8,
810 main: []const u8,
911 c_include_dirs: [][]const u8,
12 c_source_flags: [][]const u8,
1013 c_source_files: [][]const u8,
1114
1215 deps: []Module,
1316 clean_path: []const u8,
17
18 pub fn from(dep: u.Dep) !Module {
19 return Module{
20 .name = dep.name,
21 .main = dep.main,
22 .c_include_dirs = dep.c_include_dirs,
23 .c_source_flags = dep.c_source_flags,
24 .c_source_files = dep.c_source_files,
25 .deps = &[_]Module{},
26 .clean_path = try dep.clean_path(),
27 };
28 }
1429};
src/util/yaml.zig+4
......@@ -44,6 +44,10 @@ pub const Mapping = struct {
4444 return null;
4545 }
4646
47 pub fn get_string(self: Mapping, k: []const u8) []const u8 {
48 return if (self.get(k)) |v| v.string else "";
49 }
50
4751 pub fn get_string_array(self: Mapping, alloc: *std.mem.Allocator, k: []const u8) ![][]const u8 {
4852 const list = &std.ArrayList([]const u8).init(alloc);
4953 if (self.get(k)) |val| {