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 {
1010 const mode = b.standardReleaseOptions();
1111
1212 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) });
1414 const exe_name = b.fmt("{s}{s}", .{ "zigmod", if (use_full_name) with_arch_os else "" });
1515
1616 const exe = b.addExecutable(exe_name, "src/main.zig");
......@@ -42,8 +42,7 @@ pub fn build(b: *Builder) void {
4242
4343 exe.addPackagePath("zigmod", "./src/lib.zig");
4444 exe.addPackagePath("ansi", "./libs/zig-ansi/src/lib.zig");
45 }
46 else {
45 } else {
4746 deps.addAllTo(exe);
4847 }
4948
src/cmd/fetch.zig+10-12
......@@ -11,7 +11,7 @@ const common = @import("./../common.zig");
1111
1212pub fn execute(args: [][]u8) !void {
1313 //
14 const dir = try fs.path.join(gpa, &.{".zigmod", "deps"});
14 const dir = try fs.path.join(gpa, &.{ ".zigmod", "deps" });
1515
1616 const top_module = try common.collect_deps_deep(dir, "zig.mod", .{
1717 .log = true,
......@@ -127,7 +127,7 @@ fn print_paths(w: fs.File.Writer, list: []u.Module) !void {
127127 try w.print(" \"\",\n", .{});
128128 } else {
129129 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) });
131131 }
132132 }
133133}
......@@ -149,13 +149,12 @@ fn print_deps(w: fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32, array:
149149 continue;
150150 }
151151 if (!array) {
152 try w.print(" pub const {s} = packages[{}];\n", .{std.mem.replaceOwned(u8, gpa, d.name, "-", "_"), i});
153 }
154 else {
152 try w.print(" pub const {s} = packages[{}];\n", .{ std.mem.replaceOwned(u8, gpa, d.name, "-", "_"), i });
153 } else {
155154 try w.print(" package_data._{s},\n", .{d.id});
156155 }
157156 }
158 try w.print("{s}", .{try u.concat(&.{r,"}"})});
157 try w.print("{s}", .{try u.concat(&.{ r, "}" })});
159158}
160159
161160fn 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 {
165164 }
166165 for (mod.c_include_dirs) |it| {
167166 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) });
169168 } else {
170169 try w.print(" \"{}\",\n", .{std.zig.fmtEscapes(it)});
171170 }
......@@ -180,9 +179,9 @@ fn print_csrc_dirs_to(w: fs.File.Writer, list: []u.Module) !void {
180179 }
181180 for (mod.c_source_files) |it| {
182181 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, "}" });
184183 } 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, "}" });
186185 }
187186 }
188187 }
......@@ -196,12 +195,11 @@ fn print_csrc_flags_to(w: fs.File.Writer, list: []u.Module) !void {
196195 if (mod.c_source_flags.len == 0 and mod.c_source_files.len == 0) {
197196 continue;
198197 }
199 try w.print(" pub const @\"{s}\" = {s}", .{mod.id, "&.{"});
198 try w.print(" pub const @\"{s}\" = {s}", .{ mod.id, "&.{" });
200199 for (mod.c_source_flags) |it| {
201200 try w.print("\"{}\",", .{std.zig.fmtEscapes(it)});
202201 }
203202 try w.print("{s};\n", .{"}"});
204
205203 }
206204}
207205
......@@ -219,7 +217,7 @@ fn print_pkg_data_to(w: fs.File.Writer, list: *std.ArrayList(u.Module), list2: *
219217 while (i < list.items.len) : (i += 1) {
220218 const mod = list.items[i];
221219 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 });
223221 for (mod.deps) |d| {
224222 if (d.main.len > 0) {
225223 try w.print(" _{s},", .{d.id});
src/cmd/init.zig+4-4
......@@ -19,7 +19,7 @@ pub fn execute(args: [][]u8) !void {
1919 try fwriter.print("main: {s}\n", .{mainf});
2020 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 });
2323}
2424
2525fn detect_pkgname(def: []const u8) ![]const u8 {
......@@ -28,7 +28,7 @@ fn detect_pkgname(def: []const u8) ![]const u8 {
2828 }
2929 const dpath = try std.fs.cwd().realpathAlloc(gpa, "build.zig");
3030 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];
3232 name = u.trim_prefix(name, "zig-");
3333 u.assert(name.len > 0, "package name must not be an empty string", .{});
3434 return name;
......@@ -42,10 +42,10 @@ fn detct_mainfile(def: []const u8) ![]const u8 {
4242 }
4343 }
4444 }
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" }))) {
4646 return "src/lib.zig";
4747 }
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" }))) {
4949 return "src/main.zig";
5050 }
5151 u.assert(false, "unable to detect package entry point", .{});
src/cmd/license.zig+1-1
......@@ -18,7 +18,7 @@ const Map = std.StringArrayHashMap(*List);
1818
1919pub fn execute(args: [][]u8) !void {
2020 //
21 const dir = try std.fs.path.join(gpa, &.{".zigmod", "deps"});
21 const dir = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });
2222
2323 const top_module = try common.collect_deps_deep(dir, "zig.mod", .{
2424 .log = false,
src/cmd/sum.zig+8-4
......@@ -10,7 +10,7 @@ const common = @import("./../common.zig");
1010
1111pub fn execute(args: [][]u8) !void {
1212 //
13 const dir = try std.fs.path.join(gpa, &.{".zigmod", "deps"});
13 const dir = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });
1414
1515 const top_module = try common.collect_deps_deep(dir, "zig.mod", .{
1616 .log = false,
......@@ -27,9 +27,13 @@ pub fn execute(args: [][]u8) !void {
2727 try common.collect_pkgs(top_module, module_list);
2828
2929 for (module_list.items) |m| {
30 if (m.clean_path.len == 0) { continue; }
31 if (std.mem.eql(u8, m.clean_path, "../..")) { continue; }
30 if (m.clean_path.len == 0) {
31 continue;
32 }
33 if (std.mem.eql(u8, m.clean_path, "../..")) {
34 continue;
35 }
3236 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 });
3438 }
3539}
src/cmd/zpm_add.zig+5-5
......@@ -36,7 +36,7 @@ pub fn execute(args: [][]u8) !void {
3636
3737 const w = client.writer();
3838 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.? });
4040 try w.writeAll("Accept: application/json; charset=UTF-8\r\n");
4141 try w.writeAll("Connection: close\r\n");
4242 try w.writeAll("\r\n");
......@@ -56,7 +56,7 @@ pub fn execute(args: [][]u8) !void {
5656 const html_contents = data.items[index..];
5757
5858 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
6161 const found = blk: {
6262 for (res) |pkg| {
......@@ -77,14 +77,14 @@ pub fn execute(args: [][]u8) !void {
7777 }
7878 }
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 });
8181 try file.seekTo(try file.getEndPos());
82
82
8383 const file_w = file.writer();
8484 try file_w.print("\n", .{});
8585 try file_w.print(" - src: git {s}\n", .{found.git});
8686 try file_w.print(" name: {s}\n", .{found.name});
8787 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 });
9090}
src/common.zig+23-17
......@@ -68,10 +68,12 @@ pub fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void
6868}
6969
7070fn 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()});
72 const pv = try fs.path.join(gpa, &.{basedir, try d.clean_path_v()});
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}); }
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() });
73 const tempdir = try fs.path.join(gpa, &.{ basedir, "temp" });
74 if (options.log) {
75 u.print("fetch: {s}: {s}: {s}", .{ parent_name, @tagName(d.type), d.path });
76 }
7577 switch (d.type) {
7678 .system_lib => {
7779 // no op
......@@ -89,13 +91,15 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime o
8991 };
9092 if (try u.does_folder_exist(pv)) {
9193 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 }
9397 }
9498 return pv;
9599 }
96100 try d.type.pull(d.path, tempdir);
97 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});
101 if ((try u.run_cmd(tempdir, &.{ "git", "checkout", vers.string })) > 0) {
102 u.assert(false, "fetch: git: {s}: {s} {s} does not exist", .{ d.path, @tagName(vers.id), vers.string });
99103 }
100104 const td_fd = try fs.cwd().openDir(basedir, .{});
101105 try u.mkdir_all(pv);
......@@ -108,18 +112,20 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime o
108112 }
109113 if (!try u.does_folder_exist(p)) {
110114 try d.type.pull(d.path, p);
111 }
112 else {
113 if (options.update) { try d.type.update(p, d.path); }
115 } else {
116 if (options.update) {
117 try d.type.update(p, d.path);
118 }
114119 }
115120 return p;
116121 },
117122 .hg => {
118123 if (!try u.does_folder_exist(p)) {
119124 try d.type.pull(d.path, p);
120 }
121 else {
122 if (options.update) { try d.type.update(p, d.path); }
125 } else {
126 if (options.update) {
127 try d.type.update(p, d.path);
128 }
123129 }
124130 return p;
125131 },
......@@ -132,20 +138,20 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime o
132138 if (try u.does_folder_exist(pv)) {
133139 return pv;
134140 }
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 });
136142 try d.type.pull(d.path, pv);
137143 if (try u.validate_hash(d.version, file_path)) {
138144 try std.fs.cwd().deleteFile(file_path);
139145 return pv;
140146 }
141147 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 });
143149 return p;
144150 }
145151 if (try u.does_folder_exist(p)) {
146152 try u.rm_recv(p);
147153 }
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 });
149155 try d.type.pull(d.path, p);
150156 try std.fs.deleteFileAbsolute(file_path);
151157 return p;
......@@ -173,7 +179,7 @@ fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8
173179 });
174180 },
175181 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) {
177183 error.FileNotFound => {
178184 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) {
179185 var mod_from = try u.Module.from(d);
src/main.zig+2-3
......@@ -10,7 +10,6 @@ pub const common = @import("./common.zig");
1010//
1111
1212pub fn main() !void {
13
1413 const gpa = std.heap.c_allocator;
1514
1615 const proc_args = try std.process.argsAlloc(gpa);
......@@ -21,7 +20,7 @@ pub fn main() !void {
2120 @import("build_options").version,
2221 @tagName(builtin.os.tag),
2322 @tagName(builtin.arch),
24 @tagName(builtin.abi)
23 @tagName(builtin.abi),
2524 });
2625 return;
2726 }
......@@ -41,7 +40,7 @@ pub fn main() !void {
4140 for (args[1..]) |item| {
4241 try sub_cmd_args.append(item);
4342 }
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) {
4544 else => return e,
4645 error.FileNotFound => {
4746 u.assert(false, "unknown command \"{s}\" for \"zigmod\"", .{args[0]});
src/util/dep.zig+3-3
......@@ -31,15 +31,15 @@ pub const Dep = struct {
3131 p = u.trim_prefix(p, "https://");
3232 p = u.trim_prefix(p, "git://");
3333 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 });
3535 return p;
3636 }
3737
3838 pub fn clean_path_v(self: Dep) ![]const u8 {
3939 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] });
4141 }
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 });
4343 }
4444
4545 pub fn is_for_this(self: Dep) bool {
src/util/dep_type.zig+11-15
......@@ -6,6 +6,7 @@ const u = @import("./index.zig");
66//
77//
88
9// zig fmt: off
910pub const DepType = enum {
1011 system_lib, // std.build.LibExeObjStep.linkSystemLibrary
1112 git, // https://git-scm.com/
......@@ -33,25 +34,20 @@ pub const DepType = enum {
3334 switch (self) {
3435 .system_lib => {},
3536 .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 });
3738 },
3839 .hg => {
39 _ = try u.run_cmd(null, &.{"hg", "clone", rpath, dpath});
40 _ = try u.run_cmd(null, &.{ "hg", "clone", rpath, dpath });
4041 },
4142 .http => {
4243 try u.mkdir_all(dpath);
43 _ = try u.run_cmd(dpath, &.{"wget", rpath});
44 const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").?+1..];
44 _ = try u.run_cmd(dpath, &.{ "wget", rpath });
45 const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").? + 1 ..];
4546 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", "." });
4748 }
48 if (
49 std.mem.endsWith(u8, f, ".tar")
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", "."});
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")) {
50 _ = try u.run_cmd(dpath, &.{ "tar", "-xf", f, "-C", "." });
5551 }
5652 },
5753 }
......@@ -61,11 +57,11 @@ pub const DepType = enum {
6157 switch (self) {
6258 .system_lib => {},
6359 .git => {
64 _ = try u.run_cmd(dpath, &.{"git", "fetch"});
65 _ = try u.run_cmd(dpath, &.{"git", "pull"});
60 _ = try u.run_cmd(dpath, &.{ "git", "fetch" });
61 _ = try u.run_cmd(dpath, &.{ "git", "pull" });
6662 },
6763 .hg => {
68 _ = try u.run_cmd(dpath, &.{"hg", "pull"});
64 _ = try u.run_cmd(dpath, &.{ "hg", "pull" });
6965 },
7066 .http => {
7167 //
src/util/funcs.zig+16-16
......@@ -13,7 +13,7 @@ pub const mb = kb * 1024;
1313pub const gb = mb * 1024;
1414
1515pub fn print(comptime fmt: []const u8, args: anytype) void {
16 std.debug.print(fmt++"\n", args);
16 std.debug.print(fmt ++ "\n", args);
1717}
1818
1919pub fn assert(ok: bool, comptime fmt: []const u8, args: anytype) void {
......@@ -72,16 +72,16 @@ pub fn does_folder_exist(fpath: []const u8) !bool {
7272
7373pub fn _join(comptime delim: []const u8, comptime xs: [][]const u8) []const u8 {
7474 var buf: []const u8 = "";
75 for (xs) |x,i| {
75 for (xs) |x, i| {
7676 buf = buf ++ x;
77 if (i < xs.len-1) buf = buf ++ delim;
77 if (i < xs.len - 1) buf = buf ++ delim;
7878 }
7979 return buf;
8080}
8181
8282pub fn trim_suffix(comptime T: type, in: []const T, suffix: []const T) []const T {
8383 if (std.mem.endsWith(T, in, suffix)) {
84 return in[0..in.len-suffix.len];
84 return in[0 .. in.len - suffix.len];
8585 }
8686 return in;
8787}
......@@ -98,7 +98,7 @@ pub fn repeat(s: []const u8, times: i32) ![]const u8 {
9898pub fn join(xs: [][]const u8, delim: []const u8) ![]const u8 {
9999 var res: []const u8 = "";
100100 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 "" });
102102 }
103103 return res;
104104}
......@@ -106,7 +106,7 @@ pub fn join(xs: [][]const u8, delim: []const u8) ![]const u8 {
106106pub fn concat(items: [][]const u8) ![]const u8 {
107107 var buf: []const u8 = "";
108108 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 });
110110 }
111111 return buf;
112112}
......@@ -150,15 +150,14 @@ pub fn file_list(dpath: []const u8, list: *std.ArrayList([]const u8)) !void {
150150 continue;
151151 }
152152 try list.append(try gpa.dupe(u8, entry.path));
153 }
154 else {
153 } else {
155154 break;
156155 }
157156 }
158157}
159158
160159pub 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) {
162161 error.FileNotFound => {
163162 u.assert(false, "\"{s}\" command not found", .{args[0]});
164163 unreachable;
......@@ -191,7 +190,7 @@ pub fn mkdir_all(dpath: []const u8) anyerror!void {
191190 if (dpath.len == 0) {
192191 return;
193192 }
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;
195194 const ps = std.fs.path.sep_str;
196195 if (std.mem.lastIndexOf(u8, d, ps)) |index| {
197196 try mkdir_all(d[0..index]);
......@@ -210,14 +209,15 @@ pub fn rm_recv(path: []const u8) anyerror!void {
210209 defer file.close();
211210 const s = try file.stat();
212211 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;
214215 var iter = dir.iterate();
215216 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 }));
217218 }
218219 try std.fs.deleteDirAbsolute(abs_path);
219 }
220 else {
220 } else {
221221 try std.fs.deleteFileAbsolute(abs_path);
222222 }
223223}
......@@ -231,7 +231,7 @@ pub fn random_string(len: usize) ![]const u8 {
231231 var buf = try gpa.alloc(u8, len);
232232 var i: usize = 0;
233233 while (i < len) : (i += 1) {
234 buf[i] = alphabet[r.int(usize)%alphabet.len];
234 buf[i] = alphabet[r.int(usize) % alphabet.len];
235235 }
236236 return buf;
237237}
......@@ -272,7 +272,7 @@ pub fn validate_hash(input: []const u8, file_path: []const u8) !bool {
272272 };
273273 const result = std.mem.eql(u8, expected, actual);
274274 if (!result) {
275 std.log.info("expected: {s}, actual: {s}", .{expected, actual});
275 std.log.info("expected: {s}, actual: {s}", .{ expected, actual });
276276 }
277277 return result;
278278}
src/util/module.zig+3-3
......@@ -46,7 +46,7 @@ pub const Module = struct {
4646
4747 pub fn get_hash(self: Module, cdpath: []const u8) ![]const u8 {
4848 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
5151 const file_list_2 = &std.ArrayList([]const u8).init(gpa);
5252 for (file_list_1.items) |item| {
......@@ -64,10 +64,10 @@ pub const Module = struct {
6464
6565 const h = &std.crypto.hash.Blake3.init(.{});
6666 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 });
6868 const file = try std.fs.cwd().openFile(abs_path, .{});
6969 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);
7171 h.update(input);
7272 }
7373 var out: [32]u8 = undefined;
src/util/yaml.zig+19-20
......@@ -122,7 +122,6 @@ pub const Mapping = struct {
122122//
123123
124124pub fn parse(alloc: *std.mem.Allocator, input: []const u8) !Document {
125
126125 var parser: c.yaml_parser_t = undefined;
127126 _ = c.yaml_parser_initialize(&parser);
128127
......@@ -139,7 +138,7 @@ pub fn parse(alloc: *std.mem.Allocator, input: []const u8) !Document {
139138 }
140139
141140 const et = @enumToInt(event.type);
142 try all_events.append(.{.event = event});
141 try all_events.append(.{ .event = event });
143142 c.yaml_event_delete(&event);
144143
145144 if (et == c.YAML_STREAM_END_EVENT) {
......@@ -196,11 +195,11 @@ fn condense_event_list(list: *std.ArrayList(Item), lines: Array) !void {
196195}
197196
198197fn 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) {
200199 return null;
201200 }
202201 const t = from[at];
203 const n = from[at+1];
202 const n = from[at + 1];
204203
205204 if (!(t == .event and @enumToInt(t.event.type) == c.YAML_SCALAR_EVENT)) {
206205 return null;
......@@ -212,7 +211,7 @@ fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), li
212211 .value = Value{ .string = get_event_string(n.event, lines) },
213212 },
214213 });
215 return 0+2-1;
214 return 0 + 2 - 1;
216215 }
217216 if (n == .sequence) {
218217 try to.append(Item{
......@@ -221,7 +220,7 @@ fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), li
221220 .value = Value{ .sequence = n.sequence },
222221 },
223222 });
224 return 0+2-1;
223 return 0 + 2 - 1;
225224 }
226225 if (n == .mapping) {
227226 try to.append(Item{
......@@ -230,7 +229,7 @@ fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), li
230229 .value = Value{ .mapping = n.mapping },
231230 },
232231 });
233 return 0+2-1;
232 return 0 + 2 - 1;
234233 }
235234 return null;
236235}
......@@ -241,7 +240,7 @@ fn condense_event_list_mapping(from: []Item, at: usize, to: *std.ArrayList(Item)
241240 }
242241 var i: usize = 1;
243242 while (true) : (i += 1) {
244 const ele = from[at+i];
243 const ele = from[at + i];
245244 if (ele == .event and @enumToInt(ele.event.type) == c.YAML_MAPPING_END_EVENT) {
246245 break;
247246 }
......@@ -251,7 +250,7 @@ fn condense_event_list_mapping(from: []Item, at: usize, to: *std.ArrayList(Item)
251250 }
252251
253252 const keys = &std.ArrayList(Key).init(to.allocator);
254 for (from[at+1..at+i]) |item| {
253 for (from[at + 1 .. at + i]) |item| {
255254 switch (item) {
256255 .kv => {
257256 try keys.append(item.kv);
......@@ -263,7 +262,7 @@ fn condense_event_list_mapping(from: []Item, at: usize, to: *std.ArrayList(Item)
263262 try to.append(Item{
264263 .mapping = Mapping{ .items = keys.items },
265264 });
266 return 0+i;
265 return 0 + i;
267266}
268267
269268fn 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
272271 }
273272 var i: usize = 1;
274273 while (true) : (i += 1) {
275 const ele = from[at+i];
274 const ele = from[at + i];
276275 if (ele == .event) {
277276 if (@enumToInt(ele.event.type) == c.YAML_SEQUENCE_END_EVENT) {
278277 break;
......@@ -285,7 +284,7 @@ fn condense_event_list_sequence(from: []Item, at: usize, to: *std.ArrayList(Item
285284 }
286285
287286 const result = &std.ArrayList(Item).init(to.allocator);
288 for (from[at+1..at+i]) |item| {
287 for (from[at + 1 .. at + i]) |item| {
289288 try result.append(switch (item) {
290289 .mapping => item,
291290 .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
295294 try to.append(Item{
296295 .sequence = result.items,
297296 });
298 return 0+i;
297 return 0 + i;
299298}
300299
301300fn 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) {
303302 return null;
304303 }
305304 if (!(from[at] == .event and @enumToInt(from[at].event.type) == c.YAML_STREAM_START_EVENT)) {
306305 return null;
307306 }
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)) {
309308 return null;
310309 }
311 if (!(from[at+2] == .mapping)) {
310 if (!(from[at + 2] == .mapping)) {
312311 return null;
313312 }
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)) {
315314 return null;
316315 }
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)) {
318317 return null;
319318 }
320319 try to.append(Item{
321320 .document = Document{
322 .mapping = from[at+2].mapping,
321 .mapping = from[at + 2].mapping,
323322 },
324323 });
325 return 0+5-1;
324 return 0 + 5 - 1;
326325}