| author | |
| committer | |
| log | abbca727c328121a78971940e79df3e3afc56cf9 |
| tree | 8d4b2f483822ce54b4e4ffabefb97b70dac475d6 |
| parent | add6a47275b251b1e435b533da57134dbc9971f8 |
13 files changed, 107 insertions(+), 106 deletions(-)
build.zig+2-3| ... | ... | @@ -10,7 +10,7 @@ pub fn build(b: *Builder) void { |
| 10 | 10 | const mode = b.standardReleaseOptions(); |
| 11 | 11 | |
| 12 | 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 | 14 | const exe_name = b.fmt("{s}{s}", .{ "zigmod", if (use_full_name) with_arch_os else "" }); |
| 15 | 15 | |
| 16 | 16 | const exe = b.addExecutable(exe_name, "src/main.zig"); |
| ... | ... | @@ -42,8 +42,7 @@ pub fn build(b: *Builder) void { |
| 42 | 42 | |
| 43 | 43 | exe.addPackagePath("zigmod", "./src/lib.zig"); |
| 44 | 44 | exe.addPackagePath("ansi", "./libs/zig-ansi/src/lib.zig"); |
| 45 | } | |
| 46 | else { | |
| 45 | } else { | |
| 47 | 46 | deps.addAllTo(exe); |
| 48 | 47 | } |
| 49 | 48 |
src/cmd/fetch.zig+10-12| ... | ... | @@ -11,7 +11,7 @@ const common = @import("./../common.zig"); |
| 11 | 11 | |
| 12 | 12 | pub 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" }); | |
| 15 | 15 | |
| 16 | 16 | const top_module = try common.collect_deps_deep(dir, "zig.mod", .{ |
| 17 | 17 | .log = true, |
| ... | ... | @@ -127,7 +127,7 @@ fn print_paths(w: fs.File.Writer, list: []u.Module) !void { |
| 127 | 127 | try w.print(" \"\",\n", .{}); |
| 128 | 128 | } else { |
| 129 | 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 | 149 | continue; |
| 150 | 150 | } |
| 151 | 151 | 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 { | |
| 155 | 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 | } |
| 160 | 159 | |
| 161 | 160 | 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 | 165 | for (mod.c_include_dirs) |it| { |
| 167 | 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 | 168 | } else { |
| 170 | 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 | 179 | } |
| 181 | 180 | for (mod.c_source_files) |it| { |
| 182 | 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 | 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 | 195 | if (mod.c_source_flags.len == 0 and mod.c_source_files.len == 0) { |
| 197 | 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 | 199 | for (mod.c_source_flags) |it| { |
| 201 | 200 | try w.print("\"{}\",", .{std.zig.fmtEscapes(it)}); |
| 202 | 201 | } |
| 203 | 202 | try w.print("{s};\n", .{"}"}); |
| 204 | ||
| 205 | 203 | } |
| 206 | 204 | } |
| 207 | 205 | |
| ... | ... | @@ -219,7 +217,7 @@ fn print_pkg_data_to(w: fs.File.Writer, list: *std.ArrayList(u.Module), list2: * |
| 219 | 217 | while (i < list.items.len) : (i += 1) { |
| 220 | 218 | const mod = list.items[i]; |
| 221 | 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 | 221 | for (mod.deps) |d| { |
| 224 | 222 | if (d.main.len > 0) { |
| 225 | 223 | try w.print(" _{s},", .{d.id}); |
src/cmd/init.zig+4-4| ... | ... | @@ -19,7 +19,7 @@ pub fn execute(args: [][]u8) !void { |
| 19 | 19 | try fwriter.print("main: {s}\n", .{mainf}); |
| 20 | 20 | try fwriter.print("dependencies:\n", .{}); |
| 21 | 21 | |
| 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 | } |
| 24 | 24 | |
| 25 | 25 | fn detect_pkgname(def: []const u8) ![]const u8 { |
| ... | ... | @@ -28,7 +28,7 @@ fn detect_pkgname(def: []const u8) ![]const u8 { |
| 28 | 28 | } |
| 29 | 29 | const dpath = try std.fs.cwd().realpathAlloc(gpa, "build.zig"); |
| 30 | 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 | 32 | name = u.trim_prefix(name, "zig-"); |
| 33 | 33 | u.assert(name.len > 0, "package name must not be an empty string", .{}); |
| 34 | 34 | return name; |
| ... | ... | @@ -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 | 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 | 49 | return "src/main.zig"; |
| 50 | 50 | } |
| 51 | 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 | 18 | |
| 19 | 19 | pub 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" }); | |
| 22 | 22 | |
| 23 | 23 | const top_module = try common.collect_deps_deep(dir, "zig.mod", .{ |
| 24 | 24 | .log = false, |
src/cmd/sum.zig+8-4| ... | ... | @@ -10,7 +10,7 @@ const common = @import("./../common.zig"); |
| 10 | 10 | |
| 11 | 11 | pub 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" }); | |
| 14 | 14 | |
| 15 | 15 | const top_module = try common.collect_deps_deep(dir, "zig.mod", .{ |
| 16 | 16 | .log = false, |
| ... | ... | @@ -27,9 +27,13 @@ pub fn execute(args: [][]u8) !void { |
| 27 | 27 | try common.collect_pkgs(top_module, module_list); |
| 28 | 28 | |
| 29 | 29 | 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 | } | |
| 32 | 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 | 36 | |
| 37 | 37 | const w = client.writer(); |
| 38 | 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 | 40 | try w.writeAll("Accept: application/json; charset=UTF-8\r\n"); |
| 41 | 41 | try w.writeAll("Connection: close\r\n"); |
| 42 | 42 | try w.writeAll("\r\n"); |
| ... | ... | @@ -56,7 +56,7 @@ pub fn execute(args: [][]u8) !void { |
| 56 | 56 | const html_contents = data.items[index..]; |
| 57 | 57 | |
| 58 | 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 }); | |
| 60 | 60 | |
| 61 | 61 | const found = blk: { |
| 62 | 62 | for (res) |pkg| { |
| ... | ... | @@ -77,14 +77,14 @@ pub fn execute(args: [][]u8) !void { |
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
| 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 | 81 | try file.seekTo(try file.getEndPos()); |
| 82 | ||
| 82 | ||
| 83 | 83 | const file_w = file.writer(); |
| 84 | 84 | try file_w.print("\n", .{}); |
| 85 | 85 | try file_w.print(" - src: git {s}\n", .{found.git}); |
| 86 | 86 | try file_w.print(" name: {s}\n", .{found.name}); |
| 87 | 87 | try file_w.print(" main: {s}\n", .{found.root_file.?[1..]}); |
| 88 | 88 | |
| 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 | 68 | } |
| 69 | 69 | |
| 70 | 70 | fn 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 | } | |
| 75 | 77 | switch (d.type) { |
| 76 | 78 | .system_lib => { |
| 77 | 79 | // no op |
| ... | ... | @@ -89,13 +91,15 @@ fn get_moddir(basedir: []const u8, d: u.Dep, parent_name: []const u8, comptime o |
| 89 | 91 | }; |
| 90 | 92 | if (try u.does_folder_exist(pv)) { |
| 91 | 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 | 98 | return pv; |
| 95 | 99 | } |
| 96 | 100 | 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 }); | |
| 99 | 103 | } |
| 100 | 104 | const td_fd = try fs.cwd().openDir(basedir, .{}); |
| 101 | 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 | 112 | } |
| 109 | 113 | if (!try u.does_folder_exist(p)) { |
| 110 | 114 | 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 | } | |
| 114 | 119 | } |
| 115 | 120 | return p; |
| 116 | 121 | }, |
| 117 | 122 | .hg => { |
| 118 | 123 | if (!try u.does_folder_exist(p)) { |
| 119 | 124 | 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 | } | |
| 123 | 129 | } |
| 124 | 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 | 138 | if (try u.does_folder_exist(pv)) { |
| 133 | 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 | 142 | try d.type.pull(d.path, pv); |
| 137 | 143 | if (try u.validate_hash(d.version, file_path)) { |
| 138 | 144 | try std.fs.cwd().deleteFile(file_path); |
| 139 | 145 | return pv; |
| 140 | 146 | } |
| 141 | 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 | 149 | return p; |
| 144 | 150 | } |
| 145 | 151 | if (try u.does_folder_exist(p)) { |
| 146 | 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 | 155 | try d.type.pull(d.path, p); |
| 150 | 156 | try std.fs.deleteFileAbsolute(file_path); |
| 151 | 157 | return p; |
| ... | ... | @@ -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 | 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 | 183 | error.FileNotFound => { |
| 178 | 184 | if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { |
| 179 | 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 | 10 | // |
| 11 | 11 | |
| 12 | 12 | pub fn main() !void { |
| 13 | ||
| 14 | 13 | const gpa = std.heap.c_allocator; |
| 15 | 14 | |
| 16 | 15 | const proc_args = try std.process.argsAlloc(gpa); |
| ... | ... | @@ -21,7 +20,7 @@ pub fn main() !void { |
| 21 | 20 | @import("build_options").version, |
| 22 | 21 | @tagName(builtin.os.tag), |
| 23 | 22 | @tagName(builtin.arch), |
| 24 | @tagName(builtin.abi) | |
| 23 | @tagName(builtin.abi), | |
| 25 | 24 | }); |
| 26 | 25 | return; |
| 27 | 26 | } |
| ... | ... | @@ -41,7 +40,7 @@ pub fn main() !void { |
| 41 | 40 | for (args[1..]) |item| { |
| 42 | 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 | 44 | else => return e, |
| 46 | 45 | error.FileNotFound => { |
| 47 | 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 | 31 | p = u.trim_prefix(p, "https://"); |
| 32 | 32 | p = u.trim_prefix(p, "git://"); |
| 33 | 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 | 35 | return p; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | pub fn clean_path_v(self: Dep) ![]const u8 { |
| 39 | 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 | } |
| 44 | 44 | |
| 45 | 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 | // |
| 7 | 7 | // |
| 8 | 8 | |
| 9 | // zig fmt: off | |
| 9 | 10 | pub const DepType = enum { |
| 10 | 11 | system_lib, // std.build.LibExeObjStep.linkSystemLibrary |
| 11 | 12 | git, // https://git-scm.com/ |
| ... | ... | @@ -33,25 +34,20 @@ pub const DepType = enum { |
| 33 | 34 | switch (self) { |
| 34 | 35 | .system_lib => {}, |
| 35 | 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 | 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 | 42 | .http => { |
| 42 | 43 | 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 ..]; | |
| 45 | 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 | 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", "." }); | |
| 55 | 51 | } |
| 56 | 52 | }, |
| 57 | 53 | } |
| ... | ... | @@ -61,11 +57,11 @@ pub const DepType = enum { |
| 61 | 57 | switch (self) { |
| 62 | 58 | .system_lib => {}, |
| 63 | 59 | .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" }); | |
| 66 | 62 | }, |
| 67 | 63 | .hg => { |
| 68 | _ = try u.run_cmd(dpath, &.{"hg", "pull"}); | |
| 64 | _ = try u.run_cmd(dpath, &.{ "hg", "pull" }); | |
| 69 | 65 | }, |
| 70 | 66 | .http => { |
| 71 | 67 | // |
src/util/funcs.zig+16-16| ... | ... | @@ -13,7 +13,7 @@ pub const mb = kb * 1024; |
| 13 | 13 | pub const gb = mb * 1024; |
| 14 | 14 | |
| 15 | 15 | pub 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 | } |
| 18 | 18 | |
| 19 | 19 | 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 { |
| 72 | 72 | |
| 73 | 73 | pub fn _join(comptime delim: []const u8, comptime xs: [][]const u8) []const u8 { |
| 74 | 74 | var buf: []const u8 = ""; |
| 75 | for (xs) |x,i| { | |
| 75 | for (xs) |x, i| { | |
| 76 | 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 | 79 | return buf; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | pub fn trim_suffix(comptime T: type, in: []const T, suffix: []const T) []const T { |
| 83 | 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 | 86 | return in; |
| 87 | 87 | } |
| ... | ... | @@ -98,7 +98,7 @@ pub fn repeat(s: []const u8, times: i32) ![]const u8 { |
| 98 | 98 | pub fn join(xs: [][]const u8, delim: []const u8) ![]const u8 { |
| 99 | 99 | var res: []const u8 = ""; |
| 100 | 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 | 103 | return res; |
| 104 | 104 | } |
| ... | ... | @@ -106,7 +106,7 @@ pub fn join(xs: [][]const u8, delim: []const u8) ![]const u8 { |
| 106 | 106 | pub fn concat(items: [][]const u8) ![]const u8 { |
| 107 | 107 | var buf: []const u8 = ""; |
| 108 | 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 | 111 | return buf; |
| 112 | 112 | } |
| ... | ... | @@ -150,15 +150,14 @@ pub fn file_list(dpath: []const u8, list: *std.ArrayList([]const u8)) !void { |
| 150 | 150 | continue; |
| 151 | 151 | } |
| 152 | 152 | try list.append(try gpa.dupe(u8, entry.path)); |
| 153 | } | |
| 154 | else { | |
| 153 | } else { | |
| 155 | 154 | break; |
| 156 | 155 | } |
| 157 | 156 | } |
| 158 | 157 | } |
| 159 | 158 | |
| 160 | 159 | pub 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 | 161 | error.FileNotFound => { |
| 163 | 162 | u.assert(false, "\"{s}\" command not found", .{args[0]}); |
| 164 | 163 | unreachable; |
| ... | ... | @@ -191,7 +190,7 @@ pub fn mkdir_all(dpath: []const u8) anyerror!void { |
| 191 | 190 | if (dpath.len == 0) { |
| 192 | 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 | 194 | const ps = std.fs.path.sep_str; |
| 196 | 195 | if (std.mem.lastIndexOf(u8, d, ps)) |index| { |
| 197 | 196 | try mkdir_all(d[0..index]); |
| ... | ... | @@ -210,14 +209,15 @@ pub fn rm_recv(path: []const u8) anyerror!void { |
| 210 | 209 | defer file.close(); |
| 211 | 210 | const s = try file.stat(); |
| 212 | 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 | 215 | var iter = dir.iterate(); |
| 215 | 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 | 219 | try std.fs.deleteDirAbsolute(abs_path); |
| 219 | } | |
| 220 | else { | |
| 220 | } else { | |
| 221 | 221 | try std.fs.deleteFileAbsolute(abs_path); |
| 222 | 222 | } |
| 223 | 223 | } |
| ... | ... | @@ -231,7 +231,7 @@ pub fn random_string(len: usize) ![]const u8 { |
| 231 | 231 | var buf = try gpa.alloc(u8, len); |
| 232 | 232 | var i: usize = 0; |
| 233 | 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 | 236 | return buf; |
| 237 | 237 | } |
| ... | ... | @@ -272,7 +272,7 @@ pub fn validate_hash(input: []const u8, file_path: []const u8) !bool { |
| 272 | 272 | }; |
| 273 | 273 | const result = std.mem.eql(u8, expected, actual); |
| 274 | 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 | 277 | return result; |
| 278 | 278 | } |
src/util/module.zig+3-3| ... | ... | @@ -46,7 +46,7 @@ pub const Module = struct { |
| 46 | 46 | |
| 47 | 47 | pub fn get_hash(self: Module, cdpath: []const u8) ![]const u8 { |
| 48 | 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); | |
| 50 | 50 | |
| 51 | 51 | const file_list_2 = &std.ArrayList([]const u8).init(gpa); |
| 52 | 52 | for (file_list_1.items) |item| { |
| ... | ... | @@ -64,10 +64,10 @@ pub const Module = struct { |
| 64 | 64 | |
| 65 | 65 | const h = &std.crypto.hash.Blake3.init(.{}); |
| 66 | 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 | 68 | const file = try std.fs.cwd().openFile(abs_path, .{}); |
| 69 | 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 | 71 | h.update(input); |
| 72 | 72 | } |
| 73 | 73 | var out: [32]u8 = undefined; |
src/util/yaml.zig+19-20| ... | ... | @@ -122,7 +122,6 @@ pub const Mapping = struct { |
| 122 | 122 | // |
| 123 | 123 | |
| 124 | 124 | pub fn parse(alloc: *std.mem.Allocator, input: []const u8) !Document { |
| 125 | ||
| 126 | 125 | var parser: c.yaml_parser_t = undefined; |
| 127 | 126 | _ = c.yaml_parser_initialize(&parser); |
| 128 | 127 | |
| ... | ... | @@ -139,7 +138,7 @@ pub fn parse(alloc: *std.mem.Allocator, input: []const u8) !Document { |
| 139 | 138 | } |
| 140 | 139 | |
| 141 | 140 | const et = @enumToInt(event.type); |
| 142 | try all_events.append(.{.event = event}); | |
| 141 | try all_events.append(.{ .event = event }); | |
| 143 | 142 | c.yaml_event_delete(&event); |
| 144 | 143 | |
| 145 | 144 | if (et == c.YAML_STREAM_END_EVENT) { |
| ... | ... | @@ -196,11 +195,11 @@ fn condense_event_list(list: *std.ArrayList(Item), lines: Array) !void { |
| 196 | 195 | } |
| 197 | 196 | |
| 198 | 197 | fn 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 | 199 | return null; |
| 201 | 200 | } |
| 202 | 201 | const t = from[at]; |
| 203 | const n = from[at+1]; | |
| 202 | const n = from[at + 1]; | |
| 204 | 203 | |
| 205 | 204 | if (!(t == .event and @enumToInt(t.event.type) == c.YAML_SCALAR_EVENT)) { |
| 206 | 205 | return null; |
| ... | ... | @@ -212,7 +211,7 @@ fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), li |
| 212 | 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 | 216 | if (n == .sequence) { |
| 218 | 217 | try to.append(Item{ |
| ... | ... | @@ -221,7 +220,7 @@ fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), li |
| 221 | 220 | .value = Value{ .sequence = n.sequence }, |
| 222 | 221 | }, |
| 223 | 222 | }); |
| 224 | return 0+2-1; | |
| 223 | return 0 + 2 - 1; | |
| 225 | 224 | } |
| 226 | 225 | if (n == .mapping) { |
| 227 | 226 | try to.append(Item{ |
| ... | ... | @@ -230,7 +229,7 @@ fn condense_event_list_key(from: []Item, at: usize, to: *std.ArrayList(Item), li |
| 230 | 229 | .value = Value{ .mapping = n.mapping }, |
| 231 | 230 | }, |
| 232 | 231 | }); |
| 233 | return 0+2-1; | |
| 232 | return 0 + 2 - 1; | |
| 234 | 233 | } |
| 235 | 234 | return null; |
| 236 | 235 | } |
| ... | ... | @@ -241,7 +240,7 @@ fn condense_event_list_mapping(from: []Item, at: usize, to: *std.ArrayList(Item) |
| 241 | 240 | } |
| 242 | 241 | var i: usize = 1; |
| 243 | 242 | while (true) : (i += 1) { |
| 244 | const ele = from[at+i]; | |
| 243 | const ele = from[at + i]; | |
| 245 | 244 | if (ele == .event and @enumToInt(ele.event.type) == c.YAML_MAPPING_END_EVENT) { |
| 246 | 245 | break; |
| 247 | 246 | } |
| ... | ... | @@ -251,7 +250,7 @@ fn condense_event_list_mapping(from: []Item, at: usize, to: *std.ArrayList(Item) |
| 251 | 250 | } |
| 252 | 251 | |
| 253 | 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 | 254 | switch (item) { |
| 256 | 255 | .kv => { |
| 257 | 256 | try keys.append(item.kv); |
| ... | ... | @@ -263,7 +262,7 @@ fn condense_event_list_mapping(from: []Item, at: usize, to: *std.ArrayList(Item) |
| 263 | 262 | try to.append(Item{ |
| 264 | 263 | .mapping = Mapping{ .items = keys.items }, |
| 265 | 264 | }); |
| 266 | return 0+i; | |
| 265 | return 0 + i; | |
| 267 | 266 | } |
| 268 | 267 | |
| 269 | 268 | 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 |
| 272 | 271 | } |
| 273 | 272 | var i: usize = 1; |
| 274 | 273 | while (true) : (i += 1) { |
| 275 | const ele = from[at+i]; | |
| 274 | const ele = from[at + i]; | |
| 276 | 275 | if (ele == .event) { |
| 277 | 276 | if (@enumToInt(ele.event.type) == c.YAML_SEQUENCE_END_EVENT) { |
| 278 | 277 | break; |
| ... | ... | @@ -285,7 +284,7 @@ fn condense_event_list_sequence(from: []Item, at: usize, to: *std.ArrayList(Item |
| 285 | 284 | } |
| 286 | 285 | |
| 287 | 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 | 288 | try result.append(switch (item) { |
| 290 | 289 | .mapping => item, |
| 291 | 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 | 294 | try to.append(Item{ |
| 296 | 295 | .sequence = result.items, |
| 297 | 296 | }); |
| 298 | return 0+i; | |
| 297 | return 0 + i; | |
| 299 | 298 | } |
| 300 | 299 | |
| 301 | 300 | fn 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 | 302 | return null; |
| 304 | 303 | } |
| 305 | 304 | if (!(from[at] == .event and @enumToInt(from[at].event.type) == c.YAML_STREAM_START_EVENT)) { |
| 306 | 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 | 308 | return null; |
| 310 | 309 | } |
| 311 | if (!(from[at+2] == .mapping)) { | |
| 310 | if (!(from[at + 2] == .mapping)) { | |
| 312 | 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 | 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 | 317 | return null; |
| 319 | 318 | } |
| 320 | 319 | try to.append(Item{ |
| 321 | 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 | } |