| ... | @@ -2,6 +2,7 @@ const std = @import("std"); | ... | @@ -2,6 +2,7 @@ const std = @import("std"); |
| 2 | const gpa = std.heap.c_allocator; | 2 | const gpa = std.heap.c_allocator; |
| 3 | | 3 | |
| 4 | const u = @import("./util/index.zig"); | 4 | const u = @import("./util/index.zig"); |
| | 5 | const yaml = @import("./util/yaml.zig"); |
| 5 | | 6 | |
| 6 | // | 7 | // |
| 7 | // | 8 | // |
| ... | @@ -15,6 +16,10 @@ pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: CollectOpt | ... | @@ -15,6 +16,10 @@ pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: CollectOpt |
| 15 | const m = try u.ModFile.init(gpa, mpath); | 16 | const m = try u.ModFile.init(gpa, mpath); |
| 16 | const moduledeps = &std.ArrayList(u.Module).init(gpa); | 17 | const moduledeps = &std.ArrayList(u.Module).init(gpa); |
| 17 | defer moduledeps.deinit(); | 18 | defer moduledeps.deinit(); |
| | 19 | try std.fs.cwd().makePath(".zigmod/deps/files"); |
| | 20 | if (m.root_files.len > 0) { |
| | 21 | try add_files_package("root", m.root_files, moduledeps, m.name); |
| | 22 | } |
| 18 | try moduledeps.append(try collect_deps(dir, mpath, options)); | 23 | try moduledeps.append(try collect_deps(dir, mpath, options)); |
| 19 | for (m.devdeps) |d| { | 24 | for (m.devdeps) |d| { |
| 20 | if (!d.is_for_this()) { | 25 | if (!d.is_for_this()) { |
| ... | @@ -42,6 +47,9 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8, options: CollectOptions) | ... | @@ -42,6 +47,9 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8, options: CollectOptions) |
| 42 | const m = try u.ModFile.init(gpa, mpath); | 47 | const m = try u.ModFile.init(gpa, mpath); |
| 43 | const moduledeps = &std.ArrayList(u.Module).init(gpa); | 48 | const moduledeps = &std.ArrayList(u.Module).init(gpa); |
| 44 | defer moduledeps.deinit(); | 49 | defer moduledeps.deinit(); |
| | 50 | if (m.files.len > 0) { |
| | 51 | try add_files_package(m.id, m.files, moduledeps, m.name); |
| | 52 | } |
| 45 | for (m.deps) |d| { | 53 | for (m.deps) |d| { |
| 46 | if (!d.is_for_this()) { | 54 | if (!d.is_for_this()) { |
| 47 | continue; | 55 | continue; |
| ... | @@ -219,3 +227,66 @@ fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8 | ... | @@ -219,3 +227,66 @@ fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []const u8 |
| 219 | }, | 227 | }, |
| 220 | } | 228 | } |
| 221 | } | 229 | } |
| | 230 | |
| | 231 | fn add_files_package(pkg_name: []const u8, dirs: []const []const u8, list: *std.ArrayList(u.Module), parent_name: []const u8) !void { |
| | 232 | const destination = ".zigmod/deps/files"; |
| | 233 | const fname = try std.mem.join(gpa, "", &.{ pkg_name, ".zig" }); |
| | 234 | |
| | 235 | const map = &std.StringHashMap([]const u8).init(gpa); |
| | 236 | defer map.deinit(); |
| | 237 | |
| | 238 | for (dirs) |dir_path| { |
| | 239 | var walker = try std.fs.walkPath(gpa, dir_path); |
| | 240 | while (try walker.next()) |p| { |
| | 241 | if (p.kind == .Directory) { |
| | 242 | continue; |
| | 243 | } |
| | 244 | const path = try std.mem.dupe(gpa, u8, p.path); |
| | 245 | try map.put(path[dir_path.len..], path); |
| | 246 | } |
| | 247 | } |
| | 248 | |
| | 249 | const rff = try (try std.fs.cwd().openDir(destination, .{})).createFile(fname, .{}); |
| | 250 | defer rff.close(); |
| | 251 | const w = rff.writer(); |
| | 252 | try w.writeAll( |
| | 253 | \\const std = @import("std"); |
| | 254 | \\ |
| | 255 | \\const files = std.ComptimeStringMap([]const u8, .{ |
| | 256 | \\ |
| | 257 | ); |
| | 258 | var iter = map.iterator(); |
| | 259 | while (iter.next()) |item| { |
| | 260 | try w.print(" .{{ .@\"0\" = \"{}\", .@\"1\" = @embedFile(\"./../../../{}\") }},\n", .{ std.zig.fmtEscapes(item.key_ptr.*), std.zig.fmtEscapes(item.value_ptr.*) }); |
| | 261 | } |
| | 262 | try w.writeAll("\n"); |
| | 263 | try w.writeAll( |
| | 264 | \\}); |
| | 265 | \\ |
| | 266 | \\pub fn open(comptime path: []const u8) ?[]const u8 { |
| | 267 | \\ if (path.len == 0) return null; |
| | 268 | \\ if (path[0] != '/') return null; |
| | 269 | \\ return files.get(path); |
| | 270 | \\} |
| | 271 | \\ |
| | 272 | ); |
| | 273 | |
| | 274 | const d: u.Dep = .{ |
| | 275 | .type = .local, |
| | 276 | .path = "files", |
| | 277 | .id = "", |
| | 278 | .name = "self/files", |
| | 279 | .main = fname, |
| | 280 | .version = "absolute", |
| | 281 | .c_include_dirs = &.{}, |
| | 282 | .c_source_flags = &.{}, |
| | 283 | .c_source_files = &.{}, |
| | 284 | .only_os = &.{}, |
| | 285 | .except_os = &.{}, |
| | 286 | .yaml = null, |
| | 287 | }; |
| | 288 | try get_module_from_dep(list, d, destination, parent_name, .{ |
| | 289 | .log = false, |
| | 290 | .update = false, |
| | 291 | }); |
| | 292 | } |