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...@@ -106,6 +106,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
106 .git => try w.print(" exe.step.dependOn(&GitExactStep.create(b, \"{s}\", \"{s}\").step);\n", .{ module.dep.?.path, try module.pin(alloc, cachepath) }),106 .git => try w.print(" exe.step.dependOn(&GitExactStep.create(b, \"{s}\", \"{s}\").step);\n", .{ module.dep.?.path, try module.pin(alloc, cachepath) }),
107 .hg => @panic("TODO"),107 .hg => @panic("TODO"),
108 .http => @panic("TODO"),108 .http => @panic("TODO"),
109 .files => {},
109 }110 }
110 }111 }
111 try w.writeAll(112 try w.writeAll(
...@@ -273,6 +274,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:...@@ -273,6 +274,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
273 .git => try w.print(" .store = \"/{}/{s}\",\n", .{ std.zig.fmtEscapes(fixed_path), try mod.pin(alloc, cachepath) }),274 .git => try w.print(" .store = \"/{}/{s}\",\n", .{ std.zig.fmtEscapes(fixed_path), try mod.pin(alloc, cachepath) }),
274 .hg => @panic("TODO"),275 .hg => @panic("TODO"),
275 .http => @panic("TODO"),276 .http => @panic("TODO"),
277 .files => {},
276 }278 }
277 if (mod.main.len > 0 and !std.mem.eql(u8, mod.id, "root")) {279 if (mod.main.len > 0 and !std.mem.eql(u8, mod.id, "root")) {
278 try w.print(" .name = \"{s}\",\n", .{mod.name});280 try w.print(" .name = \"{s}\",\n", .{mod.name});
src/cmd/init.zig+1
...@@ -148,6 +148,7 @@ pub fn execute(args: [][]u8) !void {...@@ -148,6 +148,7 @@ pub fn execute(args: [][]u8) !void {
148 if (!exists) try w.writeAll("zig-*\n");148 if (!exists) try w.writeAll("zig-*\n");
149 try w.writeAll(".zigmod\n");149 try w.writeAll(".zigmod\n");
150 try w.writeAll("deps.zig\n");150 try w.writeAll("deps.zig\n");
151 try w.writeAll("files.zig\n");
151 }152 }
152 }153 }
153154
src/common.zig+20-25
...@@ -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, .{});
221220
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}
289288
290pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, pkg_name: string, mdir: std.fs.Dir, dirs: []const string) !zigmod.Module {289pub 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();
295292
...@@ -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 }
308305
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 }
323319
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}
343338
344pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]string {339pub 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 {...@@ -34,8 +34,8 @@ pub const Dep = struct {
34 pub const Type = @import("./dep_type.zig").DepType;34 pub const Type = @import("./dep_type.zig").DepType;
3535
36 pub fn clean_path(self: Dep, alloc: std.mem.Allocator) !string {36 pub fn clean_path(self: Dep, alloc: std.mem.Allocator) !string {
37 if (self.type == .local) {37 if (self.type == .local or self.type == .files) {
38 return if (self.path.len == 0) "../.." else self.path;38 return self.path;
39 }39 }
40 var p = self.path;40 var p = self.path;
41 p = extras.trimPrefix(p, "http://");41 p = extras.trimPrefix(p, "http://");
src/util/dep_type.zig+5
...@@ -14,6 +14,7 @@ pub const DepType = enum {...@@ -14,6 +14,7 @@ pub const DepType = enum {
14 git, // https://git-scm.com/14 git, // https://git-scm.com/
15 hg, // https://www.mercurial-scm.org/15 hg, // https://www.mercurial-scm.org/
16 http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol16 http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
17 files, // TEMP also local
1718
18 // zig fmt: on19 // zig fmt: on
19 pub fn pull(self: DepType, alloc: std.mem.Allocator, rpath: string, dpath: string) !void {20 pub fn pull(self: DepType, alloc: std.mem.Allocator, rpath: string, dpath: string) !void {
...@@ -38,6 +39,7 @@ pub const DepType = enum {...@@ -38,6 +39,7 @@ pub const DepType = enum {
38 u.assert((try u.run_cmd(alloc, dpath, &.{ "tar", "-xf", f, "-C", "." })) == 0, "un-tar {s} failed", .{f});39 u.assert((try u.run_cmd(alloc, dpath, &.{ "tar", "-xf", f, "-C", "." })) == 0, "un-tar {s} failed", .{f});
39 }40 }
40 },41 },
42 .files => {},
41 }43 }
42 }44 }
4345
...@@ -58,6 +60,7 @@ pub const DepType = enum {...@@ -58,6 +60,7 @@ pub const DepType = enum {
58 .http => {60 .http => {
59 //61 //
60 },62 },
63 .files => {},
61 }64 }
62 }65 }
6366
...@@ -71,6 +74,7 @@ pub const DepType = enum {...@@ -71,6 +74,7 @@ pub const DepType = enum {
71 .git => try std.fmt.allocPrint(alloc, "commit-{s}", .{(try u.git_rev_HEAD(alloc, mdir))}),74 .git => try std.fmt.allocPrint(alloc, "commit-{s}", .{(try u.git_rev_HEAD(alloc, mdir))}),
72 .hg => "",75 .hg => "",
73 .http => "",76 .http => "",
77 .files => "",
74 };78 };
75 }79 }
7680
...@@ -82,6 +86,7 @@ pub const DepType = enum {...@@ -82,6 +86,7 @@ pub const DepType = enum {
82 .git => false,86 .git => false,
83 .hg => false,87 .hg => false,
84 .http => false,88 .http => false,
89 .files => true,
85 };90 };
86 }91 }
8792
src/util/module.zig+1
...@@ -174,6 +174,7 @@ pub const Module = struct {...@@ -174,6 +174,7 @@ pub const Module = struct {
174 .git => try u.git_rev_HEAD(alloc, mdir),174 .git => try u.git_rev_HEAD(alloc, mdir),
175 .hg => @panic("TODO"),175 .hg => @panic("TODO"),
176 .http => @panic("TODO"),176 .http => @panic("TODO"),
177 .files => unreachable,
177 };178 };
178 },179 },
179 };180 };