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");...@@ -10,7 +10,7 @@ const u = @import("./util/index.zig");
10pub fn execute(args: [][]u8) !void {10pub fn execute(args: [][]u8) !void {
11 //11 //
12 const home = try known_folders.getPath(gpa, .home);12 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
15 const top_module = try fetch_deps(dir, "./zig.mod");15 const top_module = try fetch_deps(dir, "./zig.mod");
1616
...@@ -62,13 +62,16 @@ pub fn execute(args: [][]u8) !void {...@@ -62,13 +62,16 @@ pub fn execute(args: [][]u8) !void {
62fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {62fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
63 const m = try u.ModFile.init(gpa, mpath);63 const m = try u.ModFile.init(gpa, mpath);
64 const moduledeps = &std.ArrayList(u.Module).init(gpa);64 const moduledeps = &std.ArrayList(u.Module).init(gpa);
65 var moddir: []const u8 = undefined;
65 for (m.deps) |d| {66 for (m.deps) |d| {
66 const p = try u.concat(&[_][]const u8{dir, "/deps/", try d.clean_path()});67 const p = try u.concat(&[_][]const u8{dir, "/deps/", try d.clean_path()});
67 const pv = try u.concat(&[_][]const u8{dir, "/v/", try d.clean_path(), "/", d.version});68 const pv = try u.concat(&[_][]const u8{dir, "/v/", try d.clean_path(), "/", d.version});
68 u.print("fetch: {}: {}: {}", .{m.name, @tagName(d.type), d.path});69 u.print("fetch: {}: {}: {}", .{m.name, @tagName(d.type), d.path});
70 moddir = p;
69 switch (d.type) {71 switch (d.type) {
70 .git => blk: {72 .git => blk: {
71 if (try u.does_file_exist(pv)) {73 if (try u.does_file_exist(pv)) {
74 moddir = pv;
72 break :blk;75 break :blk;
73 }76 }
74 if (!try u.does_file_exist(p)) {77 if (!try u.does_file_exist(p)) {
...@@ -90,6 +93,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {...@@ -90,6 +93,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
90 _ = try run_cmd(pv, &[_][]const u8{"git", "checkout", ref});93 _ = try run_cmd(pv, &[_][]const u8{"git", "checkout", ref});
91 const pvd = try std.fs.openDirAbsolute(pv, .{});94 const pvd = try std.fs.openDirAbsolute(pv, .{});
92 try pvd.deleteTree(".git");95 try pvd.deleteTree(".git");
96 moddir = pv;
93 }97 }
94 else {98 else {
95 u.assert(false, "fetch: git: version type: '{}' on {} is invalid.", .{v_type_s, d.path});99 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 {...@@ -109,12 +113,14 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
109 else => {113 else => {
110 if (d.main.len == 0) {114 if (d.main.len == 0) {
111 if (d.c_include_dirs.len > 0 or d.c_source_files.len > 0) {115 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);
113 }119 }
114 break;120 break;
115 }121 }
116 var dd = try fetch_deps(dir, try u.concat(&[_][]const u8{p, "/zig.mod"}));122 var dd = try fetch_deps(dir, try u.concat(&[_][]const u8{moddir, "/zig.mod"}));
117 dd.clean_path = try d.clean_path();123 dd.clean_path = u.trim_prefix(moddir, dir)[1..];
118124
119 if (d.name.len > 0) dd.name = d.name;125 if (d.name.len > 0) dd.name = d.name;
120 if (d.main.len > 0) dd.main = d.main;126 if (d.main.len > 0) dd.main = d.main;