authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-05-02 01:57:04 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-05-02 01:57:04 -07:00
logabbca727c328121a78971940e79df3e3afc56cf9
tree8d4b2f483822ce54b4e4ffabefb97b70dac475d6
parentadd6a47275b251b1e435b533da57134dbc9971f8

finally run `zig fmt`, close #8


13 files changed, 107 insertions(+), 106 deletions(-)

build.zig+2-3
...@@ -10,7 +10,7 @@ pub fn build(b: *Builder) void {...@@ -10,7 +10,7 @@ pub fn build(b: *Builder) void {
10 const mode = b.standardReleaseOptions();10 const mode = b.standardReleaseOptions();
1111
12 const use_full_name = b.option(bool, "use-full-name", "") orelse false;12 const use_full_name = b.option(bool, "use-full-name", "") orelse false;
13 const with_arch_os = b.fmt("-{s}-{s}", .{@tagName(target.cpu_arch orelse builtin.arch), @tagName(target.os_tag orelse builtin.os.tag)});13 const with_arch_os = b.fmt("-{s}-{s}", .{ @tagName(target.cpu_arch orelse builtin.arch), @tagName(target.os_tag orelse builtin.os.tag) });
14 const exe_name = b.fmt("{s}{s}", .{ "zigmod", if (use_full_name) with_arch_os else "" });14 const exe_name = b.fmt("{s}{s}", .{ "zigmod", if (use_full_name) with_arch_os else "" });
1515
16 const exe = b.addExecutable(exe_name, "src/main.zig");16 const exe = b.addExecutable(exe_name, "src/main.zig");
...@@ -42,8 +42,7 @@ pub fn build(b: *Builder) void {...@@ -42,8 +42,7 @@ pub fn build(b: *Builder) void {
4242
43 exe.addPackagePath("zigmod", "./src/lib.zig");43 exe.addPackagePath("zigmod", "./src/lib.zig");
44 exe.addPackagePath("ansi", "./libs/zig-ansi/src/lib.zig");44 exe.addPackagePath("ansi", "./libs/zig-ansi/src/lib.zig");
45 }45 } else {
46 else {
47 deps.addAllTo(exe);46 deps.addAllTo(exe);
48 }47 }
4948
src/cmd/fetch.zig+10-12
...@@ -11,7 +11,7 @@ const common = @import("./../common.zig");...@@ -11,7 +11,7 @@ const common = @import("./../common.zig");
1111
12pub fn execute(args: [][]u8) !void {12pub fn execute(args: [][]u8) !void {
13 //13 //
14 const dir = try fs.path.join(gpa, &.{".zigmod", "deps"});14 const dir = try fs.path.join(gpa, &.{ ".zigmod", "deps" });
1515
16 const top_module = try common.collect_deps_deep(dir, "zig.mod", .{16 const top_module = try common.collect_deps_deep(dir, "zig.mod", .{
17 .log = true,17 .log = true,
...@@ -127,7 +127,7 @@ fn print_paths(w: fs.File.Writer, list: []u.Module) !void {...@@ -127,7 +127,7 @@ fn print_paths(w: fs.File.Writer, list: []u.Module) !void {
127 try w.print(" \"\",\n", .{});127 try w.print(" \"\",\n", .{});
128 } else {128 } else {
129 const s = std.fs.path.sep_str;129 const s = std.fs.path.sep_str;
130 try w.print(" \"{}{}{}\",\n", .{std.zig.fmtEscapes(s), std.zig.fmtEscapes(mod.clean_path), std.zig.fmtEscapes(s)});130 try w.print(" \"{}{}{}\",\n", .{ std.zig.fmtEscapes(s), std.zig.fmtEscapes(mod.clean_path), std.zig.fmtEscapes(s) });
131 }131 }
132 }132 }
133}133}
...@@ -149,13 +149,12 @@ fn print_deps(w: fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32, array:...@@ -149,13 +149,12 @@ fn print_deps(w: fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32, array:
149 continue;149 continue;
150 }150 }
151 if (!array) {151 if (!array) {
152 try w.print(" pub const {s} = packages[{}];\n", .{std.mem.replaceOwned(u8, gpa, d.name, "-", "_"), i});152 try w.print(" pub const {s} = packages[{}];\n", .{ std.mem.replaceOwned(u8, gpa, d.name, "-", "_"), i });
153 }153 } else {
154 else {
155 try w.print(" package_data._{s},\n", .{d.id});154 try w.print(" package_data._{s},\n", .{d.id});
156 }155 }
157 }156 }
158 try w.print("{s}", .{try u.concat(&.{r,"}"})});157 try w.print("{s}", .{try u.concat(&.{ r, "}" })});
159}158}
160159
161fn print_incl_dirs_to(w: fs.File.Writer, list: []u.Module) !void {160fn print_incl_dirs_to(w: fs.File.Writer, list: []u.Module) !void {
...@@ -165,7 +164,7 @@ fn print_incl_dirs_to(w: fs.File.Writer, list: []u.Module) !void {...@@ -165,7 +164,7 @@ fn print_incl_dirs_to(w: fs.File.Writer, list: []u.Module) !void {
165 }164 }
166 for (mod.c_include_dirs) |it| {165 for (mod.c_include_dirs) |it| {
167 if (i > 0) {166 if (i > 0) {
168 try w.print(" cache ++ _paths[{}] ++ \"{}\",\n", .{i-1, std.zig.fmtEscapes(it)});167 try w.print(" cache ++ _paths[{}] ++ \"{}\",\n", .{ i - 1, std.zig.fmtEscapes(it) });
169 } else {168 } else {
170 try w.print(" \"{}\",\n", .{std.zig.fmtEscapes(it)});169 try w.print(" \"{}\",\n", .{std.zig.fmtEscapes(it)});
171 }170 }
...@@ -180,9 +179,9 @@ fn print_csrc_dirs_to(w: fs.File.Writer, list: []u.Module) !void {...@@ -180,9 +179,9 @@ fn print_csrc_dirs_to(w: fs.File.Writer, list: []u.Module) !void {
180 }179 }
181 for (mod.c_source_files) |it| {180 for (mod.c_source_files) |it| {
182 if (i > 0) {181 if (i > 0) {
183 try w.print(" {s}_ids[{}], cache ++ _paths[{}] ++ \"{s}\"{s},\n", .{"[_][]const u8{", i-1, i-1, it, "}"});182 try w.print(" {s}_ids[{}], cache ++ _paths[{}] ++ \"{s}\"{s},\n", .{ "[_][]const u8{", i - 1, i - 1, it, "}" });
184 } else {183 } else {
185 try w.print(" {s}_ids[{}], \".{}/{s}\"{s},\n", .{"[_][]const u8{", i-1, std.zig.fmtEscapes(mod.clean_path), it, "}"});184 try w.print(" {s}_ids[{}], \".{}/{s}\"{s},\n", .{ "[_][]const u8{", i - 1, std.zig.fmtEscapes(mod.clean_path), it, "}" });
186 }185 }
187 }186 }
188 }187 }
...@@ -196,12 +195,11 @@ fn print_csrc_flags_to(w: fs.File.Writer, list: []u.Module) !void {...@@ -196,12 +195,11 @@ fn print_csrc_flags_to(w: fs.File.Writer, list: []u.Module) !void {
196 if (mod.c_source_flags.len == 0 and mod.c_source_files.len == 0) {195 if (mod.c_source_flags.len == 0 and mod.c_source_files.len == 0) {
197 continue;196 continue;
198 }197 }
199 try w.print(" pub const @\"{s}\" = {s}", .{mod.id, "&.{"});198 try w.print(" pub const @\"{s}\" = {s}", .{ mod.id, "&.{" });
200 for (mod.c_source_flags) |it| {199 for (mod.c_source_flags) |it| {
201 try w.print("\"{}\",", .{std.zig.fmtEscapes(it)});200 try w.print("\"{}\",", .{std.zig.fmtEscapes(it)});
202 }201 }
203 try w.print("{s};\n", .{"}"});202 try w.print("{s};\n", .{"}"});
204
205 }203 }
206}204}
207205
...@@ -219,7 +217,7 @@ fn print_pkg_data_to(w: fs.File.Writer, list: *std.ArrayList(u.Module), list2: *...@@ -219,7 +217,7 @@ fn print_pkg_data_to(w: fs.File.Writer, list: *std.ArrayList(u.Module), list2: *
219 while (i < list.items.len) : (i += 1) {217 while (i < list.items.len) : (i += 1) {
220 const mod = list.items[i];218 const mod = list.items[i];
221 if (contains_all(mod.deps, list2)) {219 if (contains_all(mod.deps, list2)) {
222 try w.print(" pub const _{s} = std.build.Pkg{{ .name = \"{s}\", .path = cache ++ \"/{}/{s}\", .dependencies = &[_]std.build.Pkg{{", .{mod.id, mod.name, std.zig.fmtEscapes(mod.clean_path), mod.main});220 try w.print(" pub const _{s} = std.build.Pkg{{ .name = \"{s}\", .path = cache ++ \"/{}/{s}\", .dependencies = &[_]std.build.Pkg{{", .{ mod.id, mod.name, std.zig.fmtEscapes(mod.clean_path), mod.main });
223 for (mod.deps) |d| {221 for (mod.deps) |d| {
224 if (d.main.len > 0) {222 if (d.main.len > 0) {
225 try w.print(" _{s},", .{d.id});223 try w.print(" _{s},", .{d.id});
src/cmd/init.zig+4-4
...@@ -19,7 +19,7 @@ pub fn execute(args: [][]u8) !void {...@@ -19,7 +19,7 @@ pub fn execute(args: [][]u8) !void {
19 try fwriter.print("main: {s}\n", .{mainf});19 try fwriter.print("main: {s}\n", .{mainf});
20 try fwriter.print("dependencies:\n", .{});20 try fwriter.print("dependencies:\n", .{});
2121
22 u.print("Initialized a new package named {s} with entry point {s}", .{name, mainf});22 u.print("Initialized a new package named {s} with entry point {s}", .{ name, mainf });
23}23}
2424
25fn detect_pkgname(def: []const u8) ![]const u8 {25fn detect_pkgname(def: []const u8) ![]const u8 {
...@@ -28,7 +28,7 @@ fn detect_pkgname(def: []const u8) ![]const u8 {...@@ -28,7 +28,7 @@ fn detect_pkgname(def: []const u8) ![]const u8 {
28 }28 }
29 const dpath = try std.fs.cwd().realpathAlloc(gpa, "build.zig");29 const dpath = try std.fs.cwd().realpathAlloc(gpa, "build.zig");
30 const split = try u.split(dpath, std.fs.path.sep_str);30 const split = try u.split(dpath, std.fs.path.sep_str);
31 var name = split[split.len-2];31 var name = split[split.len - 2];
32 name = u.trim_prefix(name, "zig-");32 name = u.trim_prefix(name, "zig-");
33 u.assert(name.len > 0, "package name must not be an empty string", .{});33 u.assert(name.len > 0, "package name must not be an empty string", .{});
34 return name;34 return name;
...@@ -42,10 +42,10 @@ fn detct_mainfile(def: []const u8) ![]const u8 {...@@ -42,10 +42,10 @@ fn detct_mainfile(def: []const u8) ![]const u8 {
42 }42 }
43 }43 }
44 }44 }
45 if (try u.does_file_exist(try std.fs.path.join(gpa, &.{"src", "lib.zig"}))) {45 if (try u.does_file_exist(try std.fs.path.join(gpa, &.{ "src", "lib.zig" }))) {
46 return "src/lib.zig";46 return "src/lib.zig";
47 }47 }
48 if (try u.does_file_exist(try std.fs.path.join(gpa, &.{"src", "main.zig"}))) {48 if (try u.does_file_exist(try std.fs.path.join(gpa, &.{ "src", "main.zig" }))) {
49 return "src/main.zig";49 return "src/main.zig";
50 }50 }
51 u.assert(false, "unable to detect package entry point", .{});51 u.assert(false, "unable to detect package entry point", .{});
src/cmd/license.zig+1-1
...@@ -18,7 +18,7 @@ const Map = std.StringArrayHashMap(*List);...@@ -18,7 +18,7 @@ const Map = std.StringArrayHashMap(*List);
1818
19pub fn execute(args: [][]u8) !void {19pub fn execute(args: [][]u8) !void {
20 //20 //
21 const dir = try std.fs.path.join(gpa, &.{".zigmod", "deps"});21 const dir = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });
2222
23 const top_module = try common.collect_deps_deep(dir, "zig.mod", .{23 const top_module = try common.collect_deps_deep(dir, "zig.mod", .{
24 .log = false,24 .log = false,
src/cmd/sum.zig+8-4
...@@ -10,7 +10,7 @@ const common = @import("./../common.zig");...@@ -10,7 +10,7 @@ const common = @import("./../common.zig");
1010
11pub fn execute(args: [][]u8) !void {11pub fn execute(args: [][]u8) !void {
12 //12 //
13 const dir = try std.fs.path.join(gpa, &.{".zigmod", "deps"});13 const dir = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });
1414
15 const top_module = try common.collect_deps_deep(dir, "zig.mod", .{15 const top_module = try common.collect_deps_deep(dir, "zig.mod", .{
16 .log = false,16 .log = false,
...@@ -27,9 +27,13 @@ pub fn execute(args: [][]u8) !void {...@@ -27,9 +27,13 @@ pub fn execute(args: [][]u8) !void {
27 try common.collect_pkgs(top_module, module_list);27 try common.collect_pkgs(top_module, module_list);
2828
29 for (module_list.items) |m| {29 for (module_list.items) |m| {
30 if (m.clean_path.len == 0) { continue; }30 if (m.clean_path.len == 0) {
31 if (std.mem.eql(u8, m.clean_path, "../..")) { continue; }31 continue;
32 }
33 if (std.mem.eql(u8, m.clean_path, "../..")) {
34 continue;
35 }
32 const hash = try m.get_hash(dir);36 const hash = try m.get_hash(dir);
33 try w.print("{s} {s}\n", .{hash, m.clean_path});37 try w.print("{s} {s}\n", .{ hash, m.clean_path });
34 }38 }
35}39}
src/cmd/zpm_add.zig+5-5
...@@ -36,7 +36,7 @@ pub fn execute(args: [][]u8) !void {...@@ -36,7 +36,7 @@ pub fn execute(args: [][]u8) !void {
3636
37 const w = client.writer();37 const w = client.writer();
38 try w.print("GET {s} HTTP/1.1\r\n", .{url.path});38 try w.print("GET {s} HTTP/1.1\r\n", .{url.path});
39 try w.print("Host: {s}:{}\r\n", .{url.host.name, url.port.?});39 try w.print("Host: {s}:{}\r\n", .{ url.host.name, url.port.? });
40 try w.writeAll("Accept: application/json; charset=UTF-8\r\n");40 try w.writeAll("Accept: application/json; charset=UTF-8\r\n");
41 try w.writeAll("Connection: close\r\n");41 try w.writeAll("Connection: close\r\n");
42 try w.writeAll("\r\n");42 try w.writeAll("\r\n");
...@@ -56,7 +56,7 @@ pub fn execute(args: [][]u8) !void {...@@ -56,7 +56,7 @@ pub fn execute(args: [][]u8) !void {
56 const html_contents = data.items[index..];56 const html_contents = data.items[index..];
5757
58 var stream = std.json.TokenStream.init(html_contents[4..]);58 var stream = std.json.TokenStream.init(html_contents[4..]);
59 const res = try std.json.parse([]Zpm.Package, &stream, .{ .allocator = gpa, });59 const res = try std.json.parse([]Zpm.Package, &stream, .{ .allocator = gpa });
6060
61 const found = blk: {61 const found = blk: {
62 for (res) |pkg| {62 for (res) |pkg| {
...@@ -77,14 +77,14 @@ pub fn execute(args: [][]u8) !void {...@@ -77,14 +77,14 @@ pub fn execute(args: [][]u8) !void {
77 }77 }
78 }78 }
7979
80 const file = try std.fs.cwd().openFile("zig.mod", .{ .read=true, .write=true });80 const file = try std.fs.cwd().openFile("zig.mod", .{ .read = true, .write = true });
81 try file.seekTo(try file.getEndPos());81 try file.seekTo(try file.getEndPos());
82 82
83 const file_w = file.writer();83 const file_w = file.writer();
84 try file_w.print("\n", .{});84 try file_w.print("\n", .{});
85 try file_w.print(" - src: git {s}\n", .{found.git});85 try file_w.print(" - src: git {s}\n", .{found.git});
86 try file_w.print(" name: {s}\n", .{found.name});86 try file_w.print(" name: {s}\n", .{found.name});
87 try file_w.print(" main: {s}\n", .{found.root_file.?[1..]});87 try file_w.print(" main: {s}\n", .{found.root_file.?[1..]});
8888
89 std.log.info("Successfully added package {s} by {s}", .{found.name, found.author});89 std.log.info("Successfully added package {s} by {s}", .{ found.name, found.author });
90}90}
src/common.zig+23-17
...@@ -68,10 +68,12 @@ pub fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void...@@ -68,10 +68,12 @@ pub fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void
68}68}
6969
70fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime options: CollectOptions) ![]const u8 {70fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime options: CollectOptions) ![]const u8 {
71 const p = try fs.path.join(gpa, &.{basedir, try d.clean_path()});71 const p = try fs.path.join(gpa, &.{ basedir, try d.clean_path() });
72 const pv = try fs.path.join(gpa, &.{basedir, try d.clean_path_v()});72 const pv = try fs.path.join(gpa, &.{ basedir, try d.clean_path_v() });
73 const tempdir = try fs.path.join(gpa, &.{basedir, "temp"});73 const tempdir = try fs.path.join(gpa, &.{ basedir, "temp" });
74 if (options.log) { u.print("fetch: {s}: {s}: {s}", .{parent_name, @tagName(d.type), d.path}); }74 if (options.log) {
75 u.print("fetch: {s}: {s}: {s}", .{ parent_name, @tagName(d.type), d.path });
76 }
75 switch (d.type) {77 switch (d.type) {
76 .system_lib => {78 .system_lib => {
77 // no op79 // no op
...@@ -89,13 +91,15 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime o...@@ -89,13 +91,15 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime o
89 };91 };
90 if (try u.does_folder_exist(pv)) {92 if (try u.does_folder_exist(pv)) {
91 if (vers.id == .branch) {93 if (vers.id == .branch) {
92 if (options.update) { try d.type.update(pv, d.path); }94 if (options.update) {
95 try d.type.update(pv, d.path);
96 }
93 }97 }
94 return pv;98 return pv;
95 }99 }
96 try d.type.pull(d.path, tempdir);100 try d.type.pull(d.path, tempdir);
97 if ((try u.run_cmd(tempdir, &.{"git", "checkout", vers.string})) > 0) {101 if ((try u.run_cmd(tempdir, &.{ "git", "checkout", vers.string })) > 0) {
98 u.assert(false, "fetch: git: {s}: {s} {s} does not exist", .{d.path, @tagName(vers.id), vers.string});102 u.assert(false, "fetch: git: {s}: {s} {s} does not exist", .{ d.path, @tagName(vers.id), vers.string });
99 }103 }
100 const td_fd = try fs.cwd().openDir(basedir, .{});104 const td_fd = try fs.cwd().openDir(basedir, .{});
101 try u.mkdir_all(pv);105 try u.mkdir_all(pv);
...@@ -108,18 +112,20 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime o...@@ -108,18 +112,20 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime o
108 }112 }
109 if (!try u.does_folder_exist(p)) {113 if (!try u.does_folder_exist(p)) {
110 try d.type.pull(d.path, p);114 try d.type.pull(d.path, p);
111 }115 } else {
112 else {116 if (options.update) {
113 if (options.update) { try d.type.update(p, d.path); }117 try d.type.update(p, d.path);
118 }
114 }119 }
115 return p;120 return p;
116 },121 },
117 .hg => {122 .hg => {
118 if (!try u.does_folder_exist(p)) {123 if (!try u.does_folder_exist(p)) {
119 try d.type.pull(d.path, p);124 try d.type.pull(d.path, p);
120 }125 } else {
121 else {126 if (options.update) {
122 if (options.update) { try d.type.update(p, d.path); }127 try d.type.update(p, d.path);
128 }
123 }129 }
124 return p;130 return p;
125 },131 },
...@@ -132,20 +138,20 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime o...@@ -132,20 +138,20 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime o
132 if (try u.does_folder_exist(pv)) {138 if (try u.does_folder_exist(pv)) {
133 return pv;139 return pv;
134 }140 }
135 const file_path = try std.fs.path.join(gpa, &.{pv, file_name});141 const file_path = try std.fs.path.join(gpa, &.{ pv, file_name });
136 try d.type.pull(d.path, pv);142 try d.type.pull(d.path, pv);
137 if (try u.validate_hash(d.version, file_path)) {143 if (try u.validate_hash(d.version, file_path)) {
138 try std.fs.cwd().deleteFile(file_path);144 try std.fs.cwd().deleteFile(file_path);
139 return pv;145 return pv;
140 }146 }
141 try u.rm_recv(pv);147 try u.rm_recv(pv);
142 u.assert(false, "{s} does not match hash {s}", .{d.path, d.version});148 u.assert(false, "{s} does not match hash {s}", .{ d.path, d.version });
143 return p;149 return p;
144 }150 }
145 if (try u.does_folder_exist(p)) {151 if (try u.does_folder_exist(p)) {
146 try u.rm_recv(p);152 try u.rm_recv(p);
147 }153 }
148 const file_path = try std.fs.path.join(gpa, &.{p, file_name});154 const file_path = try std.fs.path.join(gpa, &.{ p, file_name });
149 try d.type.pull(d.path, p);155 try d.type.pull(d.path, p);
150 try std.fs.deleteFileAbsolute(file_path);156 try std.fs.deleteFileAbsolute(file_path);
151 return p;157 return p;
...@@ -173,7 +179,7 @@ fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8...@@ -173,7 +179,7 @@ fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8
173 });179 });
174 },180 },
175 else => blk: {181 else => blk: {
176 var dd = try collect_deps(dir, try u.concat(&.{moddir, "/zig.mod"}), options) catch |e| switch (e) {182 var dd = try collect_deps(dir, try u.concat(&.{ moddir, "/zig.mod" }), options) catch |e| switch (e) {
177 error.FileNotFound => {183 error.FileNotFound => {
178 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) {184 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) {
179 var mod_from = try u.Module.from(d);185 var mod_from = try u.Module.from(d);
src/main.zig+2-3
...@@ -10,7 +10,6 @@ pub const common = @import("./common.zig");...@@ -10,7 +10,6 @@ pub const common = @import("./common.zig");
10//10//
1111
12pub fn main() !void {12pub fn main() !void {
13
14 const gpa = std.heap.c_allocator;13 const gpa = std.heap.c_allocator;
1514
16 const proc_args = try std.process.argsAlloc(gpa);15 const proc_args = try std.process.argsAlloc(gpa);
...@@ -21,7 +20,7 @@ pub fn main() !void {...@@ -21,7 +20,7 @@ pub fn main() !void {
21 @import("build_options").version,20 @import("build_options").version,
22 @tagName(builtin.os.tag),21 @tagName(builtin.os.tag),
23 @tagName(builtin.arch),22 @tagName(builtin.arch),
24 @tagName(builtin.abi)23 @tagName(builtin.abi),
25 });24 });
26 return;25 return;
27 }26 }
...@@ -41,7 +40,7 @@ pub fn main() !void {...@@ -41,7 +40,7 @@ pub fn main() !void {
41 for (args[1..]) |item| {40 for (args[1..]) |item| {
42 try sub_cmd_args.append(item);41 try sub_cmd_args.append(item);
43 }42 }
44 const result = std.ChildProcess.exec(.{ .allocator = gpa, .argv = sub_cmd_args.items, }) catch |e| switch(e) {43 const result = std.ChildProcess.exec(.{ .allocator = gpa, .argv = sub_cmd_args.items }) catch |e| switch (e) {
45 else => return e,44 else => return e,
46 error.FileNotFound => {45 error.FileNotFound => {
47 u.assert(false, "unknown command \"{s}\" for \"zigmod\"", .{args[0]});46 u.assert(false, "unknown command \"{s}\" for \"zigmod\"", .{args[0]});
src/util/dep.zig+3-3
...@@ -31,15 +31,15 @@ pub const Dep = struct {...@@ -31,15 +31,15 @@ pub const Dep = struct {
31 p = u.trim_prefix(p, "https://");31 p = u.trim_prefix(p, "https://");
32 p = u.trim_prefix(p, "git://");32 p = u.trim_prefix(p, "git://");
33 p = u.trim_suffix(u8, p, ".git");33 p = u.trim_suffix(u8, p, ".git");
34 p = try std.mem.join(gpa, "/", &.{@tagName(self.type), p});34 p = try std.mem.join(gpa, "/", &.{ @tagName(self.type), p });
35 return p;35 return p;
36 }36 }
3737
38 pub fn clean_path_v(self: Dep) ![]const u8 {38 pub fn clean_path_v(self: Dep) ![]const u8 {
39 if (self.type == .http and self.version.len > 0) {39 if (self.type == .http and self.version.len > 0) {
40 return std.mem.join(gpa, "/", &.{"v", @tagName(self.type), self.version[0..20]});40 return std.mem.join(gpa, "/", &.{ "v", @tagName(self.type), self.version[0..20] });
41 }41 }
42 return std.mem.join(gpa, "/", &.{"v", try self.clean_path(), self.version});42 return std.mem.join(gpa, "/", &.{ "v", try self.clean_path(), self.version });
43 }43 }
4444
45 pub fn is_for_this(self: Dep) bool {45 pub fn is_for_this(self: Dep) bool {
src/util/dep_type.zig+11-15
...@@ -6,6 +6,7 @@ const u = @import("./index.zig");...@@ -6,6 +6,7 @@ const u = @import("./index.zig");
6//6//
7//7//
88
9// zig fmt: off
9pub const DepType = enum {10pub const DepType = enum {
10 system_lib, // std.build.LibExeObjStep.linkSystemLibrary11 system_lib, // std.build.LibExeObjStep.linkSystemLibrary
11 git, // https://git-scm.com/12 git, // https://git-scm.com/
...@@ -33,25 +34,20 @@ pub const DepType = enum {...@@ -33,25 +34,20 @@ pub const DepType = enum {
33 switch (self) {34 switch (self) {
34 .system_lib => {},35 .system_lib => {},
35 .git => {36 .git => {
36 _ = try u.run_cmd(null, &.{"git", "clone", "--recurse-submodules", rpath, dpath});37 _ = try u.run_cmd(null, &.{ "git", "clone", "--recurse-submodules", rpath, dpath });
37 },38 },
38 .hg => {39 .hg => {
39 _ = try u.run_cmd(null, &.{"hg", "clone", rpath, dpath});40 _ = try u.run_cmd(null, &.{ "hg", "clone", rpath, dpath });
40 },41 },
41 .http => {42 .http => {
42 try u.mkdir_all(dpath);43 try u.mkdir_all(dpath);
43 _ = try u.run_cmd(dpath, &.{"wget", rpath});44 _ = try u.run_cmd(dpath, &.{ "wget", rpath });
44 const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").?+1..];45 const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").? + 1 ..];
45 if (std.mem.endsWith(u8, f, ".zip")) {46 if (std.mem.endsWith(u8, f, ".zip")) {
46 _ = try u.run_cmd(dpath, &.{"unzip", f, "-d", "."});47 _ = try u.run_cmd(dpath, &.{ "unzip", f, "-d", "." });
47 }48 }
48 if (49 if (std.mem.endsWith(u8, f, ".tar") or std.mem.endsWith(u8, f, ".tar.gz") or std.mem.endsWith(u8, f, ".tar.xz") or std.mem.endsWith(u8, f, ".tar.zst")) {
49 std.mem.endsWith(u8, f, ".tar")50 _ = try u.run_cmd(dpath, &.{ "tar", "-xf", f, "-C", "." });
50 or std.mem.endsWith(u8, f, ".tar.gz")
51 or std.mem.endsWith(u8, f, ".tar.xz")
52 or std.mem.endsWith(u8, f, ".tar.zst")
53 ) {
54 _ = try u.run_cmd(dpath, &.{"tar", "-xf", f, "-C", "."});
55 }51 }
56 },52 },
57 }53 }
...@@ -61,11 +57,11 @@ pub const DepType = enum {...@@ -61,11 +57,11 @@ pub const DepType = enum {
61 switch (self) {57 switch (self) {
62 .system_lib => {},58 .system_lib => {},
63 .git => {59 .git => {
64 _ = try u.run_cmd(dpath, &.{"git", "fetch"});60 _ = try u.run_cmd(dpath, &.{ "git", "fetch" });
65 _ = try u.run_cmd(dpath, &.{"git", "pull"});61 _ = try u.run_cmd(dpath, &.{ "git", "pull" });
66 },62 },
67 .hg => {63 .hg => {
68 _ = try u.run_cmd(dpath, &.{"hg", "pull"});64 _ = try u.run_cmd(dpath, &.{ "hg", "pull" });
69 },65 },
70 .http => {66 .http => {
71 //67 //
src/util/funcs.zig+16-16
...@@ -13,7 +13,7 @@ pub const mb = kb * 1024;...@@ -13,7 +13,7 @@ pub const mb = kb * 1024;
13pub const gb = mb * 1024;13pub const gb = mb * 1024;
1414
15pub fn print(comptime fmt: []const u8, args: anytype) void {15pub fn print(comptime fmt: []const u8, args: anytype) void {
16 std.debug.print(fmt++"\n", args);16 std.debug.print(fmt ++ "\n", args);
17}17}
1818
19pub fn assert(ok: bool, comptime fmt: []const u8, args: anytype) void {19pub fn assert(ok: bool, comptime fmt: []const u8, args: anytype) void {
...@@ -72,16 +72,16 @@ pub fn does_folder_exist(fpath: []const u8) !bool {...@@ -72,16 +72,16 @@ pub fn does_folder_exist(fpath: []const u8) !bool {
7272
73pub fn _join(comptime delim: []const u8, comptime xs: [][]const u8) []const u8 {73pub fn _join(comptime delim: []const u8, comptime xs: [][]const u8) []const u8 {
74 var buf: []const u8 = "";74 var buf: []const u8 = "";
75 for (xs) |x,i| {75 for (xs) |x, i| {
76 buf = buf ++ x;76 buf = buf ++ x;
77 if (i < xs.len-1) buf = buf ++ delim;77 if (i < xs.len - 1) buf = buf ++ delim;
78 }78 }
79 return buf;79 return buf;
80}80}
8181
82pub fn trim_suffix(comptime T: type, in: []const T, suffix: []const T) []const T {82pub fn trim_suffix(comptime T: type, in: []const T, suffix: []const T) []const T {
83 if (std.mem.endsWith(T, in, suffix)) {83 if (std.mem.endsWith(T, in, suffix)) {
84 return in[0..in.len-suffix.len];84 return in[0 .. in.len - suffix.len];
85 }85 }
86 return in;86 return in;
87}87}
...@@ -98,7 +98,7 @@ pub fn repeat(s: []const u8, times: i32) ![]const u8 {...@@ -98,7 +98,7 @@ pub fn repeat(s: []const u8, times: i32) ![]const u8 {
98pub fn join(xs: [][]const u8, delim: []const u8) ![]const u8 {98pub fn join(xs: [][]const u8, delim: []const u8) ![]const u8 {
99 var res: []const u8 = "";99 var res: []const u8 = "";
100 for (xs) |x, i| {100 for (xs) |x, i| {
101 res = try std.fmt.allocPrint(gpa, "{s}{s}{s}", .{res, x, if (i < xs.len-1) delim else ""});101 res = try std.fmt.allocPrint(gpa, "{s}{s}{s}", .{ res, x, if (i < xs.len - 1) delim else "" });
102 }102 }
103 return res;103 return res;
104}104}
...@@ -106,7 +106,7 @@ pub fn join(xs: [][]const u8, delim: []const u8) ![]const u8 {...@@ -106,7 +106,7 @@ pub fn join(xs: [][]const u8, delim: []const u8) ![]const u8 {
106pub fn concat(items: [][]const u8) ![]const u8 {106pub fn concat(items: [][]const u8) ![]const u8 {
107 var buf: []const u8 = "";107 var buf: []const u8 = "";
108 for (items) |x| {108 for (items) |x| {
109 buf = try std.fmt.allocPrint(gpa, "{s}{s}", .{buf, x});109 buf = try std.fmt.allocPrint(gpa, "{s}{s}", .{ buf, x });
110 }110 }
111 return buf;111 return buf;
112}112}
...@@ -150,15 +150,14 @@ pub fn file_list(dpath: []const u8, list: *std.ArrayList([]const u8)) !void {...@@ -150,15 +150,14 @@ pub fn file_list(dpath: []const u8, list: *std.ArrayList([]const u8)) !void {
150 continue;150 continue;
151 }151 }
152 try list.append(try gpa.dupe(u8, entry.path));152 try list.append(try gpa.dupe(u8, entry.path));
153 }153 } else {
154 else {
155 break;154 break;
156 }155 }
157 }156 }
158}157}
159158
160pub fn run_cmd(dir: ?[]const u8, args: []const []const u8) !u32 {159pub fn run_cmd(dir: ?[]const u8, args: []const []const u8) !u32 {
161 const result = std.ChildProcess.exec(.{ .allocator = gpa, .cwd = dir, .argv = args, .max_output_bytes = std.math.maxInt(usize) }) catch |e| switch(e) {160 const result = std.ChildProcess.exec(.{ .allocator = gpa, .cwd = dir, .argv = args, .max_output_bytes = std.math.maxInt(usize) }) catch |e| switch (e) {
162 error.FileNotFound => {161 error.FileNotFound => {
163 u.assert(false, "\"{s}\" command not found", .{args[0]});162 u.assert(false, "\"{s}\" command not found", .{args[0]});
164 unreachable;163 unreachable;
...@@ -191,7 +190,7 @@ pub fn mkdir_all(dpath: []const u8) anyerror!void {...@@ -191,7 +190,7 @@ pub fn mkdir_all(dpath: []const u8) anyerror!void {
191 if (dpath.len == 0) {190 if (dpath.len == 0) {
192 return;191 return;
193 }192 }
194 const d = if (dpath[dpath.len-1] == std.fs.path.sep) dpath[0..dpath.len-1] else dpath;193 const d = if (dpath[dpath.len - 1] == std.fs.path.sep) dpath[0 .. dpath.len - 1] else dpath;
195 const ps = std.fs.path.sep_str;194 const ps = std.fs.path.sep_str;
196 if (std.mem.lastIndexOf(u8, d, ps)) |index| {195 if (std.mem.lastIndexOf(u8, d, ps)) |index| {
197 try mkdir_all(d[0..index]);196 try mkdir_all(d[0..index]);
...@@ -210,14 +209,15 @@ pub fn rm_recv(path: []const u8) anyerror!void {...@@ -210,14 +209,15 @@ pub fn rm_recv(path: []const u8) anyerror!void {
210 defer file.close();209 defer file.close();
211 const s = try file.stat();210 const s = try file.stat();
212 if (s.kind == .Directory) {211 if (s.kind == .Directory) {
213 const dir = std.fs.cwd().openDir(abs_path, .{ .iterate=true, }) catch unreachable;212 const dir = std.fs.cwd().openDir(abs_path, .{
213 .iterate = true,
214 }) catch unreachable;
214 var iter = dir.iterate();215 var iter = dir.iterate();
215 while (try iter.next()) |item| {216 while (try iter.next()) |item| {
216 try rm_recv(try std.fs.path.join(gpa, &.{abs_path, item.name}));217 try rm_recv(try std.fs.path.join(gpa, &.{ abs_path, item.name }));
217 }218 }
218 try std.fs.deleteDirAbsolute(abs_path);219 try std.fs.deleteDirAbsolute(abs_path);
219 }220 } else {
220 else {
221 try std.fs.deleteFileAbsolute(abs_path);221 try std.fs.deleteFileAbsolute(abs_path);
222 }222 }
223}223}
...@@ -231,7 +231,7 @@ pub fn random_string(len: usize) ![]const u8 {...@@ -231,7 +231,7 @@ pub fn random_string(len: usize) ![]const u8 {
231 var buf = try gpa.alloc(u8, len);231 var buf = try gpa.alloc(u8, len);
232 var i: usize = 0;232 var i: usize = 0;
233 while (i < len) : (i += 1) {233 while (i < len) : (i += 1) {
234 buf[i] = alphabet[r.int(usize)%alphabet.len];234 buf[i] = alphabet[r.int(usize) % alphabet.len];
235 }235 }
236 return buf;236 return buf;
237}237}
...@@ -272,7 +272,7 @@ pub fn validate_hash(input: []const u8, file_path: []const u8) !bool {...@@ -272,7 +272,7 @@ pub fn validate_hash(input: []const u8, file_path: []const u8) !bool {
272 };272 };
273 const result = std.mem.eql(u8, expected, actual);273 const result = std.mem.eql(u8, expected, actual);
274 if (!result) {274 if (!result) {
275 std.log.info("expected: {s}, actual: {s}", .{expected, actual});275 std.log.info("expected: {s}, actual: {s}", .{ expected, actual });
276 }276 }
277 return result;277 return result;
278}278}
src/util/module.zig+3-3
...@@ -46,7 +46,7 @@ pub const Module = struct {...@@ -46,7 +46,7 @@ pub const Module = struct {
4646
47 pub fn get_hash(self: Module, cdpath: []const u8) ![]const u8 {47 pub fn get_hash(self: Module, cdpath: []const u8) ![]const u8 {
48 const file_list_1 = &std.ArrayList([]const u8).init(gpa);48 const file_list_1 = &std.ArrayList([]const u8).init(gpa);
49 try u.file_list(try u.concat(&.{cdpath, "/", self.clean_path}), file_list_1);49 try u.file_list(try u.concat(&.{ cdpath, "/", self.clean_path }), file_list_1);
5050
51 const file_list_2 = &std.ArrayList([]const u8).init(gpa);51 const file_list_2 = &std.ArrayList([]const u8).init(gpa);
52 for (file_list_1.items) |item| {52 for (file_list_1.items) |item| {
...@@ -64,10 +64,10 @@ pub const Module = struct {...@@ -64,10 +64,10 @@ pub const Module = struct {
6464
65 const h = &std.crypto.hash.Blake3.init(.{});65 const h = &std.crypto.hash.Blake3.init(.{});
66 for (file_list_2.items) |item| {66 for (file_list_2.items) |item| {
67 const abs_path = try u.concat(&.{cdpath, "/", self.clean_path, "/", item});67 const abs_path = try u.concat(&.{ cdpath, "/", self.clean_path, "/", item });
68 const file = try std.fs.cwd().openFile(abs_path, .{});68 const file = try std.fs.cwd().openFile(abs_path, .{});
69 defer file.close();69 defer file.close();
70 const input = try file.reader().readAllAlloc(gpa, u.mb*100);70 const input = try file.reader().readAllAlloc(gpa, u.mb * 100);
71 h.update(input);71 h.update(input);
72 }72 }
73 var out: [32]u8 = undefined;73 var out: [32]u8 = undefined;
src/util/yaml.zig+19-20
...@@ -122,7 +122,6 @@ pub const Mapping = struct {...@@ -122,7 +122,6 @@ pub const Mapping = struct {
122//122//
123123
124pub fn parse(alloc: *std.mem.Allocator, input: []const u8) !Document {124pub fn parse(alloc: *std.mem.Allocator, input: []const u8) !Document {
125
126 var parser: c.yaml_parser_t = undefined;125 var parser: c.yaml_parser_t = undefined;
127 _ = c.yaml_parser_initialize(&parser);126 _ = c.yaml_parser_initialize(&parser);
128127
...@@ -139,7 +138,7 @@ pub fn parse(alloc: *std.mem.Allocator, input: []const u8) !Document {...@@ -139,7 +138,7 @@ pub fn parse(alloc: *std.mem.Allocator, input: []const u8) !Document {
139 }138 }
140139
141 const et = @enumToInt(event.type);140 const et = @enumToInt(event.type);
142 try all_events.append(.{.event = event});141 try all_events.append(.{ .event = event });
143 c.yaml_event_delete(&event);142 c.yaml_event_delete(&event);
144143
145 if (et == c.YAML_STREAM_END_EVENT) {144 if (et == c.YAML_STREAM_END_EVENT) {
...@@ -196,11 +195,11 @@ fn condense_event_list(list: *std.ArrayList(Item), lines: Array) !void {...@@ -196,11 +195,11 @@ fn condense_event_list(list: *std.ArrayList(Item), lines: Array) !void {
196}195}
197196
198fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), lines: Array) !?usize {197fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), lines: Array) !?usize {
199 if (at >= from.len-1) {198 if (at >= from.len - 1) {
200 return null;199 return null;
201 }200 }
202 const t = from[at];201 const t = from[at];
203 const n = from[at+1];202 const n = from[at + 1];
204203
205 if (!(t == .event and @enumToInt(t.event.type) == c.YAML_SCALAR_EVENT)) {204 if (!(t == .event and @enumToInt(t.event.type) == c.YAML_SCALAR_EVENT)) {
206 return null;205 return null;
...@@ -212,7 +211,7 @@ fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), li...@@ -212,7 +211,7 @@ fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), li
212 .value = Value{ .string = get_event_string(n.event, lines) },211 .value = Value{ .string = get_event_string(n.event, lines) },
213 },212 },
214 });213 });
215 return 0+2-1;214 return 0 + 2 - 1;
216 }215 }
217 if (n == .sequence) {216 if (n == .sequence) {
218 try to.append(Item{217 try to.append(Item{
...@@ -221,7 +220,7 @@ fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), li...@@ -221,7 +220,7 @@ fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), li
221 .value = Value{ .sequence = n.sequence },220 .value = Value{ .sequence = n.sequence },
222 },221 },
223 });222 });
224 return 0+2-1;223 return 0 + 2 - 1;
225 }224 }
226 if (n == .mapping) {225 if (n == .mapping) {
227 try to.append(Item{226 try to.append(Item{
...@@ -230,7 +229,7 @@ fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), li...@@ -230,7 +229,7 @@ fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), li
230 .value = Value{ .mapping = n.mapping },229 .value = Value{ .mapping = n.mapping },
231 },230 },
232 });231 });
233 return 0+2-1;232 return 0 + 2 - 1;
234 }233 }
235 return null;234 return null;
236}235}
...@@ -241,7 +240,7 @@ fn condense_event_list_mapping(from: []Item, at: usize, to: *std.ArrayList(Item)...@@ -241,7 +240,7 @@ fn condense_event_list_mapping(from: []Item, at: usize, to: *std.ArrayList(Item)
241 }240 }
242 var i: usize = 1;241 var i: usize = 1;
243 while (true) : (i += 1) {242 while (true) : (i += 1) {
244 const ele = from[at+i];243 const ele = from[at + i];
245 if (ele == .event and @enumToInt(ele.event.type) == c.YAML_MAPPING_END_EVENT) {244 if (ele == .event and @enumToInt(ele.event.type) == c.YAML_MAPPING_END_EVENT) {
246 break;245 break;
247 }246 }
...@@ -251,7 +250,7 @@ fn condense_event_list_mapping(from: []Item, at: usize, to: *std.ArrayList(Item)...@@ -251,7 +250,7 @@ fn condense_event_list_mapping(from: []Item, at: usize, to: *std.ArrayList(Item)
251 }250 }
252251
253 const keys = &std.ArrayList(Key).init(to.allocator);252 const keys = &std.ArrayList(Key).init(to.allocator);
254 for (from[at+1..at+i]) |item| {253 for (from[at + 1 .. at + i]) |item| {
255 switch (item) {254 switch (item) {
256 .kv => {255 .kv => {
257 try keys.append(item.kv);256 try keys.append(item.kv);
...@@ -263,7 +262,7 @@ fn condense_event_list_mapping(from: []Item, at: usize, to: *std.ArrayList(Item)...@@ -263,7 +262,7 @@ fn condense_event_list_mapping(from: []Item, at: usize, to: *std.ArrayList(Item)
263 try to.append(Item{262 try to.append(Item{
264 .mapping = Mapping{ .items = keys.items },263 .mapping = Mapping{ .items = keys.items },
265 });264 });
266 return 0+i;265 return 0 + i;
267}266}
268267
269fn condense_event_list_sequence(from: []Item, at: usize, to: *std.ArrayList(Item), lines: Array) !?usize {268fn condense_event_list_sequence(from: []Item, at: usize, to: *std.ArrayList(Item), lines: Array) !?usize {
...@@ -272,7 +271,7 @@ fn condense_event_list_sequence(from: []Item, at: usize, to: *std.ArrayList(Item...@@ -272,7 +271,7 @@ fn condense_event_list_sequence(from: []Item, at: usize, to: *std.ArrayList(Item
272 }271 }
273 var i: usize = 1;272 var i: usize = 1;
274 while (true) : (i += 1) {273 while (true) : (i += 1) {
275 const ele = from[at+i];274 const ele = from[at + i];
276 if (ele == .event) {275 if (ele == .event) {
277 if (@enumToInt(ele.event.type) == c.YAML_SEQUENCE_END_EVENT) {276 if (@enumToInt(ele.event.type) == c.YAML_SEQUENCE_END_EVENT) {
278 break;277 break;
...@@ -285,7 +284,7 @@ fn condense_event_list_sequence(from: []Item, at: usize, to: *std.ArrayList(Item...@@ -285,7 +284,7 @@ fn condense_event_list_sequence(from: []Item, at: usize, to: *std.ArrayList(Item
285 }284 }
286285
287 const result = &std.ArrayList(Item).init(to.allocator);286 const result = &std.ArrayList(Item).init(to.allocator);
288 for (from[at+1..at+i]) |item| {287 for (from[at + 1 .. at + i]) |item| {
289 try result.append(switch (item) {288 try result.append(switch (item) {
290 .mapping => item,289 .mapping => item,
291 .event => Item{ .string = get_event_string(item.event, lines) },290 .event => Item{ .string = get_event_string(item.event, lines) },
...@@ -295,32 +294,32 @@ fn condense_event_list_sequence(from: []Item, at: usize, to: *std.ArrayList(Item...@@ -295,32 +294,32 @@ fn condense_event_list_sequence(from: []Item, at: usize, to: *std.ArrayList(Item
295 try to.append(Item{294 try to.append(Item{
296 .sequence = result.items,295 .sequence = result.items,
297 });296 });
298 return 0+i;297 return 0 + i;
299}298}
300299
301fn condense_event_list_document(from: []Item, at: usize, to: *std.ArrayList(Item), lines: Array) !?usize {300fn condense_event_list_document(from: []Item, at: usize, to: *std.ArrayList(Item), lines: Array) !?usize {
302 if (from.len < at+4) {301 if (from.len < at + 4) {
303 return null;302 return null;
304 }303 }
305 if (!(from[at] == .event and @enumToInt(from[at].event.type) == c.YAML_STREAM_START_EVENT)) {304 if (!(from[at] == .event and @enumToInt(from[at].event.type) == c.YAML_STREAM_START_EVENT)) {
306 return null;305 return null;
307 }306 }
308 if (!(from[at+1] == .event and @enumToInt(from[at+1].event.type) == c.YAML_DOCUMENT_START_EVENT)) {307 if (!(from[at + 1] == .event and @enumToInt(from[at + 1].event.type) == c.YAML_DOCUMENT_START_EVENT)) {
309 return null;308 return null;
310 }309 }
311 if (!(from[at+2] == .mapping)) {310 if (!(from[at + 2] == .mapping)) {
312 return null;311 return null;
313 }312 }
314 if (!(from[at+3] == .event and @enumToInt(from[at+3].event.type) == c.YAML_DOCUMENT_END_EVENT)) {313 if (!(from[at + 3] == .event and @enumToInt(from[at + 3].event.type) == c.YAML_DOCUMENT_END_EVENT)) {
315 return null;314 return null;
316 }315 }
317 if (!(from[at+4] == .event and @enumToInt(from[at+4].event.type) == c.YAML_STREAM_END_EVENT)) {316 if (!(from[at + 4] == .event and @enumToInt(from[at + 4].event.type) == c.YAML_STREAM_END_EVENT)) {
318 return null;317 return null;
319 }318 }
320 try to.append(Item{319 try to.append(Item{
321 .document = Document{320 .document = Document{
322 .mapping = from[at+2].mapping,321 .mapping = from[at + 2].mapping,
323 },322 },
324 });323 });
325 return 0+5-1;324 return 0 + 5 - 1;
326}325}