authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-08-26 11:48:26 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-08-26 11:48:26 -07:00
log8fb6d2491c0e80968ca83df0ba6599db3eaf150c
treea1c9a156aaf0ec9c6aca696038fd46e6b70b639a
parent97241c463edc1b4c43f39d7250fbc36059248795

remove self/files package since files.zig is now rendered in consumer root


6 files changed, 12 insertions(+), 39 deletions(-)

docs/zig.mod.md+2-2
......@@ -36,11 +36,11 @@ This is a list of relative paths to C source files to compile along with this pr
3636
3737### `files`
3838- Type: `[]string`
39This accepts a list of local directories to embed static assets. These files will be provided through a `self/files` package to `@import(main)`.
39This 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.
4040
4141### `root_files`
4242- Type: `[]string`
43This accepts a list of local directories to embed static assets. These files will be provided through a `self/files` package to `@import("root")`.
43This 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.
4444
4545### `dependencies`
4646- Type: `[]Dep`
src/cmd/generate.zig-2
......@@ -106,7 +106,6 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
106106 .git => try w.print(" exe.step.dependOn(&GitExactStep.create(b, \"{s}\", \"{s}\").step);\n", .{ module.dep.?.path, try module.pin(alloc, cachepath) }),
107107 .hg => @panic("TODO"),
108108 .http => @panic("TODO"),
109 .files => {},
110109 }
111110 }
112111 try w.writeAll(
......@@ -274,7 +273,6 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
274273 .git => try w.print(" .store = \"/{}/{s}\",\n", .{ std.zig.fmtEscapes(fixed_path), try mod.pin(alloc, cachepath) }),
275274 .hg => @panic("TODO"),
276275 .http => @panic("TODO"),
277 .files => {},
278276 }
279277 if (mod.main.len > 0 and !std.mem.eql(u8, mod.id, "root")) {
280278 try w.print(" .name = \"{s}\",\n", .{mod.name});
src/common.zig+9-28
......@@ -31,7 +31,7 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO
3131 var moduledeps = std.ArrayList(zigmod.Module).init(options.alloc);
3232 errdefer moduledeps.deinit();
3333 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);
3535 }
3636 try moduledeps.append(try collect_deps(cachepath, mdir, .local, options));
3737 for (m.rootdeps) |*d| {
......@@ -65,7 +65,7 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, dtype: zigmod.Dep.Type,
6565 var moduledeps = std.ArrayList(zigmod.Module).init(options.alloc);
6666 errdefer moduledeps.deinit();
6767 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);
6969 }
7070 for (m.deps) |*d| {
7171 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) !
117117 }
118118 }
119119 switch (d.type) {
120 .local, .files => {
120 .local => {
121121 if (!std.mem.endsWith(u8, d.main, ".zig")) {
122122 return d.main;
123123 }
......@@ -216,7 +216,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
216216 }
217217 if (!d.is_for_this()) return null;
218218 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, .{});
220220
221221 const nocache = d.type.isLocal();
222222 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
244244 error.ManifestNotFound => {
245245 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0 or d.keep) {
246246 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..];
248248 if (mod_from.is_for_this()) return mod_from;
249249 return null;
250250 }
......@@ -258,7 +258,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
258258 d.*.name = tryname;
259259 d.*.main = trymain.?;
260260 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..];
262262 if (mod_from.is_for_this()) return mod_from;
263263 return null;
264264 }
......@@ -269,7 +269,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
269269 dd.dep = d.*;
270270 dd.for_build = d.for_build;
271271 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..];
273273 if (dd.id.len == 0) dd.id = try u.random_string(options.alloc, 48);
274274 if (d.name.len > 0) dd.name = d.name;
275275 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
278278 if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files;
279279 if (d.only_os.len > 0) dd.only_os = d.only_os;
280280 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 });
283282 if (dd.is_for_this()) return dd;
284283 return null;
285284 },
286285 }
287286}
288287
289pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: std.fs.Dir, dirs: []const string) !zigmod.Module {
288pub fn gen_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: std.fs.Dir, dirs: []const string) !void {
290289 var map = std.StringHashMap(string).init(alloc);
291290 defer map.deinit();
292291
......@@ -316,24 +315,6 @@ pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: std.
316315 while (iter.next()) |item| {
317316 try w.print("pub const @\"/{}\" = @embedFile(\"{}\");\n", .{ std.zig.fmtEscapes(item.key_ptr.*), std.zig.fmtEscapes(item.value_ptr.*) });
318317 }
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)).?;
337318}
338319
339320pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]string {
src/util/dep.zig+1-1
......@@ -34,7 +34,7 @@ pub const Dep = struct {
3434 pub const Type = @import("./dep_type.zig").DepType;
3535
3636 pub fn clean_path(self: Dep, alloc: std.mem.Allocator) !string {
37 if (self.type == .local or self.type == .files) {
37 if (self.type == .local) {
3838 return self.path;
3939 }
4040 var p = self.path;
src/util/dep_type.zig-5
......@@ -14,7 +14,6 @@ pub const DepType = enum {
1414 git, // https://git-scm.com/
1515 hg, // https://www.mercurial-scm.org/
1616 http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
17 files, // TEMP also local
1817
1918 // zig fmt: on
2019 pub fn pull(self: DepType, alloc: std.mem.Allocator, rpath: string, dpath: string) !void {
......@@ -39,7 +38,6 @@ pub const DepType = enum {
3938 u.assert((try u.run_cmd(alloc, dpath, &.{ "tar", "-xf", f, "-C", "." })) == 0, "un-tar {s} failed", .{f});
4039 }
4140 },
42 .files => {},
4341 }
4442 }
4543
......@@ -60,7 +58,6 @@ pub const DepType = enum {
6058 .http => {
6159 //
6260 },
63 .files => {},
6461 }
6562 }
6663
......@@ -74,7 +71,6 @@ pub const DepType = enum {
7471 .git => try std.fmt.allocPrint(alloc, "commit-{s}", .{(try u.git_rev_HEAD(alloc, mdir))}),
7572 .hg => "",
7673 .http => "",
77 .files => "",
7874 };
7975 }
8076
......@@ -86,7 +82,6 @@ pub const DepType = enum {
8682 .git => false,
8783 .hg => false,
8884 .http => false,
89 .files => true,
9085 };
9186 }
9287
src/util/module.zig-1
......@@ -174,7 +174,6 @@ pub const Module = struct {
174174 .git => try u.git_rev_HEAD(alloc, mdir),
175175 .hg => @panic("TODO"),
176176 .http => @panic("TODO"),
177 .files => unreachable,
178177 };
179178 },
180179 };