authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-21 01:29:20 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-21 01:29:20 -07:00
log426ada3d7ce5491308a61eb366863ae236b19661
tree63932c9da09403acd4de1043c96a4faf41551f6a
parent76cb08619f79c914baebd7d5c11d4b453702872d

common- refactor collect_deps to accept a Dir instead of a path


5 files changed, 19 insertions(+), 15 deletions(-)

src/cmd/ci.zig+2-2
......@@ -10,15 +10,15 @@ const common = @import("./../common.zig");
1010pub fn execute(args: [][]u8) !void {
1111 _ = args;
1212
13 const dir = std.fs.cwd();
1413 const cachepath = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });
14 const dir = std.fs.cwd();
1515
1616 var options = common.CollectOptions{
1717 .log = true,
1818 .update = false,
1919 .lock = try common.parse_lockfile(dir),
2020 };
21 const top_module = try common.collect_deps_deep(cachepath, "zig.mod", &options);
21 const top_module = try common.collect_deps_deep(cachepath, dir, &options);
2222
2323 var list = std.ArrayList(u.Module).init(gpa);
2424 try common.collect_pkgs(top_module, &list);
src/cmd/fetch.zig+2-1
......@@ -18,13 +18,14 @@ const bootstrap = if (@hasDecl(build_options, "bootstrap")) build_options.bootst
1818pub fn execute(args: [][]u8) !void {
1919 //
2020 const cachepath = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });
21 const dir = std.fs.cwd();
2122 const should_update = !(args.len >= 1 and std.mem.eql(u8, args[0], "--no-update"));
2223
2324 var options = common.CollectOptions{
2425 .log = should_update,
2526 .update = should_update,
2627 };
27 const top_module = try common.collect_deps_deep(cachepath, "zig.mod", &options);
28 const top_module = try common.collect_deps_deep(cachepath, dir, &options);
2829
2930 var list = std.ArrayList(u.Module).init(gpa);
3031 try common.collect_pkgs(top_module, &list);
src/cmd/license.zig+2-1
......@@ -18,12 +18,13 @@ pub fn execute(args: [][]u8) !void {
1818 _ = args;
1919
2020 const cachepath = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });
21 const dir = std.fs.cwd();
2122
2223 var options = common.CollectOptions{
2324 .log = false,
2425 .update = false,
2526 };
26 const top_module = try common.collect_deps_deep(cachepath, "zig.mod", &options);
27 const top_module = try common.collect_deps_deep(cachepath, dir, &options);
2728
2829 const master_list = &List.init(gpa);
2930 try common.collect_pkgs(top_module, master_list);
src/cmd/sum.zig+3-2
......@@ -11,15 +11,16 @@ pub fn execute(args: [][]u8) !void {
1111 _ = args;
1212
1313 const cachepath = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" });
14 const dir = std.fs.cwd();
1415
1516 var options = common.CollectOptions{
1617 .log = false,
1718 .update = false,
1819 };
19 const top_module = try common.collect_deps_deep(cachepath, "zig.mod", &options);
20 const top_module = try common.collect_deps_deep(cachepath, dir, &options);
2021
2122 //
22 const f = try std.fs.cwd().createFile("zigmod.sum", .{});
23 const f = try dir.createFile("zigmod.sum", .{});
2324 defer f.close();
2425 const w = f.writer();
2526
src/common.zig+10-9
......@@ -27,8 +27,8 @@ pub const CollectOptions = struct {
2727 }
2828};
2929
30pub fn collect_deps_deep(cachepath: []const u8, mpath: []const u8, options: *CollectOptions) !u.Module {
31 const m = try u.ModFile.init(gpa, mpath);
30pub fn collect_deps_deep(cachepath: []const u8, mdir: std.fs.Dir, options: *CollectOptions) !u.Module {
31 const m = try u.ModFile.from_dir(gpa, mdir);
3232 try options.init();
3333 var moduledeps = std.ArrayList(u.Module).init(gpa);
3434 defer moduledeps.deinit();
......@@ -36,7 +36,7 @@ pub fn collect_deps_deep(cachepath: []const u8, mpath: []const u8, options: *Col
3636 try std.fs.cwd().makePath(".zigmod/deps/files");
3737 try moduledeps.append(try add_files_package("root", m.root_files, m.name));
3838 }
39 try moduledeps.append(try collect_deps(cachepath, mpath, options));
39 try moduledeps.append(try collect_deps(cachepath, mdir, options));
4040 for (m.devdeps) |*d| {
4141 if (try get_module_from_dep(d, cachepath, m.name, options)) |founddep| {
4242 try moduledeps.append(founddep);
......@@ -54,8 +54,8 @@ pub fn collect_deps_deep(cachepath: []const u8, mpath: []const u8, options: *Col
5454 };
5555}
5656
57pub fn collect_deps(cachepath: []const u8, mpath: []const u8, options: *CollectOptions) anyerror!u.Module {
58 const m = try u.ModFile.init(gpa, mpath);
57pub fn collect_deps(cachepath: []const u8, mdir: std.fs.Dir, options: *CollectOptions) anyerror!u.Module {
58 const m = try u.ModFile.from_dir(gpa, mdir);
5959 var moduledeps = std.ArrayList(u.Module).init(gpa);
6060 defer moduledeps.deinit();
6161 if (m.files.len > 0) {
......@@ -92,9 +92,9 @@ pub fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void
9292 }
9393}
9494
95pub fn get_modpath(basedir: []const u8, d: u.Dep, parent_name: []const u8, options: *CollectOptions) ![]const u8 {
96 const p = try std.fs.path.join(gpa, &.{ basedir, try d.clean_path() });
97 const pv = try std.fs.path.join(gpa, &.{ basedir, try d.clean_path_v() });
95pub fn get_modpath(cachepath: []const u8, d: u.Dep, parent_name: []const u8, options: *CollectOptions) ![]const u8 {
96 const p = try std.fs.path.join(gpa, &.{ cachepath, try d.clean_path() });
97 const pv = try std.fs.path.join(gpa, &.{ cachepath, try d.clean_path_v() });
9898
9999 const nocache = d.type == .local or d.type == .system_lib;
100100 if (!nocache and u.list_contains(options.already_fetched.items, p)) return p;
......@@ -209,6 +209,7 @@ pub fn get_module_from_dep(d: *u.Dep, cachepath: []const u8, parent_name: []cons
209209 }
210210 }
211211 const modpath = try get_modpath(cachepath, d.*, parent_name, options);
212 const moddir = try std.fs.cwd().openDir(modpath, .{});
212213
213214 const nocache = d.type == .local or d.type == .system_lib;
214215 if (!nocache) try options.already_fetched.append(modpath);
......@@ -229,7 +230,7 @@ pub fn get_module_from_dep(d: *u.Dep, cachepath: []const u8, parent_name: []cons
229230 };
230231 },
231232 else => {
232 var dd = try collect_deps(cachepath, try u.concat(&.{ modpath, "/zig.mod" }), options) catch |e| switch (e) {
233 var dd = try collect_deps(cachepath, moddir, options) catch |e| switch (e) {
233234 error.FileNotFound => {
234235 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) {
235236 var mod_from = try u.Module.from(d.*, cachepath, options);