From 96ae02db8af8a0024a109fcf5809e335f3bd4ad7 Mon Sep 17 00:00:00 2001 From: Meghan Date: Fri, 20 Nov 2020 13:37:07 -0800 Subject: [PATCH] fetch: set module_dir to version one if its validated --- src/cmd_fetch.zig | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/cmd_fetch.zig b/src/cmd_fetch.zig index b06f4345901dcb4ee7a9a53ecd29bf1db4ef7c64..a7bb2e3b767e00ddfb27887dd8427ec2c55215d3 100644 --- a/src/cmd_fetch.zig +++ b/src/cmd_fetch.zig @@ -10,7 +10,7 @@ const u = @import("./util/index.zig"); pub fn execute(args: [][]u8) !void { // const home = try known_folders.getPath(gpa, .home); - const dir = try std.fmt.allocPrint(gpa, "{}{}", .{home, "/.cache/zigmod/deps"}); + const dir = try std.fmt.allocPrint(gpa, "{}{}", .{home, "/.cache/zigmod"}); const top_module = try fetch_deps(dir, "./zig.mod"); @@ -62,13 +62,16 @@ pub fn execute(args: [][]u8) !void { fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { const m = try u.ModFile.init(gpa, mpath); const moduledeps = &std.ArrayList(u.Module).init(gpa); + var moddir: []const u8 = undefined; for (m.deps) |d| { const p = try u.concat(&[_][]const u8{dir, "/deps/", try d.clean_path()}); const pv = try u.concat(&[_][]const u8{dir, "/v/", try d.clean_path(), "/", d.version}); u.print("fetch: {}: {}: {}", .{m.name, @tagName(d.type), d.path}); + moddir = p; switch (d.type) { .git => blk: { if (try u.does_file_exist(pv)) { + moddir = pv; break :blk; } if (!try u.does_file_exist(p)) { @@ -90,6 +93,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { _ = try run_cmd(pv, &[_][]const u8{"git", "checkout", ref}); const pvd = try std.fs.openDirAbsolute(pv, .{}); try pvd.deleteTree(".git"); + moddir = pv; } else { u.assert(false, "fetch: git: version type: '{}' on {} is invalid.", .{v_type_s, d.path}); @@ -109,12 +113,14 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { else => { if (d.main.len == 0) { if (d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { - try moduledeps.append(try u.Module.from(d)); + var mod_from = try u.Module.from(d); + mod_from.clean_path = u.trim_prefix(moddir, dir)[1..]; + try moduledeps.append(mod_from); } break; } - var dd = try fetch_deps(dir, try u.concat(&[_][]const u8{p, "/zig.mod"})); - dd.clean_path = try d.clean_path(); + var dd = try fetch_deps(dir, try u.concat(&[_][]const u8{moddir, "/zig.mod"})); + dd.clean_path = u.trim_prefix(moddir, dir)[1..]; if (d.name.len > 0) dd.name = d.name; if (d.main.len > 0) dd.main = d.main; -- 2.54.0