| ... | ... | @@ -31,8 +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 | | const builddotzig = try extras.hashFile(mdir, "build.zig", std.crypto.hash.Sha1); |
| 35 | | try moduledeps.append(try add_files_package(options.alloc, cachepath, "root_" ++ &builddotzig, mdir, m.root_files)); |
| 34 | try moduledeps.append(try add_files_package(options.alloc, cachepath, mdir, m.root_files)); |
| 36 | 35 | } |
| 37 | 36 | try moduledeps.append(try collect_deps(cachepath, mdir, .local, options)); |
| 38 | 37 | for (m.rootdeps) |*d| { |
| ... | ... | @@ -66,7 +65,7 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, dtype: zigmod.Dep.Type, |
| 66 | 65 | var moduledeps = std.ArrayList(zigmod.Module).init(options.alloc); |
| 67 | 66 | errdefer moduledeps.deinit(); |
| 68 | 67 | if (m.files.len > 0) { |
| 69 | | try moduledeps.append(try add_files_package(options.alloc, cachepath, m.id, mdir, m.files)); |
| 68 | try moduledeps.append(try add_files_package(options.alloc, cachepath, mdir, m.files)); |
| 70 | 69 | } |
| 71 | 70 | for (m.deps) |*d| { |
| 72 | 71 | if (try get_module_from_dep(d, cachepath, options)) |founddep| { |
| ... | ... | @@ -118,7 +117,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! |
| 118 | 117 | } |
| 119 | 118 | } |
| 120 | 119 | switch (d.type) { |
| 121 | | .local => { |
| 120 | .local, .files => { |
| 122 | 121 | if (!std.mem.endsWith(u8, d.main, ".zig")) { |
| 123 | 122 | return d.main; |
| 124 | 123 | } |
| ... | ... | @@ -217,7 +216,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 217 | 216 | } |
| 218 | 217 | if (!d.is_for_this()) return null; |
| 219 | 218 | const modpath = try get_modpath(cachepath, d.*, options); |
| 220 | | const moddir = if (std.mem.eql(u8, modpath, "files") or modpath.len == 0) try std.fs.cwd().openDir(cachepath, .{}) else try std.fs.cwd().openDir(modpath, .{}); |
| 219 | const moddir = if (d.type == .files or modpath.len == 0) try std.fs.cwd().openDir(cachepath, .{}) else try std.fs.cwd().openDir(modpath, .{}); |
| 221 | 220 | |
| 222 | 221 | const nocache = d.type.isLocal(); |
| 223 | 222 | if (!nocache) try options.already_fetched.append(modpath); |
| ... | ... | @@ -245,7 +244,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 245 | 244 | error.ManifestNotFound => { |
| 246 | 245 | if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0 or d.keep) { |
| 247 | 246 | var mod_from = try zigmod.Module.from(options.alloc, d.*, cachepath, options); |
| 248 | | if (d.type != .local) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; |
| 247 | if (d.type != .local and d.type != .files) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; |
| 249 | 248 | if (mod_from.is_for_this()) return mod_from; |
| 250 | 249 | return null; |
| 251 | 250 | } |
| ... | ... | @@ -259,7 +258,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 259 | 258 | d.*.name = tryname; |
| 260 | 259 | d.*.main = trymain.?; |
| 261 | 260 | var mod_from = try zigmod.Module.from(options.alloc, d.*, cachepath, options); |
| 262 | | if (d.type != .local) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; |
| 261 | if (d.type != .local and d.type != .files) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; |
| 263 | 262 | if (mod_from.is_for_this()) return mod_from; |
| 264 | 263 | return null; |
| 265 | 264 | } |
| ... | ... | @@ -270,7 +269,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 270 | 269 | dd.dep = d.*; |
| 271 | 270 | dd.for_build = d.for_build; |
| 272 | 271 | const save = dd; |
| 273 | | if (d.type != .local) dd.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; |
| 272 | if (d.type != .local and d.type != .files) dd.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; |
| 274 | 273 | if (dd.id.len == 0) dd.id = try u.random_string(options.alloc, 48); |
| 275 | 274 | if (d.name.len > 0) dd.name = d.name; |
| 276 | 275 | if (d.main.len > 0) dd.main = d.main; |
| ... | ... | @@ -279,17 +278,15 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 279 | 278 | if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files; |
| 280 | 279 | if (d.only_os.len > 0) dd.only_os = d.only_os; |
| 281 | 280 | if (d.except_os.len > 0) dd.except_os = d.except_os; |
| 282 | | if (d.type == .local) dd.main = try std.fs.path.join(options.alloc, &.{ d.main, save.main }); |
| 283 | | if (std.mem.eql(u8, modpath, "files")) dd.clean_path = modpath; |
| 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; |
| 284 | 283 | if (dd.is_for_this()) return dd; |
| 285 | 284 | return null; |
| 286 | 285 | }, |
| 287 | 286 | } |
| 288 | 287 | } |
| 289 | 288 | |
| 290 | | pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, pkg_name: string, mdir: std.fs.Dir, dirs: []const string) !zigmod.Module { |
| 291 | | const fname = try std.mem.join(alloc, "", &.{ pkg_name, ".zig" }); |
| 292 | | |
| 289 | pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: std.fs.Dir, dirs: []const string) !zigmod.Module { |
| 293 | 290 | var map = std.StringHashMap(string).init(alloc); |
| 294 | 291 | defer map.deinit(); |
| 295 | 292 | |
| ... | ... | @@ -306,24 +303,23 @@ pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, pkg_name: |
| 306 | 303 | } |
| 307 | 304 | } |
| 308 | 305 | |
| 309 | | const fpath = try mdir.realpathAlloc(alloc, "."); |
| 310 | | var cachedir = try std.fs.cwd().openDir(cachepath, .{}); |
| 311 | | defer cachedir.close(); |
| 312 | | try cachedir.makePath("files"); |
| 313 | | var destdir = try cachedir.openDir("files", .{}); |
| 314 | | defer destdir.close(); |
| 306 | var dpath: string = try mdir.realpathAlloc(alloc, "."); |
| 307 | const is_not_root = std.mem.indexOf(u8, dpath, cachepath); |
| 308 | dpath = if (is_not_root) |idx| dpath[idx..] else "../.."; |
| 309 | |
| 310 | const fname = "files.zig"; |
| 311 | const destdir = mdir; |
| 315 | 312 | const rff = try destdir.createFile(fname, .{}); |
| 316 | 313 | defer rff.close(); |
| 317 | 314 | const w = rff.writer(); |
| 318 | | try w.print("const srcpath = \"/{}\";\n\n", .{std.zig.fmtEscapes(fpath[1..])}); |
| 319 | 315 | var iter = map.iterator(); |
| 320 | 316 | while (iter.next()) |item| { |
| 321 | | try w.print("pub const @\"/{}\" = @embedFile(srcpath ++ \"/{}\");\n", .{ std.zig.fmtEscapes(item.key_ptr.*), std.zig.fmtEscapes(item.value_ptr.*) }); |
| 317 | try w.print("pub const @\"/{}\" = @embedFile(\"{}\");\n", .{ std.zig.fmtEscapes(item.key_ptr.*), std.zig.fmtEscapes(item.value_ptr.*) }); |
| 322 | 318 | } |
| 323 | 319 | |
| 324 | 320 | var d: zigmod.Dep = .{ |
| 325 | | .type = .local, |
| 326 | | .path = "files", |
| 321 | .type = .files, |
| 322 | .path = extras.trimPrefix(extras.trimPrefix(dpath, cachepath), "/"), |
| 327 | 323 | .id = "", |
| 328 | 324 | .name = "self/files", |
| 329 | 325 | .main = fname, |
| ... | ... | @@ -337,8 +333,7 @@ pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, pkg_name: |
| 337 | 333 | .update = false, |
| 338 | 334 | .alloc = alloc, |
| 339 | 335 | }; |
| 340 | | const filesdestpath = try std.fs.path.join(alloc, &.{ cachepath, "files" }); |
| 341 | | return (try get_module_from_dep(&d, filesdestpath, &options)).?; |
| 336 | return (try get_module_from_dep(&d, cachepath, &options)).?; |
| 342 | 337 | } |
| 343 | 338 | |
| 344 | 339 | pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]string { |