authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-20 13:37:07 -08:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-20 13:37:07 -08:00
log96ae02db8af8a0024a109fcf5809e335f3bd4ad7
treecdf415776682dfcd0f9c7cdbe16835f04e99ff20
parent2aa95da7dbd0f9b23fb6e99935882b02394016b2

fetch: set module_dir to version one if its validated


1 files changed, 10 insertions(+), 4 deletions(-)

src/cmd_fetch.zig+10-4
......@@ -10,7 +10,7 @@ const u = @import("./util/index.zig");
1010pub fn execute(args: [][]u8) !void {
1111 //
1212 const home = try known_folders.getPath(gpa, .home);
13 const dir = try std.fmt.allocPrint(gpa, "{}{}", .{home, "/.cache/zigmod/deps"});
13 const dir = try std.fmt.allocPrint(gpa, "{}{}", .{home, "/.cache/zigmod"});
1414
1515 const top_module = try fetch_deps(dir, "./zig.mod");
1616
......@@ -62,13 +62,16 @@ pub fn execute(args: [][]u8) !void {
6262fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
6363 const m = try u.ModFile.init(gpa, mpath);
6464 const moduledeps = &std.ArrayList(u.Module).init(gpa);
65 var moddir: []const u8 = undefined;
6566 for (m.deps) |d| {
6667 const p = try u.concat(&[_][]const u8{dir, "/deps/", try d.clean_path()});
6768 const pv = try u.concat(&[_][]const u8{dir, "/v/", try d.clean_path(), "/", d.version});
6869 u.print("fetch: {}: {}: {}", .{m.name, @tagName(d.type), d.path});
70 moddir = p;
6971 switch (d.type) {
7072 .git => blk: {
7173 if (try u.does_file_exist(pv)) {
74 moddir = pv;
7275 break :blk;
7376 }
7477 if (!try u.does_file_exist(p)) {
......@@ -90,6 +93,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
9093 _ = try run_cmd(pv, &[_][]const u8{"git", "checkout", ref});
9194 const pvd = try std.fs.openDirAbsolute(pv, .{});
9295 try pvd.deleteTree(".git");
96 moddir = pv;
9397 }
9498 else {
9599 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 {
109113 else => {
110114 if (d.main.len == 0) {
111115 if (d.c_include_dirs.len > 0 or d.c_source_files.len > 0) {
112 try moduledeps.append(try u.Module.from(d));
116 var mod_from = try u.Module.from(d);
117 mod_from.clean_path = u.trim_prefix(moddir, dir)[1..];
118 try moduledeps.append(mod_from);
113119 }
114120 break;
115121 }
116 var dd = try fetch_deps(dir, try u.concat(&[_][]const u8{p, "/zig.mod"}));
117 dd.clean_path = try d.clean_path();
122 var dd = try fetch_deps(dir, try u.concat(&[_][]const u8{moddir, "/zig.mod"}));
123 dd.clean_path = u.trim_prefix(moddir, dir)[1..];
118124
119125 if (d.name.len > 0) dd.name = d.name;
120126 if (d.main.len > 0) dd.main = d.main;