authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-08-14 14:39:45 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-08-14 14:39:45 -07:00
log254cb608f66ebbf7109491903f06c2ff41cf9dbc
treedc1f4b2fc9d577f02294c2937536028139f06865
parent62a4e5c6d539e1d41a66077fd5203aa76a8ccb34

update files/root_files attributes to be compatible with Zig 0.11


6 files changed, 31 insertions(+), 27 deletions(-)

src/cmd/generate.zig+2
......@@ -106,6 +106,7 @@ 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 => {},
109110 }
110111 }
111112 try w.writeAll(
......@@ -273,6 +274,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
273274 .git => try w.print(" .store = \"/{}/{s}\",\n", .{ std.zig.fmtEscapes(fixed_path), try mod.pin(alloc, cachepath) }),
274275 .hg => @panic("TODO"),
275276 .http => @panic("TODO"),
277 .files => {},
276278 }
277279 if (mod.main.len > 0 and !std.mem.eql(u8, mod.id, "root")) {
278280 try w.print(" .name = \"{s}\",\n", .{mod.name});
src/cmd/init.zig+1
......@@ -148,6 +148,7 @@ pub fn execute(args: [][]u8) !void {
148148 if (!exists) try w.writeAll("zig-*\n");
149149 try w.writeAll(".zigmod\n");
150150 try w.writeAll("deps.zig\n");
151 try w.writeAll("files.zig\n");
151152 }
152153 }
153154
src/common.zig+20-25
......@@ -31,8 +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 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));
3635 }
3736 try moduledeps.append(try collect_deps(cachepath, mdir, .local, options));
3837 for (m.rootdeps) |*d| {
......@@ -66,7 +65,7 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, dtype: zigmod.Dep.Type,
6665 var moduledeps = std.ArrayList(zigmod.Module).init(options.alloc);
6766 errdefer moduledeps.deinit();
6867 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));
7069 }
7170 for (m.deps) |*d| {
7271 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) !
118117 }
119118 }
120119 switch (d.type) {
121 .local => {
120 .local, .files => {
122121 if (!std.mem.endsWith(u8, d.main, ".zig")) {
123122 return d.main;
124123 }
......@@ -217,7 +216,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
217216 }
218217 if (!d.is_for_this()) return null;
219218 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, .{});
221220
222221 const nocache = d.type.isLocal();
223222 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
245244 error.ManifestNotFound => {
246245 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0 or d.keep) {
247246 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..];
249248 if (mod_from.is_for_this()) return mod_from;
250249 return null;
251250 }
......@@ -259,7 +258,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
259258 d.*.name = tryname;
260259 d.*.main = trymain.?;
261260 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..];
263262 if (mod_from.is_for_this()) return mod_from;
264263 return null;
265264 }
......@@ -270,7 +269,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
270269 dd.dep = d.*;
271270 dd.for_build = d.for_build;
272271 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..];
274273 if (dd.id.len == 0) dd.id = try u.random_string(options.alloc, 48);
275274 if (d.name.len > 0) dd.name = d.name;
276275 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
279278 if (d.c_source_files.len > 0) dd.c_source_files = d.c_source_files;
280279 if (d.only_os.len > 0) dd.only_os = d.only_os;
281280 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;
284283 if (dd.is_for_this()) return dd;
285284 return null;
286285 },
287286 }
288287}
289288
290pub 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
289pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: std.fs.Dir, dirs: []const string) !zigmod.Module {
293290 var map = std.StringHashMap(string).init(alloc);
294291 defer map.deinit();
295292
......@@ -306,24 +303,23 @@ pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, pkg_name:
306303 }
307304 }
308305
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;
315312 const rff = try destdir.createFile(fname, .{});
316313 defer rff.close();
317314 const w = rff.writer();
318 try w.print("const srcpath = \"/{}\";\n\n", .{std.zig.fmtEscapes(fpath[1..])});
319315 var iter = map.iterator();
320316 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.*) });
322318 }
323319
324320 var d: zigmod.Dep = .{
325 .type = .local,
326 .path = "files",
321 .type = .files,
322 .path = extras.trimPrefix(extras.trimPrefix(dpath, cachepath), "/"),
327323 .id = "",
328324 .name = "self/files",
329325 .main = fname,
......@@ -337,8 +333,7 @@ pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, pkg_name:
337333 .update = false,
338334 .alloc = alloc,
339335 };
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)).?;
342337}
343338
344339pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]string {
src/util/dep.zig+2-2
......@@ -34,8 +34,8 @@ 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) {
38 return if (self.path.len == 0) "../.." else self.path;
37 if (self.type == .local or self.type == .files) {
38 return self.path;
3939 }
4040 var p = self.path;
4141 p = extras.trimPrefix(p, "http://");
src/util/dep_type.zig+5
......@@ -14,6 +14,7 @@ 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
1718
1819 // zig fmt: on
1920 pub fn pull(self: DepType, alloc: std.mem.Allocator, rpath: string, dpath: string) !void {
......@@ -38,6 +39,7 @@ pub const DepType = enum {
3839 u.assert((try u.run_cmd(alloc, dpath, &.{ "tar", "-xf", f, "-C", "." })) == 0, "un-tar {s} failed", .{f});
3940 }
4041 },
42 .files => {},
4143 }
4244 }
4345
......@@ -58,6 +60,7 @@ pub const DepType = enum {
5860 .http => {
5961 //
6062 },
63 .files => {},
6164 }
6265 }
6366
......@@ -71,6 +74,7 @@ pub const DepType = enum {
7174 .git => try std.fmt.allocPrint(alloc, "commit-{s}", .{(try u.git_rev_HEAD(alloc, mdir))}),
7275 .hg => "",
7376 .http => "",
77 .files => "",
7478 };
7579 }
7680
......@@ -82,6 +86,7 @@ pub const DepType = enum {
8286 .git => false,
8387 .hg => false,
8488 .http => false,
89 .files => true,
8590 };
8691 }
8792
src/util/module.zig+1
......@@ -174,6 +174,7 @@ pub const Module = struct {
174174 .git => try u.git_rev_HEAD(alloc, mdir),
175175 .hg => @panic("TODO"),
176176 .http => @panic("TODO"),
177 .files => unreachable,
177178 };
178179 },
179180 };