authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-11-24 00:17:14 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-11-24 00:17:14 -08:00
log09d633b1405c5cbd4e02f4c86cb34f0368bf321f
treea34fe5cbe0608b20ef5509bbd6258ecad9ac1042
parent65666d00836654f33ac4405acc12ccf50f93a071

cmd: when running zigmod inside deps folder, use parent deps folder as cachepath


6 files changed, 19 insertions(+), 6 deletions(-)

src/cmd/ci.zig+2-1
...@@ -2,6 +2,7 @@ const std = @import("std");...@@ -2,6 +2,7 @@ const std = @import("std");
2const string = []const u8;2const string = []const u8;
33
4const zigmod = @import("../lib.zig");4const zigmod = @import("../lib.zig");
5const u = @import("./../util/index.zig");
5const common = @import("./../common.zig");6const common = @import("./../common.zig");
67
7// Inspired by:8// Inspired by:
...@@ -12,7 +13,7 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {...@@ -12,7 +13,7 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {
12 _ = args;13 _ = args;
1314
14 const gpa = std.heap.c_allocator;15 const gpa = std.heap.c_allocator;
15 const cachepath = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });16 const cachepath = try u.find_cachepath();
16 const dir = std.fs.cwd();17 const dir = std.fs.cwd();
17 try do(gpa, cachepath, dir);18 try do(gpa, cachepath, dir);
18}19}
src/cmd/fetch.zig+1-2
...@@ -13,9 +13,8 @@ const license = @import("./license.zig");...@@ -13,9 +13,8 @@ const license = @import("./license.zig");
13pub fn execute(self_name: []const u8, args: [][]u8) !void {13pub fn execute(self_name: []const u8, args: [][]u8) !void {
14 _ = self_name;14 _ = self_name;
1515
16 //
17 const gpa = std.heap.c_allocator;16 const gpa = std.heap.c_allocator;
18 const cachepath = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });17 const cachepath = try u.find_cachepath();
19 const dir = std.fs.cwd();18 const dir = std.fs.cwd();
20 const should_update = !(args.len >= 1 and std.mem.eql(u8, args[0], "--no-update"));19 const should_update = !(args.len >= 1 and std.mem.eql(u8, args[0], "--no-update"));
2120
src/cmd/generate.zig+1-1
...@@ -14,7 +14,7 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {...@@ -14,7 +14,7 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {
1414
15 //15 //
16 const gpa = std.heap.c_allocator;16 const gpa = std.heap.c_allocator;
17 const cachepath = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });17 const cachepath = try u.find_cachepath();
18 const dir = std.fs.cwd();18 const dir = std.fs.cwd();
1919
20 var options = common.CollectOptions{20 var options = common.CollectOptions{
src/cmd/license.zig+2-1
...@@ -6,6 +6,7 @@ const licenses = @import("licenses");...@@ -6,6 +6,7 @@ const licenses = @import("licenses");
6const extras = @import("extras");6const extras = @import("extras");
77
8const zigmod = @import("../lib.zig");8const zigmod = @import("../lib.zig");
9const u = @import("./../util/index.zig");
9const common = @import("./../common.zig");10const common = @import("./../common.zig");
1011
11const List = std.ArrayList(zigmod.Module);12const List = std.ArrayList(zigmod.Module);
...@@ -18,7 +19,7 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {...@@ -18,7 +19,7 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {
18 _ = self_name;19 _ = self_name;
19 _ = args;20 _ = args;
2021
21 const cachepath = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });22 const cachepath = try u.find_cachepath();
22 const dir = std.fs.cwd();23 const dir = std.fs.cwd();
2324
24 var options = common.CollectOptions{25 var options = common.CollectOptions{
src/cmd/sum.zig+2-1
...@@ -2,6 +2,7 @@ const std = @import("std");...@@ -2,6 +2,7 @@ const std = @import("std");
2const gpa = std.heap.c_allocator;2const gpa = std.heap.c_allocator;
33
4const zigmod = @import("../lib.zig");4const zigmod = @import("../lib.zig");
5const u = @import("./../util/index.zig");
5const common = @import("./../common.zig");6const common = @import("./../common.zig");
67
7//8//
...@@ -11,7 +12,7 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {...@@ -11,7 +12,7 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {
11 _ = self_name;12 _ = self_name;
12 _ = args;13 _ = args;
1314
14 const cachepath = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });15 const cachepath = try u.find_cachepath();
15 const dir = std.fs.cwd();16 const dir = std.fs.cwd();
1617
17 var options = common.CollectOptions{18 var options = common.CollectOptions{
src/util/funcs.zig+11
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const gpa = std.heap.c_allocator;
3const extras = @import("extras");4const extras = @import("extras");
45
5const u = @import("index.zig");6const u = @import("index.zig");
...@@ -250,3 +251,13 @@ pub fn indexOfAfter(haystack: string, needle: u8, after: usize) ?usize {...@@ -250,3 +251,13 @@ pub fn indexOfAfter(haystack: string, needle: u8, after: usize) ?usize {
250 }251 }
251 return null;252 return null;
252}253}
254
255pub fn find_cachepath() !string {
256 const haystack = try std.fs.cwd().realpathAlloc(gpa, ".");
257 const needle = "/.zigmod/deps";
258
259 if (std.mem.indexOf(u8, haystack, needle)) |index| {
260 return haystack[0 .. index + needle.len];
261 }
262 return try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });
263}