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 {...@@ -29,6 +29,11 @@ pub fn execute(args: [][]u8) !void {
29 try ndl.append(u.Dep{29 try ndl.append(u.Dep{
30 .type = dep_type.?,30 .type = dep_type.?,
31 .path = path,31 .path = path,
32 .name = "",
33 .main = "",
34 .c_include_dirs = &[_][]const u8{},
35 .c_source_flags = &[_][]const u8{},
36 .c_source_files = &[_][]const u8{},
32 });37 });
3338
34 //39 //
src/cmd_fetch.zig+16
...@@ -86,8 +86,21 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {...@@ -86,8 +86,21 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
86 }86 }
87 switch (d.type) {87 switch (d.type) {
88 else => {88 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 }
89 var dd = try fetch_deps(dir, try std.fmt.allocPrint(gpa, "{}{}", .{p, "/zig.mod"}));95 var dd = try fetch_deps(dir, try std.fmt.allocPrint(gpa, "{}{}", .{p, "/zig.mod"}));
90 dd.clean_path = try d.clean_path();96 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
91 try moduledeps.append(dd);104 try moduledeps.append(dd);
92 },105 },
93 }106 }
...@@ -121,6 +134,9 @@ fn print_deps(w: std.fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32) an...@@ -121,6 +134,9 @@ fn print_deps(w: std.fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32) an
121 const t = " ";134 const t = " ";
122 const r = try u.repeat(t, tabs);135 const r = try u.repeat(t, tabs);
123 for (m.deps) |d| {136 for (m.deps) |d| {
137 if (d.main.len == 0) {
138 continue;
139 }
124 try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,"build.Pkg{"})});140 try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,"build.Pkg{"})});
125 try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,t,".name = \"",d.name,"\","})});141 try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,t,".name = \"",d.name,"\","})});
126 try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,t,".path = cache ++ \"/",d.clean_path,"/",d.main,"\","})});142 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 {...@@ -12,6 +12,12 @@ pub const Dep = struct {
12 type: u.DepType,12 type: u.DepType,
13 path: []const u8,13 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
15 pub fn clean_path(self: Dep) ![]const u8 {21 pub fn clean_path(self: Dep) ![]const u8 {
16 var p = self.path;22 var p = self.path;
17 p = u.trim_prefix(p, "https://");23 p = u.trim_prefix(p, "https://");
src/util/modfile.zig+5
...@@ -43,6 +43,11 @@ pub const ModFile = struct {...@@ -43,6 +43,11 @@ pub const ModFile = struct {
43 try dep_list.append(u.Dep{43 try dep_list.append(u.Dep{
44 .type = dep_type,44 .type = dep_type,
45 .path = path,45 .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"),
46 });51 });
47 }52 }
48 }53 }
src/util/module.zig+15
...@@ -1,5 +1,7 @@...@@ -1,5 +1,7 @@
1const std = @import("std");1const std = @import("std");
22
3const u = @import("index.zig");
4
3//5//
4//6//
57
...@@ -7,8 +9,21 @@ pub const Module = struct {...@@ -7,8 +9,21 @@ pub const Module = struct {
7 name: []const u8,9 name: []const u8,
8 main: []const u8,10 main: []const u8,
9 c_include_dirs: [][]const u8,11 c_include_dirs: [][]const u8,
12 c_source_flags: [][]const u8,
10 c_source_files: [][]const u8,13 c_source_files: [][]const u8,
1114
12 deps: []Module,15 deps: []Module,
13 clean_path: []const u8,16 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 }
14};29};
src/util/yaml.zig+4
...@@ -44,6 +44,10 @@ pub const Mapping = struct {...@@ -44,6 +44,10 @@ pub const Mapping = struct {
44 return null;44 return null;
45 }45 }
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
47 pub fn get_string_array(self: Mapping, alloc: *std.mem.Allocator, k: []const u8) ![][]const u8 {51 pub fn get_string_array(self: Mapping, alloc: *std.mem.Allocator, k: []const u8) ![][]const u8 {
48 const list = &std.ArrayList([]const u8).init(alloc);52 const list = &std.ArrayList([]const u8).init(alloc);
49 if (self.get(k)) |val| {53 if (self.get(k)) |val| {