authoravatarMeghan Denny<hello@nektro.net>2026-10-25 03:59:50-07:00
committeravatarMeghan Denny<hello@nektro.net>2026-10-25 04:11:33-07:00
logd0471726b19a8f24d74d58481cd071f788a46097
tree913f7a8bb6a3e9bfc331c239fe19cb16542b95c9
parent373a525dc24ba7fe53338316d61a606657fac1a5
signature Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

cmd/fetch: refinement around how local dependencies are handled

- src: local name path would work as intended when the dep was in the root but when a local dep had a local dep of its own 'path' was still relative to the root instead of the module dir

5 files changed, 18 insertions(+), 12 deletions(-)

docs/zig.mod.md+1-1
......@@ -88,7 +88,7 @@ The available `type`s are:
8888
8989For the full details on `Dep` types, you can check out the source where the enum is defined: https://github.com/nektro/zigmod/blob/master/src/util/dep_type.zig.
9090
91> Note: the `local` type modifies the input behavior to be shorthand for `<name> <main>` rather than `path version` since the latter fields don't make sense for local files.
91> Note: the `local` type modifies the input behavior to be shorthand for `name path` rather than `path ?version` since the latter fields don't make sense for local files.
9292
9393#### Dep `version`
9494- Type: `string-string`
src/cmd/fetch.zig+4
......@@ -325,6 +325,10 @@ fn print_dirs(w: nfs.File, list: []const zigmod.Module, alloc: std.mem.Allocator
325325 try w.print(" pub const _{s} = \"{}\";\n", .{ mod.short_id(), u.altStringEscape(cwd_realpath) });
326326 continue;
327327 }
328 if (mod.type == .local) {
329 try w.print(" pub const _{s} = \"{}\";\n", .{ mod.short_id(), u.altStringEscape(mod.clean_path) });
330 continue;
331 }
328332 try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.short_id(), u.altStringEscape(mod.clean_path) });
329333 }
330334}
src/common.zig+8-10
......@@ -39,12 +39,12 @@ pub fn collect_deps_deep(cachepath: [:0]const u8, mdir: nfs.Dir, options: *Colle
3939 }
4040 try moduledeps.append(try collect_deps(cachepath, mdir, ".", .local, options));
4141 for (m.rootdeps) |*d| {
42 if (try get_module_from_dep(d, cachepath, options)) |founddep| {
42 if (try get_module_from_dep(d, mdir, cachepath, options)) |founddep| {
4343 try moduledeps.append(founddep);
4444 }
4545 }
4646 for (m.builddeps) |*d| {
47 if (try get_module_from_dep(d, cachepath, options)) |founddep| {
47 if (try get_module_from_dep(d, mdir, cachepath, options)) |founddep| {
4848 try moduledeps.append(founddep);
4949 }
5050 }
......@@ -72,7 +72,7 @@ pub fn collect_deps(cachepath: [:0]const u8, mdir: nfs.Dir, mdir_path: string, d
7272 try gen_files_package(options.alloc, cachepath, mdir, m.files);
7373 }
7474 for (m.deps) |*d| {
75 if (try get_module_from_dep(d, cachepath, options)) |founddep| {
75 if (try get_module_from_dep(d, if (dtype == .local) mdir else nfs.cwd(), cachepath, options)) |founddep| {
7676 try moduledeps.append(founddep);
7777 }
7878 }
......@@ -122,9 +122,6 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
122122 }
123123 switch (d.type) {
124124 .local => {
125 if (!std.mem.endsWith(u8, d.main, ".zig")) {
126 return gpa.dupeSentinel(u8, d.main, 0);
127 }
128125 return d.path;
129126 },
130127 .system_lib, .framework => {
......@@ -216,7 +213,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
216213 }
217214}
218215
219pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: [:0]const u8, options: *CollectOptions) anyerror!?zigmod.Module {
216pub fn get_module_from_dep(d: *zigmod.Dep, localdir: nfs.Dir, cachepath: [:0]const u8, options: *CollectOptions) anyerror!?zigmod.Module {
220217 if (options.lock) |lock| {
221218 for (lock) |item| {
222219 if (std.mem.eql(u8, item[0], try d.clean_path(options.alloc))) {
......@@ -229,7 +226,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: [:0]const u8, options: *Co
229226 }
230227 if (!d.is_for_this()) return null;
231228 const modpath = try get_modpath(cachepath, d.*, options);
232 const moddir = if (modpath.len == 0) try nfs.cwd().openDir(cachepath, .{}) else try nfs.cwd().openDir(modpath, .{});
229 const moddir = if (modpath.len == 0) try nfs.cwd().openDir(cachepath, .{}) else try localdir.openDir(modpath, .{});
233230
234231 const nocache = d.type.isLocal();
235232 if (!nocache) try options.already_fetched.append(modpath);
......@@ -287,10 +284,12 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: [:0]const u8, options: *Co
287284 };
288285 dd.dep = d.*;
289286 dd.for_build = d.for_build;
290 const save = dd;
291287 if (d.type != .local) {
292288 const new_clean_path = extras.trimPrefix(modpath, cachepath)[1..];
293289 dd.clean_path = new_clean_path.ptr[0..new_clean_path.len :0];
290 } else {
291 dd.clean_path = try moddir.realpathAlloc(gpa, ".");
292 dd.clean_path = dd.clean_path[std.fs.path.dirname(std.fs.path.dirname(cachepath).?).?.len + 1 ..];
294293 }
295294 if (std.mem.eql(u8, &dd.id, &zigmod.Dep.EMPTY)) dd.id = u.random_string(48);
296295 if (d.name.len > 0) dd.name = d.name;
......@@ -300,7 +299,6 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: [:0]const u8, options: *Co
300299 if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files;
301300 if (d.only_os.len > 0) dd.only_os = d.only_os;
302301 if (d.except_os.len > 0) dd.except_os = d.except_os;
303 if (d.type == .local) dd.main = try std.fs.path.join(options.alloc, &.{ d.main, save.main });
304302 if (dd.is_for_this()) return dd;
305303 return null;
306304 },
src/util/modfile.zig+4
......@@ -132,6 +132,10 @@ pub const ModFile = struct {
132132 main = version.?;
133133 version = "";
134134 }
135 if (!std.mem.endsWith(u8, main, ".zig")) {
136 path = main;
137 main = "";
138 }
135139 }
136140
137141 var id = zigmod.Dep.EMPTY;
src/util/module.zig+1-1
......@@ -38,7 +38,7 @@ pub const Module = struct {
3838 errdefer moddeps.deinit();
3939
4040 for (dep.deps) |*d| {
41 if (try common.get_module_from_dep(d, cachepath, options)) |founddep| {
41 if (try common.get_module_from_dep(d, nfs.cwd(), cachepath, options)) |founddep| {
4242 try moddeps.append(founddep);
4343 }
4444 }