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...@@ -34,7 +34,7 @@ pub fn collect_deps_deep(cachepath: []const u8, mdir: std.fs.Dir, options: *Coll
34 defer moduledeps.deinit();34 defer moduledeps.deinit();
35 if (m.root_files.len > 0) {35 if (m.root_files.len > 0) {
36 try std.fs.cwd().makePath(".zigmod/deps/files");36 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));
38 }38 }
39 try moduledeps.append(try collect_deps(cachepath, mdir, options));39 try moduledeps.append(try collect_deps(cachepath, mdir, options));
40 for (m.devdeps) |*d| {40 for (m.devdeps) |*d| {
...@@ -60,7 +60,7 @@ pub fn collect_deps(cachepath: []const u8, mdir: std.fs.Dir, options: *CollectOp...@@ -60,7 +60,7 @@ pub fn collect_deps(cachepath: []const u8, mdir: std.fs.Dir, options: *CollectOp
60 defer moduledeps.deinit();60 defer moduledeps.deinit();
61 if (m.files.len > 0) {61 if (m.files.len > 0) {
62 try std.fs.cwd().makePath(".zigmod/deps/files");62 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));
64 }64 }
65 for (m.deps) |*d| {65 for (m.deps) |*d| {
66 if (try get_module_from_dep(d, cachepath, options)) |founddep| {66 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...@@ -276,7 +276,7 @@ pub fn get_module_from_dep(d: *u.Dep, cachepath: []const u8, options: *CollectOp
276 }276 }
277}277}
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 {
280 const destination = ".zigmod/deps/files";280 const destination = ".zigmod/deps/files";
281 const fname = try std.mem.join(gpa, "", &.{ pkg_name, ".zig" });281 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...@@ -284,7 +284,7 @@ pub fn add_files_package(pkg_name: []const u8, dirs: []const []const u8) !u.Modu
284 defer map.deinit();284 defer map.deinit();
285285
286 for (dirs) |dir_path| {286 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 });
288 var walker = try dir.walk(gpa);288 var walker = try dir.walk(gpa);
289 defer walker.deinit();289 defer walker.deinit();
290 while (try walker.next()) |p| {290 while (try walker.next()) |p| {
...@@ -296,18 +296,27 @@ pub fn add_files_package(pkg_name: []const u8, dirs: []const []const u8) !u.Modu...@@ -296,18 +296,27 @@ pub fn add_files_package(pkg_name: []const u8, dirs: []const []const u8) !u.Modu
296 }296 }
297 }297 }
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
299 const rff = try (try std.fs.cwd().openDir(destination, .{})).createFile(fname, .{});304 const rff = try (try std.fs.cwd().openDir(destination, .{})).createFile(fname, .{});
300 defer rff.close();305 defer rff.close();
301 const w = rff.writer();306 const w = rff.writer();
302 try w.writeAll(307 try w.writeAll(
303 \\const std = @import("std");308 \\const std = @import("std");
304 \\309 \\
310 \\
311 );
312 try w.print("const srcpath = \"../../../{}\";\n\n", .{std.zig.fmtEscapes(fpath[1..])});
313 try w.writeAll(
305 \\const files = std.ComptimeStringMap([]const u8, .{314 \\const files = std.ComptimeStringMap([]const u8, .{
306 \\315 \\
307 );316 );
308 var iter = map.iterator();317 var iter = map.iterator();
309 while (iter.next()) |item| {318 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.*) });
311 }320 }
312 try w.writeAll("\n");321 try w.writeAll("\n");
313 try w.writeAll(322 try w.writeAll(