From abbca727c328121a78971940e79df3e3afc56cf9 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 2 May 2021 01:57:04 -0700 Subject: [PATCH] finally run `zig fmt`, close #8 --- build.zig | 5 ++--- src/cmd/fetch.zig | 22 ++++++++++------------ src/cmd/init.zig | 8 ++++---- src/cmd/license.zig | 2 +- src/cmd/sum.zig | 12 ++++++++---- src/cmd/zpm_add.zig | 10 +++++----- src/common.zig | 40 +++++++++++++++++++++++----------------- src/main.zig | 5 ++--- src/util/dep.zig | 6 +++--- src/util/dep_type.zig | 26 +++++++++++--------------- src/util/funcs.zig | 32 ++++++++++++++++---------------- src/util/module.zig | 6 +++--- src/util/yaml.zig | 39 +++++++++++++++++++-------------------- 13 files changed, 107 insertions(+), 106 deletions(-) diff --git a/build.zig b/build.zig index 7d00b984edbd8cbf340b0d3b59665d5347206802..9018740c929f45be04092e865847cba7098b6d6d 100644 --- a/build.zig +++ b/build.zig @@ -10,7 +10,7 @@ pub fn build(b: *Builder) void { const mode = b.standardReleaseOptions(); const use_full_name = b.option(bool, "use-full-name", "") orelse false; - const with_arch_os = b.fmt("-{s}-{s}", .{@tagName(target.cpu_arch orelse builtin.arch), @tagName(target.os_tag orelse builtin.os.tag)}); + const with_arch_os = b.fmt("-{s}-{s}", .{ @tagName(target.cpu_arch orelse builtin.arch), @tagName(target.os_tag orelse builtin.os.tag) }); const exe_name = b.fmt("{s}{s}", .{ "zigmod", if (use_full_name) with_arch_os else "" }); const exe = b.addExecutable(exe_name, "src/main.zig"); @@ -42,8 +42,7 @@ pub fn build(b: *Builder) void { exe.addPackagePath("zigmod", "./src/lib.zig"); exe.addPackagePath("ansi", "./libs/zig-ansi/src/lib.zig"); - } - else { + } else { deps.addAllTo(exe); } diff --git a/src/cmd/fetch.zig b/src/cmd/fetch.zig index d88a4d9f8d957741475c2b531b8f3c6af7cc7722..fe0a6f868276c6ce080c0ad6be365ad0ff2429d3 100644 --- a/src/cmd/fetch.zig +++ b/src/cmd/fetch.zig @@ -11,7 +11,7 @@ const common = @import("./../common.zig"); pub fn execute(args: [][]u8) !void { // - const dir = try fs.path.join(gpa, &.{".zigmod", "deps"}); + const dir = try fs.path.join(gpa, &.{ ".zigmod", "deps" }); const top_module = try common.collect_deps_deep(dir, "zig.mod", .{ .log = true, @@ -127,7 +127,7 @@ fn print_paths(w: fs.File.Writer, list: []u.Module) !void { try w.print(" \"\",\n", .{}); } else { const s = std.fs.path.sep_str; - try w.print(" \"{}{}{}\",\n", .{std.zig.fmtEscapes(s), std.zig.fmtEscapes(mod.clean_path), std.zig.fmtEscapes(s)}); + try w.print(" \"{}{}{}\",\n", .{ std.zig.fmtEscapes(s), std.zig.fmtEscapes(mod.clean_path), std.zig.fmtEscapes(s) }); } } } @@ -149,13 +149,12 @@ fn print_deps(w: fs.File.Writer, dir: []const u8, m: u.Module, tabs: i32, array: continue; } if (!array) { - try w.print(" pub const {s} = packages[{}];\n", .{std.mem.replaceOwned(u8, gpa, d.name, "-", "_"), i}); - } - else { + try w.print(" pub const {s} = packages[{}];\n", .{ std.mem.replaceOwned(u8, gpa, d.name, "-", "_"), i }); + } else { try w.print(" package_data._{s},\n", .{d.id}); } } - try w.print("{s}", .{try u.concat(&.{r,"}"})}); + try w.print("{s}", .{try u.concat(&.{ r, "}" })}); } 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 { } for (mod.c_include_dirs) |it| { if (i > 0) { - try w.print(" cache ++ _paths[{}] ++ \"{}\",\n", .{i-1, std.zig.fmtEscapes(it)}); + try w.print(" cache ++ _paths[{}] ++ \"{}\",\n", .{ i - 1, std.zig.fmtEscapes(it) }); } else { try w.print(" \"{}\",\n", .{std.zig.fmtEscapes(it)}); } @@ -180,9 +179,9 @@ fn print_csrc_dirs_to(w: fs.File.Writer, list: []u.Module) !void { } for (mod.c_source_files) |it| { if (i > 0) { - try w.print(" {s}_ids[{}], cache ++ _paths[{}] ++ \"{s}\"{s},\n", .{"[_][]const u8{", i-1, i-1, it, "}"}); + try w.print(" {s}_ids[{}], cache ++ _paths[{}] ++ \"{s}\"{s},\n", .{ "[_][]const u8{", i - 1, i - 1, it, "}" }); } else { - try w.print(" {s}_ids[{}], \".{}/{s}\"{s},\n", .{"[_][]const u8{", i-1, std.zig.fmtEscapes(mod.clean_path), it, "}"}); + try w.print(" {s}_ids[{}], \".{}/{s}\"{s},\n", .{ "[_][]const u8{", i - 1, std.zig.fmtEscapes(mod.clean_path), it, "}" }); } } } @@ -196,12 +195,11 @@ fn print_csrc_flags_to(w: fs.File.Writer, list: []u.Module) !void { if (mod.c_source_flags.len == 0 and mod.c_source_files.len == 0) { continue; } - try w.print(" pub const @\"{s}\" = {s}", .{mod.id, "&.{"}); + try w.print(" pub const @\"{s}\" = {s}", .{ mod.id, "&.{" }); for (mod.c_source_flags) |it| { try w.print("\"{}\",", .{std.zig.fmtEscapes(it)}); } try w.print("{s};\n", .{"}"}); - } } @@ -219,7 +217,7 @@ fn print_pkg_data_to(w: fs.File.Writer, list: *std.ArrayList(u.Module), list2: * while (i < list.items.len) : (i += 1) { const mod = list.items[i]; if (contains_all(mod.deps, list2)) { - 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}); + 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 }); for (mod.deps) |d| { if (d.main.len > 0) { try w.print(" _{s},", .{d.id}); diff --git a/src/cmd/init.zig b/src/cmd/init.zig index 1a7823384615f3a611001ab1d78adad9cce23561..93e2af7033e8e2d20589b5f5c614fec18b758a3d 100644 --- a/src/cmd/init.zig +++ b/src/cmd/init.zig @@ -19,7 +19,7 @@ pub fn execute(args: [][]u8) !void { try fwriter.print("main: {s}\n", .{mainf}); try fwriter.print("dependencies:\n", .{}); - u.print("Initialized a new package named {s} with entry point {s}", .{name, mainf}); + u.print("Initialized a new package named {s} with entry point {s}", .{ name, mainf }); } fn detect_pkgname(def: []const u8) ![]const u8 { @@ -28,7 +28,7 @@ fn detect_pkgname(def: []const u8) ![]const u8 { } const dpath = try std.fs.cwd().realpathAlloc(gpa, "build.zig"); const split = try u.split(dpath, std.fs.path.sep_str); - var name = split[split.len-2]; + var name = split[split.len - 2]; name = u.trim_prefix(name, "zig-"); u.assert(name.len > 0, "package name must not be an empty string", .{}); return name; @@ -42,10 +42,10 @@ fn detct_mainfile(def: []const u8) ![]const u8 { } } } - if (try u.does_file_exist(try std.fs.path.join(gpa, &.{"src", "lib.zig"}))) { + if (try u.does_file_exist(try std.fs.path.join(gpa, &.{ "src", "lib.zig" }))) { return "src/lib.zig"; } - if (try u.does_file_exist(try std.fs.path.join(gpa, &.{"src", "main.zig"}))) { + if (try u.does_file_exist(try std.fs.path.join(gpa, &.{ "src", "main.zig" }))) { return "src/main.zig"; } u.assert(false, "unable to detect package entry point", .{}); diff --git a/src/cmd/license.zig b/src/cmd/license.zig index 5d05685561787f048c86a4583303f966ca5924aa..61fd7e8c49a78e00609c528192ff9d2c95a4680a 100644 --- a/src/cmd/license.zig +++ b/src/cmd/license.zig @@ -18,7 +18,7 @@ const Map = std.StringArrayHashMap(*List); pub fn execute(args: [][]u8) !void { // - const dir = try std.fs.path.join(gpa, &.{".zigmod", "deps"}); + const dir = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" }); const top_module = try common.collect_deps_deep(dir, "zig.mod", .{ .log = false, diff --git a/src/cmd/sum.zig b/src/cmd/sum.zig index 74a6f0fd431d03d9d589c0e3a924216c7a3acd7a..e420e763b02d8e4bc9f183743e387ffd700593b8 100644 --- a/src/cmd/sum.zig +++ b/src/cmd/sum.zig @@ -10,7 +10,7 @@ const common = @import("./../common.zig"); pub fn execute(args: [][]u8) !void { // - const dir = try std.fs.path.join(gpa, &.{".zigmod", "deps"}); + const dir = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" }); const top_module = try common.collect_deps_deep(dir, "zig.mod", .{ .log = false, @@ -27,9 +27,13 @@ pub fn execute(args: [][]u8) !void { try common.collect_pkgs(top_module, module_list); for (module_list.items) |m| { - if (m.clean_path.len == 0) { continue; } - if (std.mem.eql(u8, m.clean_path, "../..")) { continue; } + if (m.clean_path.len == 0) { + continue; + } + if (std.mem.eql(u8, m.clean_path, "../..")) { + continue; + } const hash = try m.get_hash(dir); - try w.print("{s} {s}\n", .{hash, m.clean_path}); + try w.print("{s} {s}\n", .{ hash, m.clean_path }); } } diff --git a/src/cmd/zpm_add.zig b/src/cmd/zpm_add.zig index 8c5c4a241fbd4c17cac0ff394c37d453d8674a3a..413b9336da873745800dbb26ee6b3d031f7826ef 100644 --- a/src/cmd/zpm_add.zig +++ b/src/cmd/zpm_add.zig @@ -36,7 +36,7 @@ pub fn execute(args: [][]u8) !void { const w = client.writer(); try w.print("GET {s} HTTP/1.1\r\n", .{url.path}); - try w.print("Host: {s}:{}\r\n", .{url.host.name, url.port.?}); + try w.print("Host: {s}:{}\r\n", .{ url.host.name, url.port.? }); try w.writeAll("Accept: application/json; charset=UTF-8\r\n"); try w.writeAll("Connection: close\r\n"); try w.writeAll("\r\n"); @@ -56,7 +56,7 @@ pub fn execute(args: [][]u8) !void { const html_contents = data.items[index..]; var stream = std.json.TokenStream.init(html_contents[4..]); - const res = try std.json.parse([]Zpm.Package, &stream, .{ .allocator = gpa, }); + const res = try std.json.parse([]Zpm.Package, &stream, .{ .allocator = gpa }); const found = blk: { for (res) |pkg| { @@ -77,14 +77,14 @@ pub fn execute(args: [][]u8) !void { } } - const file = try std.fs.cwd().openFile("zig.mod", .{ .read=true, .write=true }); + const file = try std.fs.cwd().openFile("zig.mod", .{ .read = true, .write = true }); try file.seekTo(try file.getEndPos()); - + const file_w = file.writer(); try file_w.print("\n", .{}); try file_w.print(" - src: git {s}\n", .{found.git}); try file_w.print(" name: {s}\n", .{found.name}); try file_w.print(" main: {s}\n", .{found.root_file.?[1..]}); - std.log.info("Successfully added package {s} by {s}", .{found.name, found.author}); + std.log.info("Successfully added package {s} by {s}", .{ found.name, found.author }); } diff --git a/src/common.zig b/src/common.zig index ee99f04ed2184b23e1ff59e08db6c6f7abf74fba..9414f3a42fe7f2de9d07a6b1fa6d2e30ab8e2dad 100644 --- a/src/common.zig +++ b/src/common.zig @@ -68,10 +68,12 @@ pub fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void } fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime options: CollectOptions) ![]const u8 { - const p = try fs.path.join(gpa, &.{basedir, try d.clean_path()}); - const pv = try fs.path.join(gpa, &.{basedir, try d.clean_path_v()}); - const tempdir = try fs.path.join(gpa, &.{basedir, "temp"}); - if (options.log) { u.print("fetch: {s}: {s}: {s}", .{parent_name, @tagName(d.type), d.path}); } + const p = try fs.path.join(gpa, &.{ basedir, try d.clean_path() }); + const pv = try fs.path.join(gpa, &.{ basedir, try d.clean_path_v() }); + const tempdir = try fs.path.join(gpa, &.{ basedir, "temp" }); + if (options.log) { + u.print("fetch: {s}: {s}: {s}", .{ parent_name, @tagName(d.type), d.path }); + } switch (d.type) { .system_lib => { // no op @@ -89,13 +91,15 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime o }; if (try u.does_folder_exist(pv)) { if (vers.id == .branch) { - if (options.update) { try d.type.update(pv, d.path); } + if (options.update) { + try d.type.update(pv, d.path); + } } return pv; } try d.type.pull(d.path, tempdir); - if ((try u.run_cmd(tempdir, &.{"git", "checkout", vers.string})) > 0) { - u.assert(false, "fetch: git: {s}: {s} {s} does not exist", .{d.path, @tagName(vers.id), vers.string}); + if ((try u.run_cmd(tempdir, &.{ "git", "checkout", vers.string })) > 0) { + u.assert(false, "fetch: git: {s}: {s} {s} does not exist", .{ d.path, @tagName(vers.id), vers.string }); } const td_fd = try fs.cwd().openDir(basedir, .{}); try u.mkdir_all(pv); @@ -108,18 +112,20 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime o } if (!try u.does_folder_exist(p)) { try d.type.pull(d.path, p); - } - else { - if (options.update) { try d.type.update(p, d.path); } + } else { + if (options.update) { + try d.type.update(p, d.path); + } } return p; }, .hg => { if (!try u.does_folder_exist(p)) { try d.type.pull(d.path, p); - } - else { - if (options.update) { try d.type.update(p, d.path); } + } else { + if (options.update) { + try d.type.update(p, d.path); + } } return p; }, @@ -132,20 +138,20 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime o if (try u.does_folder_exist(pv)) { return pv; } - const file_path = try std.fs.path.join(gpa, &.{pv, file_name}); + const file_path = try std.fs.path.join(gpa, &.{ pv, file_name }); try d.type.pull(d.path, pv); if (try u.validate_hash(d.version, file_path)) { try std.fs.cwd().deleteFile(file_path); return pv; } try u.rm_recv(pv); - u.assert(false, "{s} does not match hash {s}", .{d.path, d.version}); + u.assert(false, "{s} does not match hash {s}", .{ d.path, d.version }); return p; } if (try u.does_folder_exist(p)) { try u.rm_recv(p); } - const file_path = try std.fs.path.join(gpa, &.{p, file_name}); + const file_path = try std.fs.path.join(gpa, &.{ p, file_name }); try d.type.pull(d.path, p); try std.fs.deleteFileAbsolute(file_path); return p; @@ -173,7 +179,7 @@ fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8 }); }, else => blk: { - var dd = try collect_deps(dir, try u.concat(&.{moddir, "/zig.mod"}), options) catch |e| switch (e) { + var dd = try collect_deps(dir, try u.concat(&.{ moddir, "/zig.mod" }), options) catch |e| switch (e) { error.FileNotFound => { if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { var mod_from = try u.Module.from(d); diff --git a/src/main.zig b/src/main.zig index 217ca03b72857073488dca042b6bb83ed9533a16..1d7a0c740a432d060d7477b7c289dd7f38a32f4b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -10,7 +10,6 @@ pub const common = @import("./common.zig"); // pub fn main() !void { - const gpa = std.heap.c_allocator; const proc_args = try std.process.argsAlloc(gpa); @@ -21,7 +20,7 @@ pub fn main() !void { @import("build_options").version, @tagName(builtin.os.tag), @tagName(builtin.arch), - @tagName(builtin.abi) + @tagName(builtin.abi), }); return; } @@ -41,7 +40,7 @@ pub fn main() !void { for (args[1..]) |item| { try sub_cmd_args.append(item); } - const result = std.ChildProcess.exec(.{ .allocator = gpa, .argv = sub_cmd_args.items, }) catch |e| switch(e) { + const result = std.ChildProcess.exec(.{ .allocator = gpa, .argv = sub_cmd_args.items }) catch |e| switch (e) { else => return e, error.FileNotFound => { u.assert(false, "unknown command \"{s}\" for \"zigmod\"", .{args[0]}); diff --git a/src/util/dep.zig b/src/util/dep.zig index e26ddd0ae16f36f3741949f4d7d4c5a23361b915..9de7b7a48689a8bc516563822a6196b5f51024eb 100644 --- a/src/util/dep.zig +++ b/src/util/dep.zig @@ -31,15 +31,15 @@ pub const Dep = struct { p = u.trim_prefix(p, "https://"); p = u.trim_prefix(p, "git://"); p = u.trim_suffix(u8, p, ".git"); - p = try std.mem.join(gpa, "/", &.{@tagName(self.type), p}); + p = try std.mem.join(gpa, "/", &.{ @tagName(self.type), p }); return p; } pub fn clean_path_v(self: Dep) ![]const u8 { if (self.type == .http and self.version.len > 0) { - return std.mem.join(gpa, "/", &.{"v", @tagName(self.type), self.version[0..20]}); + return std.mem.join(gpa, "/", &.{ "v", @tagName(self.type), self.version[0..20] }); } - return std.mem.join(gpa, "/", &.{"v", try self.clean_path(), self.version}); + return std.mem.join(gpa, "/", &.{ "v", try self.clean_path(), self.version }); } pub fn is_for_this(self: Dep) bool { diff --git a/src/util/dep_type.zig b/src/util/dep_type.zig index c7f52e531b6781a77231f4e99189e5c5f980b7bc..3571335f81c57651d10efe82e368943a0555478f 100644 --- a/src/util/dep_type.zig +++ b/src/util/dep_type.zig @@ -6,6 +6,7 @@ const u = @import("./index.zig"); // // +// zig fmt: off pub const DepType = enum { system_lib, // std.build.LibExeObjStep.linkSystemLibrary git, // https://git-scm.com/ @@ -33,25 +34,20 @@ pub const DepType = enum { switch (self) { .system_lib => {}, .git => { - _ = try u.run_cmd(null, &.{"git", "clone", "--recurse-submodules", rpath, dpath}); + _ = try u.run_cmd(null, &.{ "git", "clone", "--recurse-submodules", rpath, dpath }); }, .hg => { - _ = try u.run_cmd(null, &.{"hg", "clone", rpath, dpath}); + _ = try u.run_cmd(null, &.{ "hg", "clone", rpath, dpath }); }, .http => { try u.mkdir_all(dpath); - _ = try u.run_cmd(dpath, &.{"wget", rpath}); - const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").?+1..]; + _ = try u.run_cmd(dpath, &.{ "wget", rpath }); + const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").? + 1 ..]; if (std.mem.endsWith(u8, f, ".zip")) { - _ = try u.run_cmd(dpath, &.{"unzip", f, "-d", "."}); + _ = try u.run_cmd(dpath, &.{ "unzip", f, "-d", "." }); } - 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") - ) { - _ = try u.run_cmd(dpath, &.{"tar", "-xf", f, "-C", "."}); + 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")) { + _ = try u.run_cmd(dpath, &.{ "tar", "-xf", f, "-C", "." }); } }, } @@ -61,11 +57,11 @@ pub const DepType = enum { switch (self) { .system_lib => {}, .git => { - _ = try u.run_cmd(dpath, &.{"git", "fetch"}); - _ = try u.run_cmd(dpath, &.{"git", "pull"}); + _ = try u.run_cmd(dpath, &.{ "git", "fetch" }); + _ = try u.run_cmd(dpath, &.{ "git", "pull" }); }, .hg => { - _ = try u.run_cmd(dpath, &.{"hg", "pull"}); + _ = try u.run_cmd(dpath, &.{ "hg", "pull" }); }, .http => { // diff --git a/src/util/funcs.zig b/src/util/funcs.zig index 22380b8c428ebdf0d25ec139961e37220b627c7a..97c6e32dc7665b3878330811dc72c0fab4eb10f7 100644 --- a/src/util/funcs.zig +++ b/src/util/funcs.zig @@ -13,7 +13,7 @@ pub const mb = kb * 1024; pub const gb = mb * 1024; pub fn print(comptime fmt: []const u8, args: anytype) void { - std.debug.print(fmt++"\n", args); + std.debug.print(fmt ++ "\n", args); } pub fn assert(ok: bool, comptime fmt: []const u8, args: anytype) void { @@ -72,16 +72,16 @@ pub fn does_folder_exist(fpath: []const u8) !bool { pub fn _join(comptime delim: []const u8, comptime xs: [][]const u8) []const u8 { var buf: []const u8 = ""; - for (xs) |x,i| { + for (xs) |x, i| { buf = buf ++ x; - if (i < xs.len-1) buf = buf ++ delim; + if (i < xs.len - 1) buf = buf ++ delim; } return buf; } pub fn trim_suffix(comptime T: type, in: []const T, suffix: []const T) []const T { if (std.mem.endsWith(T, in, suffix)) { - return in[0..in.len-suffix.len]; + return in[0 .. in.len - suffix.len]; } return in; } @@ -98,7 +98,7 @@ pub fn repeat(s: []const u8, times: i32) ![]const u8 { pub fn join(xs: [][]const u8, delim: []const u8) ![]const u8 { var res: []const u8 = ""; for (xs) |x, i| { - res = try std.fmt.allocPrint(gpa, "{s}{s}{s}", .{res, x, if (i < xs.len-1) delim else ""}); + res = try std.fmt.allocPrint(gpa, "{s}{s}{s}", .{ res, x, if (i < xs.len - 1) delim else "" }); } return res; } @@ -106,7 +106,7 @@ pub fn join(xs: [][]const u8, delim: []const u8) ![]const u8 { pub fn concat(items: [][]const u8) ![]const u8 { var buf: []const u8 = ""; for (items) |x| { - buf = try std.fmt.allocPrint(gpa, "{s}{s}", .{buf, x}); + buf = try std.fmt.allocPrint(gpa, "{s}{s}", .{ buf, x }); } return buf; } @@ -150,15 +150,14 @@ pub fn file_list(dpath: []const u8, list: *std.ArrayList([]const u8)) !void { continue; } try list.append(try gpa.dupe(u8, entry.path)); - } - else { + } else { break; } } } pub fn run_cmd(dir: ?[]const u8, args: []const []const u8) !u32 { - const result = std.ChildProcess.exec(.{ .allocator = gpa, .cwd = dir, .argv = args, .max_output_bytes = std.math.maxInt(usize) }) catch |e| switch(e) { + const result = std.ChildProcess.exec(.{ .allocator = gpa, .cwd = dir, .argv = args, .max_output_bytes = std.math.maxInt(usize) }) catch |e| switch (e) { error.FileNotFound => { u.assert(false, "\"{s}\" command not found", .{args[0]}); unreachable; @@ -191,7 +190,7 @@ pub fn mkdir_all(dpath: []const u8) anyerror!void { if (dpath.len == 0) { return; } - const d = if (dpath[dpath.len-1] == std.fs.path.sep) dpath[0..dpath.len-1] else dpath; + const d = if (dpath[dpath.len - 1] == std.fs.path.sep) dpath[0 .. dpath.len - 1] else dpath; const ps = std.fs.path.sep_str; if (std.mem.lastIndexOf(u8, d, ps)) |index| { try mkdir_all(d[0..index]); @@ -210,14 +209,15 @@ pub fn rm_recv(path: []const u8) anyerror!void { defer file.close(); const s = try file.stat(); if (s.kind == .Directory) { - const dir = std.fs.cwd().openDir(abs_path, .{ .iterate=true, }) catch unreachable; + const dir = std.fs.cwd().openDir(abs_path, .{ + .iterate = true, + }) catch unreachable; var iter = dir.iterate(); while (try iter.next()) |item| { - try rm_recv(try std.fs.path.join(gpa, &.{abs_path, item.name})); + try rm_recv(try std.fs.path.join(gpa, &.{ abs_path, item.name })); } try std.fs.deleteDirAbsolute(abs_path); - } - else { + } else { try std.fs.deleteFileAbsolute(abs_path); } } @@ -231,7 +231,7 @@ pub fn random_string(len: usize) ![]const u8 { var buf = try gpa.alloc(u8, len); var i: usize = 0; while (i < len) : (i += 1) { - buf[i] = alphabet[r.int(usize)%alphabet.len]; + buf[i] = alphabet[r.int(usize) % alphabet.len]; } return buf; } @@ -272,7 +272,7 @@ pub fn validate_hash(input: []const u8, file_path: []const u8) !bool { }; const result = std.mem.eql(u8, expected, actual); if (!result) { - std.log.info("expected: {s}, actual: {s}", .{expected, actual}); + std.log.info("expected: {s}, actual: {s}", .{ expected, actual }); } return result; } diff --git a/src/util/module.zig b/src/util/module.zig index 2dde7b326e6b6617b047dbf13c38319997b8ee87..201fdae2642cbe8600d54e31d683a183af5e046a 100644 --- a/src/util/module.zig +++ b/src/util/module.zig @@ -46,7 +46,7 @@ pub const Module = struct { pub fn get_hash(self: Module, cdpath: []const u8) ![]const u8 { const file_list_1 = &std.ArrayList([]const u8).init(gpa); - try u.file_list(try u.concat(&.{cdpath, "/", self.clean_path}), file_list_1); + try u.file_list(try u.concat(&.{ cdpath, "/", self.clean_path }), file_list_1); const file_list_2 = &std.ArrayList([]const u8).init(gpa); for (file_list_1.items) |item| { @@ -64,10 +64,10 @@ pub const Module = struct { const h = &std.crypto.hash.Blake3.init(.{}); for (file_list_2.items) |item| { - const abs_path = try u.concat(&.{cdpath, "/", self.clean_path, "/", item}); + const abs_path = try u.concat(&.{ cdpath, "/", self.clean_path, "/", item }); const file = try std.fs.cwd().openFile(abs_path, .{}); defer file.close(); - const input = try file.reader().readAllAlloc(gpa, u.mb*100); + const input = try file.reader().readAllAlloc(gpa, u.mb * 100); h.update(input); } var out: [32]u8 = undefined; diff --git a/src/util/yaml.zig b/src/util/yaml.zig index 91a27041ba6f983c2e50dfeb193e69f8ea452e40..8b99460d1661a63c28fa7e326121b8ef68dfc430 100644 --- a/src/util/yaml.zig +++ b/src/util/yaml.zig @@ -122,7 +122,6 @@ pub const Mapping = struct { // pub fn parse(alloc: *std.mem.Allocator, input: []const u8) !Document { - var parser: c.yaml_parser_t = undefined; _ = c.yaml_parser_initialize(&parser); @@ -139,7 +138,7 @@ pub fn parse(alloc: *std.mem.Allocator, input: []const u8) !Document { } const et = @enumToInt(event.type); - try all_events.append(.{.event = event}); + try all_events.append(.{ .event = event }); c.yaml_event_delete(&event); if (et == c.YAML_STREAM_END_EVENT) { @@ -196,11 +195,11 @@ fn condense_event_list(list: *std.ArrayList(Item), lines: Array) !void { } fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), lines: Array) !?usize { - if (at >= from.len-1) { + if (at >= from.len - 1) { return null; } const t = from[at]; - const n = from[at+1]; + const n = from[at + 1]; if (!(t == .event and @enumToInt(t.event.type) == c.YAML_SCALAR_EVENT)) { return null; @@ -212,7 +211,7 @@ fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), li .value = Value{ .string = get_event_string(n.event, lines) }, }, }); - return 0+2-1; + return 0 + 2 - 1; } if (n == .sequence) { try to.append(Item{ @@ -221,7 +220,7 @@ fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), li .value = Value{ .sequence = n.sequence }, }, }); - return 0+2-1; + return 0 + 2 - 1; } if (n == .mapping) { try to.append(Item{ @@ -230,7 +229,7 @@ fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), li .value = Value{ .mapping = n.mapping }, }, }); - return 0+2-1; + return 0 + 2 - 1; } return null; } @@ -241,7 +240,7 @@ fn condense_event_list_mapping(from: []Item, at: usize, to: *std.ArrayList(Item) } var i: usize = 1; while (true) : (i += 1) { - const ele = from[at+i]; + const ele = from[at + i]; if (ele == .event and @enumToInt(ele.event.type) == c.YAML_MAPPING_END_EVENT) { break; } @@ -251,7 +250,7 @@ fn condense_event_list_mapping(from: []Item, at: usize, to: *std.ArrayList(Item) } const keys = &std.ArrayList(Key).init(to.allocator); - for (from[at+1..at+i]) |item| { + for (from[at + 1 .. at + i]) |item| { switch (item) { .kv => { try keys.append(item.kv); @@ -263,7 +262,7 @@ fn condense_event_list_mapping(from: []Item, at: usize, to: *std.ArrayList(Item) try to.append(Item{ .mapping = Mapping{ .items = keys.items }, }); - return 0+i; + return 0 + i; } fn 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 } var i: usize = 1; while (true) : (i += 1) { - const ele = from[at+i]; + const ele = from[at + i]; if (ele == .event) { if (@enumToInt(ele.event.type) == c.YAML_SEQUENCE_END_EVENT) { break; @@ -285,7 +284,7 @@ fn condense_event_list_sequence(from: []Item, at: usize, to: *std.ArrayList(Item } const result = &std.ArrayList(Item).init(to.allocator); - for (from[at+1..at+i]) |item| { + for (from[at + 1 .. at + i]) |item| { try result.append(switch (item) { .mapping => item, .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 try to.append(Item{ .sequence = result.items, }); - return 0+i; + return 0 + i; } fn condense_event_list_document(from: []Item, at: usize, to: *std.ArrayList(Item), lines: Array) !?usize { - if (from.len < at+4) { + if (from.len < at + 4) { return null; } if (!(from[at] == .event and @enumToInt(from[at].event.type) == c.YAML_STREAM_START_EVENT)) { return null; } - if (!(from[at+1] == .event and @enumToInt(from[at+1].event.type) == c.YAML_DOCUMENT_START_EVENT)) { + if (!(from[at + 1] == .event and @enumToInt(from[at + 1].event.type) == c.YAML_DOCUMENT_START_EVENT)) { return null; } - if (!(from[at+2] == .mapping)) { + if (!(from[at + 2] == .mapping)) { return null; } - if (!(from[at+3] == .event and @enumToInt(from[at+3].event.type) == c.YAML_DOCUMENT_END_EVENT)) { + if (!(from[at + 3] == .event and @enumToInt(from[at + 3].event.type) == c.YAML_DOCUMENT_END_EVENT)) { return null; } - if (!(from[at+4] == .event and @enumToInt(from[at+4].event.type) == c.YAML_STREAM_END_EVENT)) { + if (!(from[at + 4] == .event and @enumToInt(from[at + 4].event.type) == c.YAML_STREAM_END_EVENT)) { return null; } try to.append(Item{ .document = Document{ - .mapping = from[at+2].mapping, + .mapping = from[at + 2].mapping, }, }); - return 0+5-1; + return 0 + 5 - 1; } -- 2.54.0