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");
22const string = []const u8;
33
44const zigmod = @import("../lib.zig");
5const u = @import("./../util/index.zig");
56const common = @import("./../common.zig");
67
78// Inspired by:
......@@ -12,7 +13,7 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {
1213 _ = args;
1314
1415 const gpa = std.heap.c_allocator;
15 const cachepath = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });
16 const cachepath = try u.find_cachepath();
1617 const dir = std.fs.cwd();
1718 try do(gpa, cachepath, dir);
1819}
src/cmd/fetch.zig+1-2
......@@ -13,9 +13,8 @@ const license = @import("./license.zig");
1313pub fn execute(self_name: []const u8, args: [][]u8) !void {
1414 _ = self_name;
1515
16 //
1716 const gpa = std.heap.c_allocator;
18 const cachepath = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });
17 const cachepath = try u.find_cachepath();
1918 const dir = std.fs.cwd();
2019 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 {
1414
1515 //
1616 const gpa = std.heap.c_allocator;
17 const cachepath = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });
17 const cachepath = try u.find_cachepath();
1818 const dir = std.fs.cwd();
1919
2020 var options = common.CollectOptions{
src/cmd/license.zig+2-1
......@@ -6,6 +6,7 @@ const licenses = @import("licenses");
66const extras = @import("extras");
77
88const zigmod = @import("../lib.zig");
9const u = @import("./../util/index.zig");
910const common = @import("./../common.zig");
1011
1112const List = std.ArrayList(zigmod.Module);
......@@ -18,7 +19,7 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {
1819 _ = self_name;
1920 _ = args;
2021
21 const cachepath = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });
22 const cachepath = try u.find_cachepath();
2223 const dir = std.fs.cwd();
2324
2425 var options = common.CollectOptions{
src/cmd/sum.zig+2-1
......@@ -2,6 +2,7 @@ const std = @import("std");
22const gpa = std.heap.c_allocator;
33
44const zigmod = @import("../lib.zig");
5const u = @import("./../util/index.zig");
56const common = @import("./../common.zig");
67
78//
......@@ -11,7 +12,7 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void {
1112 _ = self_name;
1213 _ = args;
1314
14 const cachepath = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });
15 const cachepath = try u.find_cachepath();
1516 const dir = std.fs.cwd();
1617
1718 var options = common.CollectOptions{
src/util/funcs.zig+11
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const string = []const u8;
3const gpa = std.heap.c_allocator;
34const extras = @import("extras");
45
56const u = @import("index.zig");
......@@ -250,3 +251,13 @@ pub fn indexOfAfter(haystack: string, needle: u8, after: usize) ?usize {
250251 }
251252 return null;
252253}
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}