authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-09-12 00:04:58 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-09-12 00:04:58 -07:00
log3f37f7d5d23b5df6f8f501047b02f6a6ebdae637
tree3488951c4eb7ba52087d8502d5d0d21f9f117def
parent88305122a91b853fc753fc05234b7f695e6ebe8c

fix files package generate for non-root sources


1 files changed, 14 insertions(+), 5 deletions(-)

src/common.zig+14-5
......@@ -34,7 +34,7 @@ pub fn collect_deps_deep(cachepath: []const u8, mdir: std.fs.Dir, options: *Coll
3434 defer moduledeps.deinit();
3535 if (m.root_files.len > 0) {
3636 try std.fs.cwd().makePath(".zigmod/deps/files");
37 try moduledeps.append(try add_files_package("root", m.root_files));
37 try moduledeps.append(try add_files_package("root", mdir, m.root_files));
3838 }
3939 try moduledeps.append(try collect_deps(cachepath, mdir, options));
4040 for (m.devdeps) |*d| {
......@@ -60,7 +60,7 @@ pub fn collect_deps(cachepath: []const u8, mdir: std.fs.Dir, options: *CollectOp
6060 defer moduledeps.deinit();
6161 if (m.files.len > 0) {
6262 try std.fs.cwd().makePath(".zigmod/deps/files");
63 try moduledeps.append(try add_files_package(m.id, m.files));
63 try moduledeps.append(try add_files_package(m.id, mdir, m.files));
6464 }
6565 for (m.deps) |*d| {
6666 if (try get_module_from_dep(d, cachepath, options)) |founddep| {
......@@ -276,7 +276,7 @@ pub fn get_module_from_dep(d: *u.Dep, cachepath: []const u8, options: *CollectOp
276276 }
277277}
278278
279pub fn add_files_package(pkg_name: []const u8, dirs: []const []const u8) !u.Module {
279pub fn add_files_package(pkg_name: []const u8, mdir: std.fs.Dir, dirs: []const []const u8) !u.Module {
280280 const destination = ".zigmod/deps/files";
281281 const fname = try std.mem.join(gpa, "", &.{ pkg_name, ".zig" });
282282
......@@ -284,7 +284,7 @@ pub fn add_files_package(pkg_name: []const u8, dirs: []const []const u8) !u.Modu
284284 defer map.deinit();
285285
286286 for (dirs) |dir_path| {
287 const dir = try std.fs.cwd().openDir(dir_path, .{ .iterate = true });
287 const dir = try mdir.openDir(dir_path, .{ .iterate = true });
288288 var walker = try dir.walk(gpa);
289289 defer walker.deinit();
290290 while (try walker.next()) |p| {
......@@ -296,18 +296,27 @@ pub fn add_files_package(pkg_name: []const u8, dirs: []const []const u8) !u.Modu
296296 }
297297 }
298298
299 const cwdpath = try std.fs.cwd().realpathAlloc(gpa, ".");
300 const mpath = try mdir.realpathAlloc(gpa, ".");
301 var fpath = u.trim_prefix(mpath, cwdpath);
302 if (fpath.len == 0) fpath = std.fs.path.sep_str;
303
299304 const rff = try (try std.fs.cwd().openDir(destination, .{})).createFile(fname, .{});
300305 defer rff.close();
301306 const w = rff.writer();
302307 try w.writeAll(
303308 \\const std = @import("std");
304309 \\
310 \\
311 );
312 try w.print("const srcpath = \"../../../{}\";\n\n", .{std.zig.fmtEscapes(fpath[1..])});
313 try w.writeAll(
305314 \\const files = std.ComptimeStringMap([]const u8, .{
306315 \\
307316 );
308317 var iter = map.iterator();
309318 while (iter.next()) |item| {
310 try w.print(" .{{ .@\"0\" = \"/{}\", .@\"1\" = @embedFile(\"./../../../{}\") }},\n", .{ std.zig.fmtEscapes(item.key_ptr.*), std.zig.fmtEscapes(item.value_ptr.*) });
319 try w.print(" .{{ .@\"0\" = \"/{}\", .@\"1\" = @embedFile(srcpath ++ \"/{}\") }},\n", .{ std.zig.fmtEscapes(item.key_ptr.*), std.zig.fmtEscapes(item.value_ptr.*) });
311320 }
312321 try w.writeAll("\n");
313322 try w.writeAll(