| author | |
| committer | |
| log | 868105a6cf4c075037d365f18171a52b75f61a3f |
| tree | 4a8143c3e09b219f8be0fabb6c2cdcacccd0cd53 |
| parent | 2ce1b0d0d0d41d4858f2f5481fc299078cf5d44d |
6 files changed, 51 insertions(+), 0 deletions(-)
src/cmd_add.zig+5| ... | ... | @@ -29,6 +29,11 @@ pub fn execute(args: [][]u8) !void { |
| 29 | 29 | try ndl.append(u.Dep{ |
| 30 | 30 | .type = dep_type.?, |
| 31 | 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 | }); |
| 33 | 38 | |
| 34 | 39 | // |
src/cmd_fetch.zig+16| ... | ... | @@ -86,8 +86,21 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { |
| 86 | 86 | } |
| 87 | 87 | switch (d.type) { |
| 88 | 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 | 95 | var dd = try fetch_deps(dir, try std.fmt.allocPrint(gpa, "{}{}", .{p, "/zig.mod"})); |
| 90 | 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 | 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 | 134 | const t = " "; |
| 122 | 135 | const r = try u.repeat(t, tabs); |
| 123 | 136 | for (m.deps) |d| { |
| 137 | if (d.main.len == 0) { | |
| 138 | continue; | |
| 139 | } | |
| 124 | 140 | try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,"build.Pkg{"})}); |
| 125 | 141 | try w.print("{}\n", .{try u.concat(&[_][]const u8{r,t,t,".name = \"",d.name,"\","})}); |
| 126 | 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 | 12 | type: u.DepType, |
| 13 | 13 | path: []const u8, |
| 14 | 14 | |
| 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 | 21 | pub fn clean_path(self: Dep) ![]const u8 { |
| 16 | 22 | var p = self.path; |
| 17 | 23 | p = u.trim_prefix(p, "https://"); |
src/util/modfile.zig+5| ... | ... | @@ -43,6 +43,11 @@ pub const ModFile = struct { |
| 43 | 43 | try dep_list.append(u.Dep{ |
| 44 | 44 | .type = dep_type, |
| 45 | 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 | 1 | const std = @import("std"); |
| 2 | 2 | |
| 3 | const u = @import("index.zig"); | |
| 4 | ||
| 3 | 5 | // |
| 4 | 6 | // |
| 5 | 7 | |
| ... | ... | @@ -7,8 +9,21 @@ pub const Module = struct { |
| 7 | 9 | name: []const u8, |
| 8 | 10 | main: []const u8, |
| 9 | 11 | c_include_dirs: [][]const u8, |
| 12 | c_source_flags: [][]const u8, | |
| 10 | 13 | c_source_files: [][]const u8, |
| 11 | 14 | |
| 12 | 15 | deps: []Module, |
| 13 | 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 | 44 | return null; |
| 45 | 45 | } |
| 46 | 46 | |
| 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 | 51 | pub fn get_string_array(self: Mapping, alloc: *std.mem.Allocator, k: []const u8) ![][]const u8 { |
| 48 | 52 | const list = &std.ArrayList([]const u8).init(alloc); |
| 49 | 53 | if (self.get(k)) |val| { |