| ... | ... | @@ -31,7 +31,7 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO |
| 31 | 31 | var moduledeps = std.ArrayList(zigmod.Module).init(options.alloc); |
| 32 | 32 | errdefer moduledeps.deinit(); |
| 33 | 33 | if (m.root_files.len > 0) { |
| 34 | | try moduledeps.append(try add_files_package(options.alloc, cachepath, mdir, m.root_files)); |
| 34 | try gen_files_package(options.alloc, cachepath, mdir, m.root_files); |
| 35 | 35 | } |
| 36 | 36 | try moduledeps.append(try collect_deps(cachepath, mdir, .local, options)); |
| 37 | 37 | for (m.rootdeps) |*d| { |
| ... | ... | @@ -65,7 +65,7 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, dtype: zigmod.Dep.Type, |
| 65 | 65 | var moduledeps = std.ArrayList(zigmod.Module).init(options.alloc); |
| 66 | 66 | errdefer moduledeps.deinit(); |
| 67 | 67 | if (m.files.len > 0) { |
| 68 | | try moduledeps.append(try add_files_package(options.alloc, cachepath, mdir, m.files)); |
| 68 | try gen_files_package(options.alloc, cachepath, mdir, m.files); |
| 69 | 69 | } |
| 70 | 70 | for (m.deps) |*d| { |
| 71 | 71 | if (try get_module_from_dep(d, cachepath, options)) |founddep| { |
| ... | ... | @@ -117,7 +117,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! |
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | switch (d.type) { |
| 120 | | .local, .files => { |
| 120 | .local => { |
| 121 | 121 | if (!std.mem.endsWith(u8, d.main, ".zig")) { |
| 122 | 122 | return d.main; |
| 123 | 123 | } |
| ... | ... | @@ -216,7 +216,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 216 | 216 | } |
| 217 | 217 | if (!d.is_for_this()) return null; |
| 218 | 218 | const modpath = try get_modpath(cachepath, d.*, options); |
| 219 | | const moddir = if (d.type == .files or modpath.len == 0) try std.fs.cwd().openDir(cachepath, .{}) else try std.fs.cwd().openDir(modpath, .{}); |
| 219 | const moddir = if (modpath.len == 0) try std.fs.cwd().openDir(cachepath, .{}) else try std.fs.cwd().openDir(modpath, .{}); |
| 220 | 220 | |
| 221 | 221 | const nocache = d.type.isLocal(); |
| 222 | 222 | if (!nocache) try options.already_fetched.append(modpath); |
| ... | ... | @@ -244,7 +244,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 244 | 244 | error.ManifestNotFound => { |
| 245 | 245 | if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0 or d.keep) { |
| 246 | 246 | var mod_from = try zigmod.Module.from(options.alloc, d.*, cachepath, options); |
| 247 | | if (d.type != .local and d.type != .files) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; |
| 247 | if (d.type != .local) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; |
| 248 | 248 | if (mod_from.is_for_this()) return mod_from; |
| 249 | 249 | return null; |
| 250 | 250 | } |
| ... | ... | @@ -258,7 +258,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 258 | 258 | d.*.name = tryname; |
| 259 | 259 | d.*.main = trymain.?; |
| 260 | 260 | var mod_from = try zigmod.Module.from(options.alloc, d.*, cachepath, options); |
| 261 | | if (d.type != .local and d.type != .files) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; |
| 261 | if (d.type != .local) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; |
| 262 | 262 | if (mod_from.is_for_this()) return mod_from; |
| 263 | 263 | return null; |
| 264 | 264 | } |
| ... | ... | @@ -269,7 +269,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 269 | 269 | dd.dep = d.*; |
| 270 | 270 | dd.for_build = d.for_build; |
| 271 | 271 | const save = dd; |
| 272 | | if (d.type != .local and d.type != .files) dd.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; |
| 272 | if (d.type != .local) dd.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; |
| 273 | 273 | if (dd.id.len == 0) dd.id = try u.random_string(options.alloc, 48); |
| 274 | 274 | if (d.name.len > 0) dd.name = d.name; |
| 275 | 275 | if (d.main.len > 0) dd.main = d.main; |
| ... | ... | @@ -278,15 +278,14 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 278 | 278 | if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files; |
| 279 | 279 | if (d.only_os.len > 0) dd.only_os = d.only_os; |
| 280 | 280 | if (d.except_os.len > 0) dd.except_os = d.except_os; |
| 281 | | if (d.type == .local or d.type == .files) dd.main = try std.fs.path.join(options.alloc, &.{ d.main, save.main }); |
| 282 | | if (d.type == .files) dd.clean_path = modpath; |
| 281 | if (d.type == .local) dd.main = try std.fs.path.join(options.alloc, &.{ d.main, save.main }); |
| 283 | 282 | if (dd.is_for_this()) return dd; |
| 284 | 283 | return null; |
| 285 | 284 | }, |
| 286 | 285 | } |
| 287 | 286 | } |
| 288 | 287 | |
| 289 | | pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: std.fs.Dir, dirs: []const string) !zigmod.Module { |
| 288 | pub fn gen_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: std.fs.Dir, dirs: []const string) !void { |
| 290 | 289 | var map = std.StringHashMap(string).init(alloc); |
| 291 | 290 | defer map.deinit(); |
| 292 | 291 | |
| ... | ... | @@ -316,24 +315,6 @@ pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: std. |
| 316 | 315 | while (iter.next()) |item| { |
| 317 | 316 | try w.print("pub const @\"/{}\" = @embedFile(\"{}\");\n", .{ std.zig.fmtEscapes(item.key_ptr.*), std.zig.fmtEscapes(item.value_ptr.*) }); |
| 318 | 317 | } |
| 319 | | |
| 320 | | var d: zigmod.Dep = .{ |
| 321 | | .type = .files, |
| 322 | | .path = extras.trimPrefix(extras.trimPrefix(dpath, cachepath), "/"), |
| 323 | | .id = "", |
| 324 | | .name = "self/files", |
| 325 | | .main = fname, |
| 326 | | .version = "absolute", |
| 327 | | .yaml = null, |
| 328 | | .deps = &.{}, |
| 329 | | .parent_id = "TODO-1", |
| 330 | | }; |
| 331 | | var options = CollectOptions{ |
| 332 | | .log = false, |
| 333 | | .update = false, |
| 334 | | .alloc = alloc, |
| 335 | | }; |
| 336 | | return (try get_module_from_dep(&d, cachepath, &options)).?; |
| 337 | 318 | } |
| 338 | 319 | |
| 339 | 320 | pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]string { |