| author | |
| committer | |
| log | de9de0a7679d6e71e938f2807b7a792e302ef550 |
| tree | ba3b67864fd0c8812cfcec529a092e937b1ab169 |
| parent | f9ed63ba65289f3e0ef5b0d8609d09996780c767 |
4 files changed, 26 insertions(+), 26 deletions(-)
src/cmd/fetch.zig+1-1| ... | ... | @@ -144,7 +144,7 @@ fn diff_lockfile() !void { |
| 144 | 144 | const max = std.math.maxInt(usize); |
| 145 | 145 | |
| 146 | 146 | if (try u.does_folder_exist(".git")) { |
| 147 | const result = try u.run_cmd_raw(null, &.{ "git", "diff", "zigmod.lock" }); | |
| 147 | const result = try u.run_cmd_raw(gpa, null, &.{ "git", "diff", "zigmod.lock" }); | |
| 148 | 148 | const r = std.io.fixedBufferStream(result.stdout).reader(); |
| 149 | 149 | while (try r.readUntilDelimiterOrEofAlloc(gpa, '\n', max)) |line| { |
| 150 | 150 | if (std.mem.startsWith(u8, line, "@@")) break; |
src/common.zig+9-9| ... | ... | @@ -136,13 +136,13 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! |
| 136 | 136 | if (try u.does_folder_exist(pv)) { |
| 137 | 137 | if (vers.id == .branch) { |
| 138 | 138 | if (options.update) { |
| 139 | try d.type.update(pv, d.path); | |
| 139 | try d.type.update(gpa, pv, d.path); | |
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | return pv; |
| 143 | 143 | } |
| 144 | try d.type.pull(d.path, pv); | |
| 145 | if ((try u.run_cmd(pv, &.{ "git", "checkout", vers.string })) > 0) { | |
| 144 | try d.type.pull(gpa, d.path, pv); | |
| 145 | if ((try u.run_cmd(gpa, pv, &.{ "git", "checkout", vers.string })) > 0) { | |
| 146 | 146 | u.fail("fetch: git: {s}: {s} {s} does not exist", .{ d.path, @tagName(vers.id), vers.string }); |
| 147 | 147 | } |
| 148 | 148 | if (builtin.os.tag != .windows and vers.id != .branch) { |
| ... | ... | @@ -152,20 +152,20 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! |
| 152 | 152 | return pv; |
| 153 | 153 | } |
| 154 | 154 | if (!try u.does_folder_exist(p)) { |
| 155 | try d.type.pull(d.path, p); | |
| 155 | try d.type.pull(gpa, d.path, p); | |
| 156 | 156 | } else { |
| 157 | 157 | if (options.update) { |
| 158 | try d.type.update(p, d.path); | |
| 158 | try d.type.update(gpa, p, d.path); | |
| 159 | 159 | } |
| 160 | 160 | } |
| 161 | 161 | return p; |
| 162 | 162 | }, |
| 163 | 163 | .hg => { |
| 164 | 164 | if (!try u.does_folder_exist(p)) { |
| 165 | try d.type.pull(d.path, p); | |
| 165 | try d.type.pull(gpa, d.path, p); | |
| 166 | 166 | } else { |
| 167 | 167 | if (options.update) { |
| 168 | try d.type.update(p, d.path); | |
| 168 | try d.type.update(gpa, p, d.path); | |
| 169 | 169 | } |
| 170 | 170 | } |
| 171 | 171 | return p; |
| ... | ... | @@ -180,7 +180,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! |
| 180 | 180 | return pv; |
| 181 | 181 | } |
| 182 | 182 | const file_path = try std.fs.path.join(gpa, &.{ pv, file_name }); |
| 183 | try d.type.pull(d.path, pv); | |
| 183 | try d.type.pull(gpa, d.path, pv); | |
| 184 | 184 | if (try u.validate_hash(d.version, file_path)) { |
| 185 | 185 | try std.fs.cwd().deleteFile(file_path); |
| 186 | 186 | return pv; |
| ... | ... | @@ -193,7 +193,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! |
| 193 | 193 | try std.fs.cwd().deleteTree(p); |
| 194 | 194 | } |
| 195 | 195 | const file_path = try std.fs.path.join(gpa, &.{ p, file_name }); |
| 196 | try d.type.pull(d.path, p); | |
| 196 | try d.type.pull(gpa, d.path, p); | |
| 197 | 197 | try std.fs.deleteFileAbsolute(file_path); |
| 198 | 198 | return p; |
| 199 | 199 | }, |
src/util/dep_type.zig+10-10| ... | ... | @@ -32,43 +32,43 @@ pub const DepType = enum { |
| 32 | 32 | // hypercore, // https://hypercore-protocol.org/ |
| 33 | 33 | |
| 34 | 34 | // zig fmt: on |
| 35 | pub fn pull(self: DepType, rpath: string, dpath: string) !void { | |
| 35 | pub fn pull(self: DepType, alloc: *std.mem.Allocator, rpath: string, dpath: string) !void { | |
| 36 | 36 | switch (self) { |
| 37 | 37 | .local => {}, |
| 38 | 38 | .system_lib => {}, |
| 39 | 39 | .git => { |
| 40 | u.assert((try u.run_cmd(null, &.{ "git", "clone", "--recurse-submodules", rpath, dpath })) == 0, "git clone {s} failed", .{rpath}); | |
| 40 | u.assert((try u.run_cmd(alloc, null, &.{ "git", "clone", "--recurse-submodules", rpath, dpath })) == 0, "git clone {s} failed", .{rpath}); | |
| 41 | 41 | }, |
| 42 | 42 | .hg => { |
| 43 | u.assert((try u.run_cmd(null, &.{ "hg", "clone", rpath, dpath })) == 0, "hg clone {s} failed", .{rpath}); | |
| 43 | u.assert((try u.run_cmd(alloc, null, &.{ "hg", "clone", rpath, dpath })) == 0, "hg clone {s} failed", .{rpath}); | |
| 44 | 44 | }, |
| 45 | 45 | .http => { |
| 46 | 46 | try std.fs.cwd().makePath(dpath); |
| 47 | u.assert((try u.run_cmd(dpath, &.{ "wget", rpath })) == 0, "wget {s} failed", .{rpath}); | |
| 47 | u.assert((try u.run_cmd(alloc, dpath, &.{ "wget", rpath })) == 0, "wget {s} failed", .{rpath}); | |
| 48 | 48 | const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").? + 1 ..]; |
| 49 | 49 | if (std.mem.endsWith(u8, f, ".zip")) { |
| 50 | u.assert((try u.run_cmd(dpath, &.{ "unzip", f, "-d", "." })) == 0, "unzip {s} failed", .{f}); | |
| 50 | u.assert((try u.run_cmd(alloc, dpath, &.{ "unzip", f, "-d", "." })) == 0, "unzip {s} failed", .{f}); | |
| 51 | 51 | } |
| 52 | 52 | 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")) { |
| 53 | u.assert((try u.run_cmd(dpath, &.{ "tar", "-xf", f, "-C", "." })) == 0, "un-tar {s} failed", .{f}); | |
| 53 | u.assert((try u.run_cmd(alloc, dpath, &.{ "tar", "-xf", f, "-C", "." })) == 0, "un-tar {s} failed", .{f}); | |
| 54 | 54 | } |
| 55 | 55 | }, |
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | // zig fmt: on |
| 60 | pub fn update(self: DepType, dpath: string, rpath: string) !void { | |
| 60 | pub fn update(self: DepType, alloc: *std.mem.Allocator, dpath: string, rpath: string) !void { | |
| 61 | 61 | _ = rpath; |
| 62 | 62 | |
| 63 | 63 | switch (self) { |
| 64 | 64 | .local => {}, |
| 65 | 65 | .system_lib => {}, |
| 66 | 66 | .git => { |
| 67 | u.assert((try u.run_cmd(dpath, &.{ "git", "fetch" })) == 0, "git fetch failed", .{}); | |
| 68 | u.assert((try u.run_cmd(dpath, &.{ "git", "pull" })) == 0, "git pull failed", .{}); | |
| 67 | u.assert((try u.run_cmd(alloc, dpath, &.{ "git", "fetch" })) == 0, "git fetch failed", .{}); | |
| 68 | u.assert((try u.run_cmd(alloc, dpath, &.{ "git", "pull" })) == 0, "git pull failed", .{}); | |
| 69 | 69 | }, |
| 70 | 70 | .hg => { |
| 71 | u.assert((try u.run_cmd(dpath, &.{ "hg", "pull" })) == 0, "hg pull failed", .{}); | |
| 71 | u.assert((try u.run_cmd(alloc, dpath, &.{ "hg", "pull" })) == 0, "hg pull failed", .{}); | |
| 72 | 72 | }, |
| 73 | 73 | .http => { |
| 74 | 74 | // |
src/util/funcs.zig+6-6| ... | ... | @@ -134,8 +134,8 @@ pub fn file_list(alloc: *std.mem.Allocator, dpath: string) ![]const string { |
| 134 | 134 | return list.toOwnedSlice(); |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | pub fn run_cmd_raw(dir: ?string, args: []const string) !std.ChildProcess.ExecResult { | |
| 138 | return std.ChildProcess.exec(.{ .allocator = gpa, .cwd = dir, .argv = args, .max_output_bytes = std.math.maxInt(usize) }) catch |e| switch (e) { | |
| 137 | pub fn run_cmd_raw(alloc: *std.mem.Allocator, dir: ?string, args: []const string) !std.ChildProcess.ExecResult { | |
| 138 | return std.ChildProcess.exec(.{ .allocator = alloc, .cwd = dir, .argv = args, .max_output_bytes = std.math.maxInt(usize) }) catch |e| switch (e) { | |
| 139 | 139 | error.FileNotFound => { |
| 140 | 140 | u.fail("\"{s}\" command not found", .{args[0]}); |
| 141 | 141 | }, |
| ... | ... | @@ -143,10 +143,10 @@ pub fn run_cmd_raw(dir: ?string, args: []const string) !std.ChildProcess.ExecRes |
| 143 | 143 | }; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | pub fn run_cmd(dir: ?string, args: []const string) !u32 { | |
| 147 | const result = try run_cmd_raw(dir, args); | |
| 148 | gpa.free(result.stdout); | |
| 149 | gpa.free(result.stderr); | |
| 146 | pub fn run_cmd(alloc: *std.mem.Allocator, dir: ?string, args: []const string) !u32 { | |
| 147 | const result = try run_cmd_raw(alloc, dir, args); | |
| 148 | alloc.free(result.stdout); | |
| 149 | alloc.free(result.stderr); | |
| 150 | 150 | return result.term.Exited; |
| 151 | 151 | } |
| 152 | 152 |