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