authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 03:48:10 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 03:48:10 -07:00
logde9de0a7679d6e71e938f2807b7a792e302ef550
treeba3b67864fd0c8812cfcec529a092e937b1ab169
parentf9ed63ba65289f3e0ef5b0d8609d09996780c767

remove global allocator from u.run_cmd


4 files changed, 26 insertions(+), 26 deletions(-)

src/cmd/fetch.zig+1-1
......@@ -144,7 +144,7 @@ fn diff_lockfile() !void {
144144 const max = std.math.maxInt(usize);
145145
146146 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" });
148148 const r = std.io.fixedBufferStream(result.stdout).reader();
149149 while (try r.readUntilDelimiterOrEofAlloc(gpa, '\n', max)) |line| {
150150 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) !
136136 if (try u.does_folder_exist(pv)) {
137137 if (vers.id == .branch) {
138138 if (options.update) {
139 try d.type.update(pv, d.path);
139 try d.type.update(gpa, pv, d.path);
140140 }
141141 }
142142 return pv;
143143 }
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) {
146146 u.fail("fetch: git: {s}: {s} {s} does not exist", .{ d.path, @tagName(vers.id), vers.string });
147147 }
148148 if (builtin.os.tag != .windows and vers.id != .branch) {
......@@ -152,20 +152,20 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
152152 return pv;
153153 }
154154 if (!try u.does_folder_exist(p)) {
155 try d.type.pull(d.path, p);
155 try d.type.pull(gpa, d.path, p);
156156 } else {
157157 if (options.update) {
158 try d.type.update(p, d.path);
158 try d.type.update(gpa, p, d.path);
159159 }
160160 }
161161 return p;
162162 },
163163 .hg => {
164164 if (!try u.does_folder_exist(p)) {
165 try d.type.pull(d.path, p);
165 try d.type.pull(gpa, d.path, p);
166166 } else {
167167 if (options.update) {
168 try d.type.update(p, d.path);
168 try d.type.update(gpa, p, d.path);
169169 }
170170 }
171171 return p;
......@@ -180,7 +180,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
180180 return pv;
181181 }
182182 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);
184184 if (try u.validate_hash(d.version, file_path)) {
185185 try std.fs.cwd().deleteFile(file_path);
186186 return pv;
......@@ -193,7 +193,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
193193 try std.fs.cwd().deleteTree(p);
194194 }
195195 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);
197197 try std.fs.deleteFileAbsolute(file_path);
198198 return p;
199199 },
src/util/dep_type.zig+10-10
......@@ -32,43 +32,43 @@ pub const DepType = enum {
3232 // hypercore, // https://hypercore-protocol.org/
3333
3434 // 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 {
3636 switch (self) {
3737 .local => {},
3838 .system_lib => {},
3939 .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});
4141 },
4242 .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});
4444 },
4545 .http => {
4646 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});
4848 const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").? + 1 ..];
4949 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});
5151 }
5252 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});
5454 }
5555 },
5656 }
5757 }
5858
5959 // 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 {
6161 _ = rpath;
6262
6363 switch (self) {
6464 .local => {},
6565 .system_lib => {},
6666 .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", .{});
6969 },
7070 .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", .{});
7272 },
7373 .http => {
7474 //
src/util/funcs.zig+6-6
......@@ -134,8 +134,8 @@ pub fn file_list(alloc: *std.mem.Allocator, dpath: string) ![]const string {
134134 return list.toOwnedSlice();
135135}
136136
137pub 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) {
137pub 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) {
139139 error.FileNotFound => {
140140 u.fail("\"{s}\" command not found", .{args[0]});
141141 },
......@@ -143,10 +143,10 @@ pub fn run_cmd_raw(dir: ?string, args: []const string) !std.ChildProcess.ExecRes
143143 };
144144}
145145
146pub 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);
146pub 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);
150150 return result.term.Exited;
151151}
152152