diff --git a/docs/zig.mod.md b/docs/zig.mod.md index dcf6c1c92490b56391e47b3be2e65858b6eb116c..69434592d1967a04a7afb9ae25a0293761c2bfc9 100644 --- a/docs/zig.mod.md +++ b/docs/zig.mod.md @@ -36,11 +36,11 @@ This is a list of relative paths to C source files to compile along with this pr ### `files` - Type: `[]string` -This accepts a list of local directories to embed static assets. These files will be provided through a `self/files` package to `@import(main)`. +This accepts a list of local directories to embed static assets. These files will be provided through a `files.zig` files in the module root. It generates a list of `@embedFile` calls. ### `root_files` - Type: `[]string` -This accepts a list of local directories to embed static assets. These files will be provided through a `self/files` package to `@import("root")`. +This accepts a list of local directories to embed static assets. These files will be provided through a `files.zig` files in the package root. It generates a list of `@embedFile` calls. ### `dependencies` - Type: `[]Dep` diff --git a/src/cmd/generate.zig b/src/cmd/generate.zig index a41cb426471f8c2351fa8dac71462bdc3b936fe6..980663e9e84f08f21fa7f19a1a9e77743dc8e517 100644 --- a/src/cmd/generate.zig +++ b/src/cmd/generate.zig @@ -106,7 +106,6 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D .git => try w.print(" exe.step.dependOn(&GitExactStep.create(b, \"{s}\", \"{s}\").step);\n", .{ module.dep.?.path, try module.pin(alloc, cachepath) }), .hg => @panic("TODO"), .http => @panic("TODO"), - .files => {}, } } try w.writeAll( @@ -274,7 +273,6 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath: .git => try w.print(" .store = \"/{}/{s}\",\n", .{ std.zig.fmtEscapes(fixed_path), try mod.pin(alloc, cachepath) }), .hg => @panic("TODO"), .http => @panic("TODO"), - .files => {}, } if (mod.main.len > 0 and !std.mem.eql(u8, mod.id, "root")) { try w.print(" .name = \"{s}\",\n", .{mod.name}); diff --git a/src/common.zig b/src/common.zig index 1488aeb9becc6c93cbff9957e6cbe3d7d7da5bda..84deccad193cfc1bbbc63ab66a4e6a30085ab50c 100644 --- a/src/common.zig +++ b/src/common.zig @@ -31,7 +31,7 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO var moduledeps = std.ArrayList(zigmod.Module).init(options.alloc); errdefer moduledeps.deinit(); if (m.root_files.len > 0) { - try moduledeps.append(try add_files_package(options.alloc, cachepath, mdir, m.root_files)); + try gen_files_package(options.alloc, cachepath, mdir, m.root_files); } try moduledeps.append(try collect_deps(cachepath, mdir, .local, options)); for (m.rootdeps) |*d| { @@ -65,7 +65,7 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, dtype: zigmod.Dep.Type, var moduledeps = std.ArrayList(zigmod.Module).init(options.alloc); errdefer moduledeps.deinit(); if (m.files.len > 0) { - try moduledeps.append(try add_files_package(options.alloc, cachepath, mdir, m.files)); + try gen_files_package(options.alloc, cachepath, mdir, m.files); } for (m.deps) |*d| { 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) ! } } switch (d.type) { - .local, .files => { + .local => { if (!std.mem.endsWith(u8, d.main, ".zig")) { return d.main; } @@ -216,7 +216,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO } if (!d.is_for_this()) return null; const modpath = try get_modpath(cachepath, d.*, options); - const moddir = if (d.type == .files or modpath.len == 0) try std.fs.cwd().openDir(cachepath, .{}) else try std.fs.cwd().openDir(modpath, .{}); + const moddir = if (modpath.len == 0) try std.fs.cwd().openDir(cachepath, .{}) else try std.fs.cwd().openDir(modpath, .{}); const nocache = d.type.isLocal(); 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 error.ManifestNotFound => { if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0 or d.keep) { var mod_from = try zigmod.Module.from(options.alloc, d.*, cachepath, options); - if (d.type != .local and d.type != .files) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; + if (d.type != .local) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; if (mod_from.is_for_this()) return mod_from; return null; } @@ -258,7 +258,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO d.*.name = tryname; d.*.main = trymain.?; var mod_from = try zigmod.Module.from(options.alloc, d.*, cachepath, options); - if (d.type != .local and d.type != .files) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; + if (d.type != .local) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; if (mod_from.is_for_this()) return mod_from; return null; } @@ -269,7 +269,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO dd.dep = d.*; dd.for_build = d.for_build; const save = dd; - if (d.type != .local and d.type != .files) dd.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; + if (d.type != .local) dd.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; if (dd.id.len == 0) dd.id = try u.random_string(options.alloc, 48); if (d.name.len > 0) dd.name = d.name; 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 if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files; if (d.only_os.len > 0) dd.only_os = d.only_os; if (d.except_os.len > 0) dd.except_os = d.except_os; - if (d.type == .local or d.type == .files) dd.main = try std.fs.path.join(options.alloc, &.{ d.main, save.main }); - if (d.type == .files) dd.clean_path = modpath; + if (d.type == .local) dd.main = try std.fs.path.join(options.alloc, &.{ d.main, save.main }); if (dd.is_for_this()) return dd; return null; }, } } -pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: std.fs.Dir, dirs: []const string) !zigmod.Module { +pub fn gen_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: std.fs.Dir, dirs: []const string) !void { var map = std.StringHashMap(string).init(alloc); defer map.deinit(); @@ -316,24 +315,6 @@ pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: std. while (iter.next()) |item| { try w.print("pub const @\"/{}\" = @embedFile(\"{}\");\n", .{ std.zig.fmtEscapes(item.key_ptr.*), std.zig.fmtEscapes(item.value_ptr.*) }); } - - var d: zigmod.Dep = .{ - .type = .files, - .path = extras.trimPrefix(extras.trimPrefix(dpath, cachepath), "/"), - .id = "", - .name = "self/files", - .main = fname, - .version = "absolute", - .yaml = null, - .deps = &.{}, - .parent_id = "TODO-1", - }; - var options = CollectOptions{ - .log = false, - .update = false, - .alloc = alloc, - }; - return (try get_module_from_dep(&d, cachepath, &options)).?; } pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]string { diff --git a/src/util/dep.zig b/src/util/dep.zig index d50dcf34b21fea06c4043f5fdaa96b554d91e45a..e8bd2c5f16d8d33ae0abb3069102a45b84a08ce9 100644 --- a/src/util/dep.zig +++ b/src/util/dep.zig @@ -34,7 +34,7 @@ pub const Dep = struct { pub const Type = @import("./dep_type.zig").DepType; pub fn clean_path(self: Dep, alloc: std.mem.Allocator) !string { - if (self.type == .local or self.type == .files) { + if (self.type == .local) { return self.path; } var p = self.path; diff --git a/src/util/dep_type.zig b/src/util/dep_type.zig index ca06f61139451f8f6d7636d248bac90464b4210f..865b826028abbcb6175d6a050892da786115389a 100644 --- a/src/util/dep_type.zig +++ b/src/util/dep_type.zig @@ -14,7 +14,6 @@ pub const DepType = enum { git, // https://git-scm.com/ hg, // https://www.mercurial-scm.org/ http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol - files, // TEMP also local // zig fmt: on pub fn pull(self: DepType, alloc: std.mem.Allocator, rpath: string, dpath: string) !void { @@ -39,7 +38,6 @@ pub const DepType = enum { u.assert((try u.run_cmd(alloc, dpath, &.{ "tar", "-xf", f, "-C", "." })) == 0, "un-tar {s} failed", .{f}); } }, - .files => {}, } } @@ -60,7 +58,6 @@ pub const DepType = enum { .http => { // }, - .files => {}, } } @@ -74,7 +71,6 @@ pub const DepType = enum { .git => try std.fmt.allocPrint(alloc, "commit-{s}", .{(try u.git_rev_HEAD(alloc, mdir))}), .hg => "", .http => "", - .files => "", }; } @@ -86,7 +82,6 @@ pub const DepType = enum { .git => false, .hg => false, .http => false, - .files => true, }; } diff --git a/src/util/module.zig b/src/util/module.zig index 6bb8c5c9c869f0db81558ccfa273d87fedf374c2..ac1c03de7ee97351e5f827088da9ecab731a7b7b 100644 --- a/src/util/module.zig +++ b/src/util/module.zig @@ -174,7 +174,6 @@ pub const Module = struct { .git => try u.git_rev_HEAD(alloc, mdir), .hg => @panic("TODO"), .http => @panic("TODO"), - .files => unreachable, }; }, };