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 {...@@ -144,7 +144,7 @@ fn diff_lockfile() !void {
144 const max = std.math.maxInt(usize);144 const max = std.math.maxInt(usize);
145145
146 if (try u.does_folder_exist(".git")) {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 const r = std.io.fixedBufferStream(result.stdout).reader();148 const r = std.io.fixedBufferStream(result.stdout).reader();
149 while (try r.readUntilDelimiterOrEofAlloc(gpa, '\n', max)) |line| {149 while (try r.readUntilDelimiterOrEofAlloc(gpa, '\n', max)) |line| {
150 if (std.mem.startsWith(u8, line, "@@")) break;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,13 +136,13 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
136 if (try u.does_folder_exist(pv)) {136 if (try u.does_folder_exist(pv)) {
137 if (vers.id == .branch) {137 if (vers.id == .branch) {
138 if (options.update) {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 return pv;142 return pv;
143 }143 }
144 try d.type.pull(d.path, pv);144 try d.type.pull(gpa, d.path, pv);
145 if ((try u.run_cmd(pv, &.{ "git", "checkout", vers.string })) > 0) {145 if ((try u.run_cmd(gpa, pv, &.{ "git", "checkout", vers.string })) > 0) {
146 u.fail("fetch: git: {s}: {s} {s} does not exist", .{ d.path, @tagName(vers.id), vers.string });146 u.fail("fetch: git: {s}: {s} {s} does not exist", .{ d.path, @tagName(vers.id), vers.string });
147 }147 }
148 if (builtin.os.tag != .windows and vers.id != .branch) {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,20 +152,20 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
152 return pv;152 return pv;
153 }153 }
154 if (!try u.does_folder_exist(p)) {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 } else {156 } else {
157 if (options.update) {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 return p;161 return p;
162 },162 },
163 .hg => {163 .hg => {
164 if (!try u.does_folder_exist(p)) {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 } else {166 } else {
167 if (options.update) {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 return p;171 return p;
...@@ -180,7 +180,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !...@@ -180,7 +180,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
180 return pv;180 return pv;
181 }181 }
182 const file_path = try std.fs.path.join(gpa, &.{ pv, file_name });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 if (try u.validate_hash(d.version, file_path)) {184 if (try u.validate_hash(d.version, file_path)) {
185 try std.fs.cwd().deleteFile(file_path);185 try std.fs.cwd().deleteFile(file_path);
186 return pv;186 return pv;
...@@ -193,7 +193,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !...@@ -193,7 +193,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
193 try std.fs.cwd().deleteTree(p);193 try std.fs.cwd().deleteTree(p);
194 }194 }
195 const file_path = try std.fs.path.join(gpa, &.{ p, file_name });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 try std.fs.deleteFileAbsolute(file_path);197 try std.fs.deleteFileAbsolute(file_path);
198 return p;198 return p;
199 },199 },
src/util/dep_type.zig+10-10
...@@ -32,43 +32,43 @@ pub const DepType = enum {...@@ -32,43 +32,43 @@ pub const DepType = enum {
32 // hypercore, // https://hypercore-protocol.org/32 // hypercore, // https://hypercore-protocol.org/
3333
34 // zig fmt: on34 // 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 switch (self) {36 switch (self) {
37 .local => {},37 .local => {},
38 .system_lib => {},38 .system_lib => {},
39 .git => {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 .hg => {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 .http => {45 .http => {
46 try std.fs.cwd().makePath(dpath);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 const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").? + 1 ..];48 const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").? + 1 ..];
49 if (std.mem.endsWith(u8, f, ".zip")) {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 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")) {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 }
5858
59 // zig fmt: on59 // 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 _ = rpath;61 _ = rpath;
6262
63 switch (self) {63 switch (self) {
64 .local => {},64 .local => {},
65 .system_lib => {},65 .system_lib => {},
66 .git => {66 .git => {
67 u.assert((try u.run_cmd(dpath, &.{ "git", "fetch" })) == 0, "git fetch failed", .{});67 u.assert((try u.run_cmd(alloc, dpath, &.{ "git", "fetch" })) == 0, "git fetch failed", .{});
68 u.assert((try u.run_cmd(dpath, &.{ "git", "pull" })) == 0, "git pull failed", .{});68 u.assert((try u.run_cmd(alloc, dpath, &.{ "git", "pull" })) == 0, "git pull failed", .{});
69 },69 },
70 .hg => {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 .http => {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,8 +134,8 @@ pub fn file_list(alloc: *std.mem.Allocator, dpath: string) ![]const string {
134 return list.toOwnedSlice();134 return list.toOwnedSlice();
135}135}
136136
137pub fn run_cmd_raw(dir: ?string, args: []const string) !std.ChildProcess.ExecResult {137pub fn run_cmd_raw(alloc: *std.mem.Allocator, 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) {138 return std.ChildProcess.exec(.{ .allocator = alloc, .cwd = dir, .argv = args, .max_output_bytes = std.math.maxInt(usize) }) catch |e| switch (e) {
139 error.FileNotFound => {139 error.FileNotFound => {
140 u.fail("\"{s}\" command not found", .{args[0]});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,10 +143,10 @@ pub fn run_cmd_raw(dir: ?string, args: []const string) !std.ChildProcess.ExecRes
143 };143 };
144}144}
145145
146pub fn run_cmd(dir: ?string, args: []const string) !u32 {146pub fn run_cmd(alloc: *std.mem.Allocator, dir: ?string, args: []const string) !u32 {
147 const result = try run_cmd_raw(dir, args);147 const result = try run_cmd_raw(alloc, dir, args);
148 gpa.free(result.stdout);148 alloc.free(result.stdout);
149 gpa.free(result.stderr);149 alloc.free(result.stderr);
150 return result.term.Exited;150 return result.term.Exited;
151}151}
152152