authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-02 02:18:47 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-02 02:18:47 -08:00
log59348111497cce95db695dd8c4aafe73affc5c8c
tree8f7c0049ac0b41e08433ba8a9db34146b6673c24
parent0f2b7d5a7adb79c776ea58fd0e661c444991d298

common/add_files_package- make files dir inside


1 files changed, 11 insertions(+), 8 deletions(-)

src/common.zig+11-8
......@@ -34,8 +34,7 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO
3434 var moduledeps = std.ArrayList(zigmod.Module).init(options.alloc);
3535 defer moduledeps.deinit();
3636 if (m.root_files.len > 0) {
37 try std.fs.cwd().makePath(".zigmod/deps/files");
38 try moduledeps.append(try add_files_package(options.alloc, "root", mdir, m.root_files));
37 try moduledeps.append(try add_files_package(options.alloc, cachepath, "root", mdir, m.root_files));
3938 }
4039 try moduledeps.append(try collect_deps(cachepath, mdir, options));
4140 for (m.devdeps) |*d| {
......@@ -61,8 +60,7 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOption
6160 var moduledeps = std.ArrayList(zigmod.Module).init(options.alloc);
6261 defer moduledeps.deinit();
6362 if (m.files.len > 0) {
64 try std.fs.cwd().makePath(".zigmod/deps/files");
65 try moduledeps.append(try add_files_package(options.alloc, m.id, mdir, m.files));
63 try moduledeps.append(try add_files_package(options.alloc, cachepath, m.id, mdir, m.files));
6664 }
6765 for (m.deps) |*d| {
6866 if (try get_module_from_dep(d, cachepath, options)) |founddep| {
......@@ -279,8 +277,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
279277 }
280278}
281279
282pub fn add_files_package(alloc: *std.mem.Allocator, pkg_name: string, mdir: std.fs.Dir, dirs: []const string) !zigmod.Module {
283 const destination = ".zigmod/deps/files";
280pub fn add_files_package(alloc: *std.mem.Allocator, cachepath: string, pkg_name: string, mdir: std.fs.Dir, dirs: []const string) !zigmod.Module {
284281 const fname = try std.mem.join(alloc, "", &.{ pkg_name, ".zig" });
285282
286283 const map = &std.StringHashMap(string).init(alloc);
......@@ -304,7 +301,12 @@ pub fn add_files_package(alloc: *std.mem.Allocator, pkg_name: string, mdir: std.
304301 var fpath = u.trim_prefix(mpath, cwdpath);
305302 if (fpath.len == 0) fpath = std.fs.path.sep_str;
306303
307 const rff = try (try std.fs.cwd().openDir(destination, .{})).createFile(fname, .{});
304 var cachedir = try std.fs.cwd().openDir(cachepath, .{});
305 defer cachedir.close();
306 try cachedir.makePath("files");
307 var destdir = try cachedir.openDir("files", .{});
308 defer destdir.close();
309 const rff = try destdir.createFile(fname, .{});
308310 defer rff.close();
309311 const w = rff.writer();
310312 try w.writeAll(
......@@ -335,7 +337,8 @@ pub fn add_files_package(alloc: *std.mem.Allocator, pkg_name: string, mdir: std.
335337 .update = false,
336338 .alloc = alloc,
337339 };
338 return (try get_module_from_dep(&d, destination, &options)).?;
340 const filesdestpath = try std.fs.path.join(alloc, &.{ cachepath, "files" });
341 return (try get_module_from_dep(&d, filesdestpath, &options)).?;
339342}
340343
341344pub fn parse_lockfile(alloc: *std.mem.Allocator, dir: std.fs.Dir) ![]const [4]string {