authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-30 02:17:38 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-30 02:17:38 -07:00
log773b09ff745c30c0e02b6d4717e0da9cb10b2978
tree2d9a771dddfa90375973757f8f32527ee62d002b
parentd5d2b751e297e1ec5e80b2ac29b7c23d746c761b
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

use nfs more


18 files changed, 245 insertions(+), 186 deletions(-)

deps.zig+15-15
......@@ -60,7 +60,7 @@ pub fn fetch(exe: *std.Build.Step.Compile) *std.Build.Step {
6060 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zfetch", "40d141bf7db81f05a83cce5f2edc4b14e41a5c34").step);
6161 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-ansi", "5f89211a749aef6bf518889c0467ceb24825c055").step);
6262 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-detect-license", "a1a066da88dab50873a56f0349dc12dc76542077").step);
63 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-extras", "c2c581aa6a38438dd9ed8da0f59019691c5dd45d").step);
63 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-extras", "b3457b31a1d1ea2c19c5d0b007c903d3e80add40").step);
6464 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-git", "2b3f83cd341764f979969603e4f77e62f353b6a3").step);
6565 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-inquirer", "4cddefa42744d61067567b0b36b5d2bb376e5ae3").step);
6666 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-intrusive-parser", "a31b480914d15f3d13cdfb586aac950c73beebdd").step);
......@@ -68,13 +68,13 @@ pub fn fetch(exe: *std.Build.Step.Compile) *std.Build.Step {
6868 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-leven", "618eddde4ffbc6d34100e4bc6aa654d41161537a").step);
6969 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses", "16cef5e32b3f8bbcf1064c599615290a720b6547").step);
7070 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses-text", "ba0f00dfb23d28c301e4b54d0a278def2c38dc7b").step);
71 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-nfs", "18b00c5c5d25e230ff4f3ea07fadb2a1d54a773d").step);
71 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-nfs", "c855473c8bd15dd24a4e8b6911b7e006062004ba").step);
7272 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-nio", "c1da2e8a31858880eb3e4cfcf12de0a865617623").step);
73 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-sys-darwin", "c5c1b35492224b0ed8d2570c8e71702947b1e400").step);
74 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-sys-linux", "9edefde5fcf96894b6aa4ab60241940bba65debf").step);
73 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-sys-darwin", "3265d1f06418eb0360d753c12116310a14b97bde").step);
74 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-sys-linux", "f0b155d3627f8c19868be1b2f15d71cda908b575").step);
7575 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-time", "0f4db4c980146e4a3fc86a9a9070452a25ff9317").step);
7676 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-tracer", "3a5fdea4ffd387a53ac2a42fb503557cdbe20696").step);
77 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-yaml", "b1ebd056b9afaaa719cb55359c610455ffe04499").step);
77 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-yaml", "00e899bec815bc2b49c6e5a72a7cfeeda673e133").step);
7878 step.dependOn(&GitExactStep.create(b, "https://github.com/truemedian/hzzp", "ab212bd208f0eb54d85861679677c5e3dc9bb543").step);
7979 step.dependOn(&GitExactStep.create(b, "https://github.com/madler/zlib", "da607da739fa6047df13e66a2af6b8bec7c2a498").step);
8080 step.dependOn(&GitExactStep.create(b, "https://github.com/yaml/libyaml", "2c891fc7a770e8ba2fec34fc6b545c672beb37e6").step);
......@@ -210,9 +210,9 @@ pub const package_data = struct {
210210 .entry = "/git/github.com/nektro/zig-ansi/5f89211a749aef6bf518889c0467ceb24825c055/src/lib.zig",
211211 };
212212 pub var _f7dubzb7cyqe = Package{
213 .store = "/git/github.com/nektro/zig-extras/c2c581aa6a38438dd9ed8da0f59019691c5dd45d",
213 .store = "/git/github.com/nektro/zig-extras/b3457b31a1d1ea2c19c5d0b007c903d3e80add40",
214214 .name = "extras",
215 .entry = "/git/github.com/nektro/zig-extras/c2c581aa6a38438dd9ed8da0f59019691c5dd45d/src/lib.zig",
215 .entry = "/git/github.com/nektro/zig-extras/b3457b31a1d1ea2c19c5d0b007c903d3e80add40/src/lib.zig",
216216 };
217217 pub var _c1xirp1ota5p = Package{
218218 .store = "/git/github.com/nektro/zig-inquirer/4cddefa42744d61067567b0b36b5d2bb376e5ae3",
......@@ -231,14 +231,14 @@ pub const package_data = struct {
231231 .entry = "/git/github.com/nektro/zig-licenses/16cef5e32b3f8bbcf1064c599615290a720b6547/src/lib.zig",
232232 };
233233 pub var _73bukkeci2u6 = Package{
234 .store = "/git/github.com/nektro/zig-sys-darwin/c5c1b35492224b0ed8d2570c8e71702947b1e400",
234 .store = "/git/github.com/nektro/zig-sys-darwin/3265d1f06418eb0360d753c12116310a14b97bde",
235235 .name = "sys-darwin",
236 .entry = "/git/github.com/nektro/zig-sys-darwin/c5c1b35492224b0ed8d2570c8e71702947b1e400/sys_darwin.zig",
236 .entry = "/git/github.com/nektro/zig-sys-darwin/3265d1f06418eb0360d753c12116310a14b97bde/sys_darwin.zig",
237237 };
238238 pub var _h7tv7ayhffak = Package{
239 .store = "/git/github.com/nektro/zig-sys-linux/9edefde5fcf96894b6aa4ab60241940bba65debf",
239 .store = "/git/github.com/nektro/zig-sys-linux/f0b155d3627f8c19868be1b2f15d71cda908b575",
240240 .name = "sys-linux",
241 .entry = "/git/github.com/nektro/zig-sys-linux/9edefde5fcf96894b6aa4ab60241940bba65debf/mod.zig",
241 .entry = "/git/github.com/nektro/zig-sys-linux/f0b155d3627f8c19868be1b2f15d71cda908b575/mod.zig",
242242 .deps = &[_]*Package{ },
243243 .system_libs = &.{ "c" },
244244 };
......@@ -261,9 +261,9 @@ pub const package_data = struct {
261261 .deps = &[_]*Package{ &_f7dubzb7cyqe, &_h7tv7ayhffak, &_73bukkeci2u6 },
262262 };
263263 pub var _vph9l0hxpeze = Package{
264 .store = "/git/github.com/nektro/zig-nfs/18b00c5c5d25e230ff4f3ea07fadb2a1d54a773d",
264 .store = "/git/github.com/nektro/zig-nfs/c855473c8bd15dd24a4e8b6911b7e006062004ba",
265265 .name = "nfs",
266 .entry = "/git/github.com/nektro/zig-nfs/18b00c5c5d25e230ff4f3ea07fadb2a1d54a773d/nfs.zig",
266 .entry = "/git/github.com/nektro/zig-nfs/c855473c8bd15dd24a4e8b6911b7e006062004ba/nfs.zig",
267267 .deps = &[_]*Package{ &_h7tv7ayhffak, &_kscsl0145t7x, &_iecwp4b3bsfm, &_73bukkeci2u6 },
268268 };
269269 pub var _ede2wygpe1iy = Package{
......@@ -297,9 +297,9 @@ pub const package_data = struct {
297297 .deps = &[_]*Package{ &_pt88y5d80m25, &_96h80ezrvj7i },
298298 };
299299 pub var _g982zq6e8wsv = Package{
300 .store = "/git/github.com/nektro/zig-yaml/b1ebd056b9afaaa719cb55359c610455ffe04499",
300 .store = "/git/github.com/nektro/zig-yaml/00e899bec815bc2b49c6e5a72a7cfeeda673e133",
301301 .name = "yaml",
302 .entry = "/git/github.com/nektro/zig-yaml/b1ebd056b9afaaa719cb55359c610455ffe04499/yaml.zig",
302 .entry = "/git/github.com/nektro/zig-yaml/00e899bec815bc2b49c6e5a72a7cfeeda673e133/yaml.zig",
303303 .deps = &[_]*Package{ &_8mdbh0zuneb0 },
304304 };
305305 pub var _9k24gimke1an = Package{
src/cmd/ci.zig+3-2
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const string = []const u8;
3const nfs = @import("nfs");
34
45const zigmod = @import("../lib.zig");
56const u = @import("./../util/funcs.zig");
......@@ -14,11 +15,11 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
1415
1516 const gpa = std.heap.c_allocator;
1617 const cachepath = try u.find_cachepath();
17 const dir = std.fs.cwd();
18 const dir = nfs.cwd();
1819 try do(gpa, cachepath, dir);
1920}
2021
21pub fn do(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.Dir) !void {
22pub fn do(alloc: std.mem.Allocator, cachepath: [:0]const u8, dir: nfs.Dir) !void {
2223 var options = common.CollectOptions{
2324 .log = true,
2425 .update = false,
src/cmd/explain.zig+2-1
......@@ -1,6 +1,7 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const extras = @import("extras");
4const nfs = @import("nfs");
45
56const zigmod = @import("../lib.zig");
67const u = @import("./../util/funcs.zig");
......@@ -14,7 +15,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
1415
1516 const gpa = std.heap.c_allocator;
1617 const cachepath = try u.find_cachepath();
17 const dir = std.fs.cwd();
18 const dir = nfs.cwd();
1819 const should_lock = args.len >= 1 and std.mem.eql(u8, args[0], "--locked");
1920 const format_i: usize = if (should_lock) 1 else 0;
2021 const Format = enum {
src/cmd/fetch.zig+23-22
......@@ -2,6 +2,7 @@ const std = @import("std");
22const string = []const u8;
33const ansi = @import("ansi");
44const extras = @import("extras");
5const nfs = @import("nfs");
56
67const zigmod = @import("../lib.zig");
78const u = @import("./../util/funcs.zig");
......@@ -16,7 +17,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
1617
1718 const gpa = std.heap.c_allocator;
1819 const cachepath = try u.find_cachepath();
19 const dir = std.fs.cwd();
20 const dir = nfs.cwd();
2021 const should_update = !(args.len >= 1 and std.mem.eql(u8, args[0], "--no-update"));
2122
2223 var options = common.CollectOptions{
......@@ -43,17 +44,17 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
4344 try license.do(cachepath, dir, &options, outfile);
4445}
4546
46pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.Dir, top_module: zigmod.Module, list: *std.ArrayList(zigmod.Module)) !void {
47pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: nfs.Dir, top_module: zigmod.Module, list: *std.ArrayList(zigmod.Module)) !void {
4748 const f = try dir.createFile("deps.zig", .{});
4849 defer f.close();
4950
50 const w = f.writer();
51 const w = f;
5152 try w.writeAll("// zig fmt: off\n");
5253 try w.writeAll("const std = @import(\"std\");\n");
5354 try w.writeAll("const builtin = @import(\"builtin\");\n");
5455 try w.writeAll("const string = []const u8;\n");
5556 try w.writeAll("\n");
56 try w.print("pub const cache = \"{}\";\n", .{std.zig.fmtEscapes(cachepath)});
57 try w.print("pub const cache = \"{}\";\n", .{u.altStringEscape(cachepath)});
5758 try w.writeAll("pub var skip_libc = false;\n");
5859 try w.writeAll("\n");
5960 try w.writeAll(
......@@ -148,7 +149,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
148149 \\}}
149150 \\
150151 \\
151 , .{top_module.minZigVersion()});
152 , .{if (top_module.minZigVersion()) |sv| u.altSemanticVersion(sv) else null});
152153
153154 try w.writeAll("pub const dirs = struct {\n");
154155 try print_dirs(w, list.items, alloc);
......@@ -179,18 +180,18 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
179180 try w.writeAll("};\n");
180181}
181182
182fn create_lockfile(alloc: std.mem.Allocator, list: *std.ArrayList(zigmod.Module), path: string, dir: std.fs.Dir) !void {
183fn create_lockfile(alloc: std.mem.Allocator, list: *std.ArrayList(zigmod.Module), path: string, dir: nfs.Dir) !void {
183184 const fl = try dir.createFile("zigmod.lock", .{});
184185 defer fl.close();
185186
186187 std.mem.sort(zigmod.Module, list.items, {}, zigmod.Module.lessThan);
187188
188 const wl = fl.writer();
189 const wl = fl;
189190 try wl.writeAll("2\n");
190191 for (list.items) |m| {
191192 if (m.dep) |md| {
192193 if (md.type.isLocal()) continue;
193 const mpath = try std.fs.path.join(alloc, &.{ path, m.clean_path });
194 const mpath = try std.fs.path.joinZ(alloc, &.{ path, m.clean_path });
194195 const version = try md.exact_version(alloc, mpath);
195196 try wl.print("{s} {s} {s}\n", .{ @tagName(md.type), md.path, version });
196197 }
......@@ -290,7 +291,7 @@ fn diff_printchange(comptime testt: string, comptime replacement: string, item:
290291 return false;
291292}
292293
293fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module, alloc: std.mem.Allocator) !void {
294fn print_dirs(w: nfs.File, list: []const zigmod.Module, alloc: std.mem.Allocator) !void {
294295 for (list) |mod| {
295296 if (mod.type == .system_lib or mod.type == .framework) continue;
296297 if (std.mem.eql(u8, &mod.id, &zigmod.Module.ROOT)) {
......@@ -298,15 +299,15 @@ fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module, alloc: std.mem
298299 continue;
299300 }
300301 if (std.mem.eql(u8, mod.clean_path, "../..")) {
301 const cwd_realpath = try std.fs.cwd().realpathAlloc(alloc, ".");
302 try w.print(" pub const _{s} = \"{}\";\n", .{ mod.short_id(), std.zig.fmtEscapes(cwd_realpath) });
302 const cwd_realpath = try nfs.cwd().realpathAlloc(alloc, ".");
303 try w.print(" pub const _{s} = \"{}\";\n", .{ mod.short_id(), u.altStringEscape(cwd_realpath) });
303304 continue;
304305 }
305 try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.short_id(), std.zig.fmtEscapes(mod.clean_path) });
306 try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.short_id(), u.altStringEscape(mod.clean_path) });
306307 }
307308}
308309
309fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void {
310fn print_deps(w: nfs.File, m: zigmod.Module) !void {
310311 try w.writeAll("&[_]*const Package{\n");
311312 for (m.deps) |d| {
312313 if (d.main.len == 0) {
......@@ -320,7 +321,7 @@ fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void {
320321 try w.writeAll("}");
321322}
322323
323fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Module), done: *std.ArrayList(zigmod.Module)) !void {
324fn print_pkg_data_to(w: nfs.File, notdone: *std.ArrayList(zigmod.Module), done: *std.ArrayList(zigmod.Module)) !void {
324325 var len: usize = notdone.items.len;
325326 while (notdone.items.len > 0) {
326327 for (notdone.items, 0..) |mod, i| {
......@@ -359,7 +360,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul
359360 if (mod.c_include_dirs.len > 0) {
360361 try w.writeAll(" .c_include_dirs = &.{");
361362 for (mod.c_include_dirs, 0..) |item, j| {
362 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)});
363 try w.print(" \"{}\"", .{u.altStringEscape(item)});
363364 if (j != mod.c_include_dirs.len - 1) try w.writeAll(",");
364365 }
365366 try w.writeAll(" },\n");
......@@ -367,7 +368,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul
367368 if (mod.c_source_files.len > 0) {
368369 try w.writeAll(" .c_source_files = &.{");
369370 for (mod.c_source_files, 0..) |item, j| {
370 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)});
371 try w.print(" \"{}\"", .{u.altStringEscape(item)});
371372 if (j != mod.c_source_files.len - 1) try w.writeAll(",");
372373 }
373374 try w.writeAll(" },\n");
......@@ -375,7 +376,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul
375376 if (mod.c_source_flags.len > 0) {
376377 try w.writeAll(" .c_source_flags = &.{");
377378 for (mod.c_source_flags, 0..) |item, j| {
378 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)});
379 try w.print(" \"{}\"", .{u.altStringEscape(item)});
379380 if (j != mod.c_source_flags.len - 1) try w.writeAll(",");
380381 }
381382 try w.writeAll(" },\n");
......@@ -384,7 +385,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul
384385 try w.writeAll(" .system_libs = &.{");
385386 for (mod.deps, 0..) |item, j| {
386387 if (!(item.type == .system_lib)) continue;
387 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item.name)});
388 try w.print(" \"{}\"", .{u.altStringEscape(item.name)});
388389 if (j != mod.deps.len - 1) try w.writeAll(",");
389390 }
390391 try w.writeAll(" },\n");
......@@ -393,7 +394,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul
393394 try w.writeAll(" .frameworks = &.{");
394395 for (mod.deps, 0..) |item, j| {
395396 if (!(item.type == .system_lib)) continue;
396 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item.name)});
397 try w.print(" \"{}\"", .{u.altStringEscape(item.name)});
397398 if (j != mod.deps.len - 1) try w.writeAll(",");
398399 }
399400 try w.writeAll(" },\n");
......@@ -422,7 +423,7 @@ fn contains_all(needles: []zigmod.Module, haystack: []const zigmod.Module) bool
422423 return true;
423424}
424425
425fn print_pkgs(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module) !void {
426fn print_pkgs(alloc: std.mem.Allocator, w: nfs.File, m: zigmod.Module) !void {
426427 try w.writeAll("struct {\n");
427428 for (m.deps) |d| {
428429 if (d.main.len == 0) {
......@@ -437,7 +438,7 @@ fn print_pkgs(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module)
437438 try w.writeAll("}");
438439}
439440
440fn print_imports(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module, path: string) !void {
441fn print_imports(alloc: std.mem.Allocator, w: nfs.File, m: zigmod.Module, path: string) !void {
441442 for (m.deps) |d| {
442443 if (d.main.len == 0) {
443444 continue;
......@@ -446,7 +447,7 @@ fn print_imports(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Modu
446447 continue;
447448 }
448449 const ident = try zig_name_from_pkg_name(alloc, d.name);
449 try w.print(" pub const {s} = @import(\"{}/{}/{s}\");\n", .{ ident, std.zig.fmtEscapes(path), std.zig.fmtEscapes(d.clean_path), d.main });
450 try w.print(" pub const {s} = @import(\"{}/{}/{s}\");\n", .{ ident, u.altStringEscape(path), u.altStringEscape(d.clean_path), d.main });
450451 }
451452}
452453
src/cmd/generate.zig+19-18
......@@ -1,6 +1,7 @@
11const std = @import("std");
22const string = []const u8;
33const extras = @import("extras");
4const nfs = @import("nfs");
45
56const zigmod = @import("../lib.zig");
67const u = @import("./../util/funcs.zig");
......@@ -15,7 +16,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
1516 //
1617 const gpa = std.heap.c_allocator;
1718 const cachepath = try u.find_cachepath();
18 const dir = std.fs.cwd();
19 const dir = nfs.cwd();
1920 const should_lock = args.len >= 1 and std.mem.eql(u8, args[0], "--locked");
2021
2122 var options = common.CollectOptions{
......@@ -34,11 +35,11 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
3435 try create_depszig(gpa, cachepath, dir, top_module, list.items, &options);
3536}
3637
37pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.Dir, top_module: zigmod.Module, list: []const zigmod.Module, options: *common.CollectOptions) !void {
38pub fn create_depszig(alloc: std.mem.Allocator, cachepath: [:0]const u8, dir: nfs.Dir, top_module: zigmod.Module, list: []const zigmod.Module, options: *common.CollectOptions) !void {
3839 const f = try dir.createFile("deps.zig", .{});
3940 defer f.close();
4041
41 const w = f.writer();
42 const w = f;
4243 try w.writeAll("// zig fmt: off\n");
4344 try w.writeAll("const std = @import(\"std\");\n");
4445 try w.writeAll("const builtin = @import(\"builtin\");\n");
......@@ -225,7 +226,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
225226 \\}}
226227 \\
227228 \\
228 , .{top_module.minZigVersion()});
229 , .{if (top_module.minZigVersion()) |sv| u.altSemanticVersion(sv) else null});
229230
230231 try w.writeAll("pub const package_data = struct {\n");
231232 var duped = std.ArrayList(zigmod.Module).init(alloc);
......@@ -252,18 +253,18 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
252253 try w.writeAll("};\n");
253254}
254255
255fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module) !void {
256fn print_dirs(w: nfs.File, list: []const zigmod.Module) !void {
256257 for (list) |mod| {
257258 if (mod.type == .system_lib or mod.type == .framework) continue;
258259 if (std.mem.eql(u8, mod.id, "root")) {
259260 try w.writeAll(" pub const _root = \"\";\n");
260261 continue;
261262 }
262 try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.short_id(), std.zig.fmtEscapes(mod.clean_path) });
263 try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.short_id(), u.altStringEscape(mod.clean_path) });
263264 }
264265}
265266
266fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void {
267fn print_deps(w: nfs.File, m: zigmod.Module) !void {
267268 try w.writeAll("[_]*Package{\n");
268269 for (m.deps) |d| {
269270 if (d.main.len == 0) {
......@@ -277,7 +278,7 @@ fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void {
277278 try w.writeAll("}");
278279}
279280
280fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath: string, notdone: *std.ArrayList(zigmod.Module), done: *std.ArrayList(zigmod.Module), options: *common.CollectOptions) !void {
281fn print_pkg_data_to(w: nfs.File, alloc: std.mem.Allocator, cachepath: [:0]const u8, notdone: *std.ArrayList(zigmod.Module), done: *std.ArrayList(zigmod.Module), options: *common.CollectOptions) !void {
281282 var len: usize = notdone.items.len;
282283 while (notdone.items.len > 0) {
283284 for (notdone.items, 0..) |mod, i| {
......@@ -292,13 +293,13 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
292293 switch (mod.type) {
293294 .system_lib, .framework => {},
294295 .local => {},
295 .git => try w.print(" .store = \"/{}/{s}\",\n", .{ std.zig.fmtEscapes(fixed_path), try mod.pin(alloc, cachepath, options) }),
296 .git => try w.print(" .store = \"/{}/{s}\",\n", .{ u.altStringEscape(fixed_path), try mod.pin(alloc, cachepath, options) }),
296297 .hg => @panic("TODO"),
297298 .http => @panic("TODO"),
298299 }
299300 if (mod.main.len > 0 and !std.mem.eql(u8, &mod.id, &zigmod.Module.ROOT)) {
300301 try w.print(" .name = \"{s}\",\n", .{mod.name});
301 try w.print(" .entry = \"/{}/{s}/{s}\",\n", .{ std.zig.fmtEscapes(fixed_path), try mod.pin(alloc, cachepath, options), mod.main });
302 try w.print(" .entry = \"/{}/{s}/{s}\",\n", .{ u.altStringEscape(fixed_path), try mod.pin(alloc, cachepath, options), mod.main });
302303
303304 if (mod.deps.len != 0) {
304305 try w.writeAll(" .deps = &[_]*Package{");
......@@ -313,7 +314,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
313314 if (mod.c_include_dirs.len > 0) {
314315 try w.writeAll(" .c_include_dirs = &.{");
315316 for (mod.c_include_dirs, 0..) |item, j| {
316 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)});
317 try w.print(" \"{}\"", .{u.altStringEscape(item)});
317318 if (j != mod.c_include_dirs.len - 1) try w.writeAll(",");
318319 }
319320 try w.writeAll(" },\n");
......@@ -321,7 +322,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
321322 if (mod.c_source_files.len > 0) {
322323 try w.writeAll(" .c_source_files = &.{");
323324 for (mod.c_source_files, 0..) |item, j| {
324 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)});
325 try w.print(" \"{}\"", .{u.altStringEscape(item)});
325326 if (j != mod.c_source_files.len - 1) try w.writeAll(",");
326327 }
327328 try w.writeAll(" },\n");
......@@ -329,7 +330,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
329330 if (mod.c_source_flags.len > 0) {
330331 try w.writeAll(" .c_source_flags = &.{");
331332 for (mod.c_source_flags, 0..) |item, j| {
332 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)});
333 try w.print(" \"{}\"", .{u.altStringEscape(item)});
333334 if (j != mod.c_source_flags.len - 1) try w.writeAll(",");
334335 }
335336 try w.writeAll(" },\n");
......@@ -338,7 +339,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
338339 try w.writeAll(" .system_libs = &.{");
339340 for (mod.deps, 0..) |item, j| {
340341 if (!(item.type == .system_lib)) continue;
341 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item.name)});
342 try w.print(" \"{}\"", .{u.altStringEscape(item.name)});
342343 if (j != mod.deps.len - 1) try w.writeAll(",");
343344 }
344345 try w.writeAll(" },\n");
......@@ -347,7 +348,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
347348 try w.writeAll(" .frameworks = &.{");
348349 for (mod.deps, 0..) |item, j| {
349350 if (!(item.type == .system_lib)) continue;
350 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item.name)});
351 try w.print(" \"{}\"", .{u.altStringEscape(item.name)});
351352 if (j != mod.deps.len - 1) try w.writeAll(",");
352353 }
353354 try w.writeAll(" },\n");
......@@ -376,7 +377,7 @@ fn contains_all(needles: []zigmod.Module, haystack: []const zigmod.Module) bool
376377 return true;
377378}
378379
379fn print_pkgs(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module) !void {
380fn print_pkgs(alloc: std.mem.Allocator, w: nfs.File, m: zigmod.Module) !void {
380381 try w.writeAll("struct {\n");
381382 for (m.deps) |d| {
382383 if (d.main.len == 0) {
......@@ -391,7 +392,7 @@ fn print_pkgs(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module)
391392 try w.writeAll("}");
392393}
393394
394fn print_imports(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module, path: string) !void {
395fn print_imports(alloc: std.mem.Allocator, w: nfs.File, m: zigmod.Module, path: string) !void {
395396 for (m.deps) |d| {
396397 if (d.main.len == 0) {
397398 continue;
......@@ -400,7 +401,7 @@ fn print_imports(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Modu
400401 continue;
401402 }
402403 const ident = try zig_name_from_pkg_name(alloc, d.name);
403 try w.print(" pub const {s} = @import(\"{}/{}/{s}\");\n", .{ ident, std.zig.fmtEscapes(path), std.zig.fmtEscapes(d.clean_path), d.main });
404 try w.print(" pub const {s} = @import(\"{}/{}/{s}\");\n", .{ ident, u.altStringEscape(path), u.altStringEscape(d.clean_path), d.main });
404405 }
405406}
406407
src/cmd/init.zig+21-19
......@@ -9,6 +9,7 @@ const ini = @import("ini");
99const time = @import("time");
1010const extras = @import("extras");
1111const nio = @import("nio");
12const nfs = @import("nfs");
1213
1314const u = @import("./../util/funcs.zig");
1415const common = @import("./../common.zig");
......@@ -25,9 +26,9 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
2526 std.debug.print("Press ^C at any time to quit.\n", .{});
2627 std.debug.print("\n", .{});
2728
28 const stdout = std.io.getStdOut().writer();
29 const stdin = std.io.getStdIn().reader();
30 const cwd = std.fs.cwd();
29 const stdout = nfs.stdout();
30 const stdin = nfs.stdin();
31 const cwd = nfs.cwd();
3132
3233 const id = try inquirer.answer(stdout, "ID (this gets autogenerated):", string, "{s}", &u.random_string(48));
3334
......@@ -38,12 +39,13 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
3839 const flatname = try gpa.dupe(u8, name);
3940 _ = std.mem.replaceScalar(u8, flatname, '-', '_');
4041
41 const entry = if (ptype == .lib) try inquirer.forString(stdout, stdin, "package entry point:", gpa, u.detct_mainfile(gpa, u.try_index(string, args, 1, ""), null, name) catch |err| switch (err) {
42 const entry_bare = if (ptype == .lib) try inquirer.forString(stdout, stdin, "package entry point:", gpa, u.detct_mainfile(gpa, u.try_index(string, args, 1, ""), .cwd(), name) catch |err| switch (err) {
4243 error.CantFindMain => try std.mem.concat(gpa, u8, &.{ flatname, ".zig" }),
4344 else => |ee| return ee,
4445 }) else null;
46 const entry = if (entry_bare) |ent| try gpa.dupeZ(u8, ent) else null;
4547
46 const maybe_license_text = try detectlicense.detectInDir(gpa, cwd);
48 const maybe_license_text = try detectlicense.detectInDir(gpa, cwd.to_std());
4749 const license = try inquirer.forString(stdout, stdin, "license:", gpa, maybe_license_text);
4850
4951 const description = try inquirer.forString(stdout, stdin, "description:", gpa, null);
......@@ -66,7 +68,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
6668 true => {
6769 const file = try cwd.createFile("zigmod.yml", .{});
6870 defer file.close();
69 const w = file.writer();
71 const w = file;
7072 switch (ptype) {
7173 .exe => try writeExeManifest(w, id, name, license, description),
7274 .lib => try writeLibManifest(w, id, name, license, description, entry.?),
......@@ -98,7 +100,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
98100
99101 const file = try cwd.createFile("LICENSE", .{});
100102 defer file.close();
101 const w = file.writer();
103 const w = file;
102104
103105 // properly format license text to fit within 80 columns
104106 var start: usize = 0;
......@@ -140,12 +142,12 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
140142 const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitignore?", gpa);
141143 if (do) {
142144 const exists = try extras.doesFileExist(null, ".gitignore");
143 const file: std.fs.File = try (if (exists) cwd.openFile(".gitignore", .{ .mode = .read_write }) else cwd.createFile(".gitignore", .{}));
145 const file: nfs.File = try (if (exists) cwd.openFile(".gitignore", .{ .mode = .read_write }) else cwd.createFile(".gitignore", .{}));
144146 defer file.close();
145147 const len = try file.getEndPos();
146148 if (len > 0) try file.seekTo(len - 1);
147 const w = file.writer();
148 if (len > 0 and (try file.reader().readByte()) != '\n') {
149 const w = file;
150 if (len > 0 and (try file.readByte()) != '\n') {
149151 try w.writeAll("\n");
150152 }
151153 if (!exists) try w.writeAll(".zig-cache\n");
......@@ -162,12 +164,12 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
162164 const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitattributes?", gpa);
163165 if (do) {
164166 const exists = try extras.doesFileExist(null, ".gitattributes");
165 const file: std.fs.File = try (if (exists) cwd.openFile(".gitattributes", .{ .mode = .read_write }) else cwd.createFile(".gitattributes", .{}));
167 const file: nfs.File = try (if (exists) cwd.openFile(".gitattributes", .{ .mode = .read_write }) else cwd.createFile(".gitattributes", .{}));
166168 defer file.close();
167169 const len = try file.getEndPos();
168170 if (len > 0) try file.seekTo(len - 1);
169 const w = file.writer();
170 if (len > 0 and (try file.reader().readByte()) != '\n') {
171 const w = file;
172 if (len > 0 and (try file.readByte()) != '\n') {
171173 try w.writeAll("\n");
172174 }
173175 if (!exists) try w.writeAll("* text=auto\n");
......@@ -182,7 +184,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
182184 if (do) {
183185 const file = try cwd.createFile("build.zig", .{});
184186 defer file.close();
185 const w = file.writer();
187 const w = file;
186188 switch (ptype) {
187189 .exe => {
188190 try w.writeAll(
......@@ -249,7 +251,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
249251 if (do) {
250252 const file = try cwd.createFile(entry orelse "main.zig", .{});
251253 defer file.close();
252 const w = file.writer();
254 const w = file;
253255 switch (ptype) {
254256 .exe => {
255257 try w.print(
......@@ -283,7 +285,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
283285 if (do) {
284286 const file = try cwd.createFile("test.zig", .{});
285287 defer file.close();
286 const w = file.writer();
288 const w = file;
287289 try w.print(
288290 \\const std = @import("std");
289291 \\const {s} = @import("{s}");
......@@ -301,7 +303,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
301303 {
302304 const alloc = gpa;
303305 const cachepath = try u.find_cachepath();
304 const dir = std.fs.cwd();
306 const dir = nfs.cwd();
305307
306308 var options = common.CollectOptions{
307309 .log = true,
......@@ -318,7 +320,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
318320 }
319321}
320322
321pub fn writeExeManifest(w: std.fs.File.Writer, id: string, name: string, license: ?string, description: ?string) !void {
323pub fn writeExeManifest(w: nfs.File, id: string, name: string, license: ?string, description: ?string) !void {
322324 try w.print("id: {s}\n", .{id});
323325 try w.print("name: {s}\n", .{name});
324326 if (license) |_| try w.print("license: {s}\n", .{license.?});
......@@ -328,7 +330,7 @@ pub fn writeExeManifest(w: std.fs.File.Writer, id: string, name: string, license
328330 try w.writeAll("root_dependencies:\n");
329331}
330332
331pub fn writeLibManifest(w: std.fs.File.Writer, id: string, name: string, license: string, description: string, entry: string) !void {
333pub fn writeLibManifest(w: nfs.File, id: string, name: string, license: string, description: string, entry: string) !void {
332334 try w.print("id: {s}\n", .{id});
333335 try w.print("name: {s}\n", .{name});
334336 try w.print("main: {s}\n", .{entry});
src/cmd/install.zig+7-6
......@@ -4,6 +4,7 @@ const gpa = std.heap.c_allocator;
44const knownfolders = @import("known-folders");
55const extras = @import("extras");
66const nio = @import("nio");
7const nfs = @import("nfs");
78
89const zigmod = @import("./../lib.zig");
910const u = @import("./../util/funcs.zig");
......@@ -48,8 +49,8 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
4849 .for_build = false,
4950 };
5051 const clean_path = try dep.clean_path(gpa);
51 const cachepath = try std.fs.path.join(gpa, &.{ cache, "zigmod", "deps" });
52 const modpath = try std.fs.path.join(gpa, &.{ cachepath, clean_path });
52 const cachepath = try std.fs.path.joinZ(gpa, &.{ cache, "zigmod", "deps" });
53 const modpath = try std.fs.path.joinZ(gpa, &.{ cachepath, clean_path });
5354 std.log.debug("modpath: {s}", .{modpath});
5455
5556 if (!try extras.doesFolderExist(null, modpath)) {
......@@ -58,14 +59,14 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
5859 try dep.type.update(gpa, modpath, "");
5960 }
6061
61 const moddir = try std.fs.cwd().openDir(modpath, .{});
62 const moddir = try nfs.cwd().openDir(modpath, .{});
6263 const ci = @import("./ci.zig");
6364 try ci.do(gpa, cachepath, moddir);
6465
6566 const modfile = try zigmod.ModFile.from_dir(gpa, moddir, modpath);
66 _ = modfile.min_zig_version orelse u.fail("zigmod manifest requires min_zig_version field", .{});
67 const zigversion = try nio.fmt.allocPrint(gpa, "{s}", .{modfile.yaml.get_string("min_zig_version").?});
68 const zigpath = try std.fs.path.join(gpa, &.{ datapath, "zig", zigversion, "zig" });
67 const zigversion_sv = modfile.min_zig_version orelse u.fail("zigmod manifest requires min_zig_version field", .{});
68 const zigversion = try nio.fmt.allocPrint(gpa, "{s}", .{u.altSemanticVersion(zigversion_sv)});
69 const zigpath = try std.fs.path.joinZ(gpa, &.{ datapath, "zig", zigversion, "zig" });
6970
7071 // zig build
7172 const argv: []const string = &.{
src/cmd/license.zig+6-5
......@@ -4,6 +4,7 @@ const string = []const u8;
44const style = @import("ansi").style;
55const licenses = @import("licenses");
66const extras = @import("extras");
7const nfs = @import("nfs");
78
89const zigmod = @import("../lib.zig");
910const u = @import("./../util/funcs.zig");
......@@ -20,7 +21,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
2021 _ = args;
2122
2223 const cachepath = try u.find_cachepath();
23 const dir = std.fs.cwd();
24 const dir = nfs.cwd();
2425
2526 var options = common.CollectOptions{
2627 .log = false,
......@@ -28,10 +29,10 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
2829 .alloc = gpa,
2930 };
3031
31 try do(cachepath, dir, &options, std.io.getStdOut());
32 try do(cachepath, dir, &options, .stdout());
3233}
3334
34pub fn do(cachepath: string, dir: std.fs.Dir, options: *common.CollectOptions, outfile: std.fs.File) !void {
35pub fn do(cachepath: [:0]const u8, dir: nfs.Dir, options: *common.CollectOptions, outfile: nfs.File) !void {
3536 const top_module = try common.collect_deps_deep(cachepath, dir, options);
3637
3738 var master_list = List.init(gpa);
......@@ -71,8 +72,8 @@ pub fn do(cachepath: string, dir: std.fs.Dir, options: *common.CollectOptions, o
7172 try tracking_list.append(item);
7273 }
7374
74 const istty = outfile.isTty();
75 const writer = outfile.writer();
75 const istty = outfile.isatty();
76 const writer = outfile;
7677 const Bold = if (!istty) "" else style.Bold;
7778 const Faint = if (!istty) "" else style.Faint;
7879 const ResetIntensity = if (!istty) "" else style.ResetIntensity;
src/cmd/sum.zig+3-2
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const gpa = std.heap.c_allocator;
3const nfs = @import("nfs");
34
45const zigmod = @import("../lib.zig");
56const u = @import("./../util/funcs.zig");
......@@ -13,7 +14,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
1314 _ = args;
1415
1516 const cachepath = try u.find_cachepath();
16 const dir = std.fs.cwd();
17 const dir = nfs.cwd();
1718
1819 var options = common.CollectOptions{
1920 .log = false,
......@@ -25,7 +26,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
2526 //
2627 const f = try dir.createFile("zigmod.sum", .{});
2728 defer f.close();
28 const w = f.writer();
29 const w = f;
2930
3031 //
3132 var module_list = std.ArrayList(zigmod.Module).init(gpa);
src/cmd/version.zig+2-1
......@@ -1,6 +1,7 @@
11const std = @import("std");
22const gpa = std.heap.c_allocator;
33const builtin = @import("builtin");
4const nfs = @import("nfs");
45
56const u = @import("./../util/funcs.zig");
67
......@@ -14,7 +15,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
1415 const root = @import("root");
1516 const version = root.build_options.version;
1617
17 var gitversion = u.git_rev_HEAD(gpa, std.fs.cwd()) catch "";
18 var gitversion = u.git_rev_HEAD(gpa, nfs.cwd()) catch "";
1819 gitversion = if (gitversion.len > 0) gitversion[0..9] else gitversion;
1920
2021 const stdout = std.io.getStdOut();
src/cmd/zpm/add.zig+3-2
......@@ -2,6 +2,7 @@ const std = @import("std");
22const gpa = std.heap.c_allocator;
33const zfetch = @import("zfetch");
44const extras = @import("extras");
5const nfs = @import("nfs");
56
67const zigmod = @import("../../lib.zig");
78const u = @import("./../../util/funcs.zig");
......@@ -57,11 +58,11 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
5758 break :blk @intFromEnum(_req.status) == 200;
5859 };
5960
60 _, const file = try zigmod.ModFile.openFile(std.fs.cwd(), .{ .mode = .read_write });
61 _, const file = try zigmod.ModFile.openFile(nfs.cwd(), .{ .mode = .read_write });
6162 defer file.close();
6263 try file.seekTo(try file.getEndPos());
6364
64 const file_w = file.writer();
65 const file_w = file;
6566 try file_w.writeAll("\n");
6667 try file_w.print(" - src: git {s}\n", .{extras.trimSuffix(found.git, ".git")});
6768 if (!(has_zigdotmod or has_zigmodyml)) {
src/common.zig+49-40
......@@ -4,10 +4,13 @@ const builtin = @import("builtin");
44const ansi = @import("ansi");
55const extras = @import("extras");
66const nio = @import("nio");
7const nfs = @import("nfs");
78
89const zigmod = @import("./lib.zig");
910const u = @import("./util/funcs.zig");
1011
12const gpa = std.heap.c_allocator;
13
1114//
1215//
1316
......@@ -24,8 +27,8 @@ pub const CollectOptions = struct {
2427 }
2528};
2629
27pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectOptions) !zigmod.Module {
28 try std.fs.cwd().makePath(cachepath);
30pub fn collect_deps_deep(cachepath: [:0]const u8, mdir: nfs.Dir, options: *CollectOptions) !zigmod.Module {
31 try nfs.cwd().makePath(cachepath);
2932
3033 const m = try zigmod.ModFile.from_dir(options.alloc, mdir, ".");
3134 try options.init();
......@@ -58,8 +61,8 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO
5861 };
5962}
6063
61pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, mdir_path: string, dtype: zigmod.Dep.Type, options: *CollectOptions) anyerror!zigmod.Module {
62 try std.fs.cwd().makePath(cachepath);
64pub fn collect_deps(cachepath: [:0]const u8, mdir: nfs.Dir, mdir_path: string, dtype: zigmod.Dep.Type, options: *CollectOptions) anyerror!zigmod.Module {
65 try nfs.cwd().makePath(cachepath);
6366
6467 const m = try zigmod.ModFile.from_dir(options.alloc, mdir, mdir_path);
6568 var moduledeps = std.ArrayList(zigmod.Module).init(options.alloc);
......@@ -98,9 +101,9 @@ pub fn collect_pkgs(mod: zigmod.Module, list: *std.ArrayList(zigmod.Module)) any
98101 }
99102}
100103
101pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !string {
102 const p = try std.fs.path.join(options.alloc, &.{ cachepath, try d.clean_path(options.alloc) });
103 const pv = try std.fs.path.join(options.alloc, &.{ cachepath, try d.clean_path_v(options.alloc) });
104pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ![:0]const u8 {
105 const p = try std.fs.path.joinZ(options.alloc, &.{ cachepath, try d.clean_path(options.alloc) });
106 const pv = try std.fs.path.joinZ(options.alloc, &.{ cachepath, try d.clean_path_v(options.alloc) });
104107
105108 const nocache = d.type.isLocal();
106109 if (!nocache and extras.containsString(options.already_fetched.items, p)) return p;
......@@ -118,7 +121,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
118121 switch (d.type) {
119122 .local => {
120123 if (!std.mem.endsWith(u8, d.main, ".zig")) {
121 return d.main;
124 return gpa.dupeZ(u8, d.main);
122125 }
123126 return d.path;
124127 },
......@@ -148,11 +151,11 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
148151 u.fail("fetch: git: {s}: {s} {s} does not exist", .{ d.path, @tagName(vers.id), vers.string });
149152 }
150153 if (builtin.os.tag != .windows and vers.id == .commit) {
151 var pvd = try std.fs.cwd().openDir(pv, .{});
154 var pvd = try nfs.cwd().openDir(pv, .{});
152155 defer pvd.close();
153156 try pvd.deleteTree(".git");
154157 }
155 var pvd = try std.fs.cwd().openDir(pv, .{ .iterate = true });
158 var pvd = try nfs.cwd().openDir(pv, .{});
156159 defer pvd.close();
157160 try setTreeReadOnly(pvd, options.alloc);
158161 return pv;
......@@ -185,36 +188,38 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
185188 if (try extras.doesFolderExist(null, pv)) {
186189 return pv;
187190 }
188 const file_path = try std.fs.path.join(options.alloc, &.{ pv, file_name });
191 const file_path = try std.fs.path.joinZ(options.alloc, &.{ pv, file_name });
189192 try d.type.pull(options.alloc, d.path, pv);
190193 if (try u.validate_hash(options.alloc, d.version, file_path)) {
191 try std.fs.cwd().deleteFile(file_path);
192 var pvd = try std.fs.cwd().openDir(pv, .{ .iterate = true });
194 try nfs.cwd().deleteFile(file_path);
195 var pvd = try nfs.cwd().openDir(pv, .{});
193196 defer pvd.close();
194197 try setTreeReadOnly(pvd, options.alloc);
195198 return pv;
196199 }
197 try std.fs.cwd().deleteTree(pv);
200 try nfs.cwd().deleteTree(pv);
198201 u.fail("{s} does not match hash {s}", .{ d.path, d.version });
199202 return p;
200203 }
201204 if (try extras.doesFolderExist(null, p)) {
202 try std.fs.cwd().deleteTree(p);
205 try nfs.cwd().deleteTree(p);
203206 }
204 const file_path = try std.fs.path.resolve(options.alloc, &.{ p, file_name });
207 const file_path_s = try std.fs.path.resolve(options.alloc, &.{ p, file_name });
208 defer gpa.free(file_path_s);
209 const file_path = try gpa.dupeZ(u8, file_path_s);
205210 try d.type.pull(options.alloc, d.path, p);
206 try std.fs.cwd().deleteFile(file_path);
211 try nfs.cwd().deleteFile(file_path);
207212 return p;
208213 },
209214 }
210215}
211216
212pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectOptions) anyerror!?zigmod.Module {
217pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: [:0]const u8, options: *CollectOptions) anyerror!?zigmod.Module {
213218 if (options.lock) |lock| {
214219 for (lock) |item| {
215220 if (std.mem.eql(u8, item[0], try d.clean_path(options.alloc))) {
216221 d.type = std.meta.stringToEnum(zigmod.Dep.Type, item[1]).?;
217 d.path = item[2];
222 d.path = try gpa.dupeZ(u8, item[2]);
218223 d.version = item[3];
219224 break;
220225 }
......@@ -222,7 +227,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
222227 }
223228 if (!d.is_for_this()) return null;
224229 const modpath = try get_modpath(cachepath, d.*, options);
225 const moddir = if (modpath.len == 0) try std.fs.cwd().openDir(cachepath, .{}) else try std.fs.cwd().openDir(modpath, .{});
230 const moddir = if (modpath.len == 0) try nfs.cwd().openDir(cachepath, .{}) else try nfs.cwd().openDir(modpath, .{});
226231
227232 const nocache = d.type.isLocal();
228233 if (!nocache) try options.already_fetched.append(modpath);
......@@ -249,11 +254,14 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
249254 error.ManifestNotFound => {
250255 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0 or d.keep) {
251256 var mod_from = try zigmod.Module.from(options.alloc, d.*, cachepath, options);
252 if (d.type != .local) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..];
257 if (d.type != .local) {
258 const new_clean_path = extras.trimPrefix(modpath, cachepath)[1..];
259 mod_from.clean_path = new_clean_path.ptr[0..new_clean_path.len :0];
260 }
253261 if (mod_from.is_for_this()) return mod_from;
254262 return null;
255263 }
256 const moddirO = try std.fs.cwd().openDir(modpath, .{});
264 const moddirO = try nfs.cwd().openDir(modpath, .{});
257265 const tryname = try u.detect_pkgname(options.alloc, d.name, modpath);
258266 const trymain: ?string = u.detct_mainfile(options.alloc, d.main, moddirO, tryname) catch |err| switch (err) {
259267 error.CantFindMain => null,
......@@ -263,7 +271,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
263271 d.*.name = tryname;
264272 d.*.main = trymain.?;
265273 var mod_from = try zigmod.Module.from(options.alloc, d.*, cachepath, options);
266 if (d.type != .local) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..];
274 if (d.type != .local) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..][0.. :0];
267275 if (mod_from.is_for_this()) return mod_from;
268276 return null;
269277 }
......@@ -274,7 +282,10 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
274282 dd.dep = d.*;
275283 dd.for_build = d.for_build;
276284 const save = dd;
277 if (d.type != .local) dd.clean_path = extras.trimPrefix(modpath, cachepath)[1..];
285 if (d.type != .local) {
286 const new_clean_path = extras.trimPrefix(modpath, cachepath)[1..];
287 dd.clean_path = new_clean_path.ptr[0..new_clean_path.len :0];
288 }
278289 if (std.mem.eql(u8, &dd.id, &zigmod.Dep.EMPTY)) dd.id = u.random_string(48);
279290 if (d.name.len > 0) dd.name = d.name;
280291 if (d.main.len > 0) dd.main = d.main;
......@@ -290,16 +301,16 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
290301 }
291302}
292303
293pub fn gen_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: std.fs.Dir, dirs: []const string) !void {
304pub fn gen_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: nfs.Dir, dirs: []const string) !void {
294305 var map = std.StringHashMap(string).init(alloc);
295306 defer map.deinit();
296307
297308 for (dirs) |dir_path| {
298 const dir = try mdir.openDir(dir_path, .{ .iterate = true });
309 const dir = try mdir.openDirC(dir_path, .{});
299310 var walker = try dir.walk(alloc);
300311 defer walker.deinit();
301312 while (try walker.next()) |p| {
302 if (p.kind == .directory) {
313 if (p.type == .DIR) {
303314 continue;
304315 }
305316 const path = try alloc.dupe(u8, p.path);
......@@ -315,21 +326,19 @@ pub fn gen_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: std.
315326 const destdir = mdir;
316327 const rff = try destdir.createFile(fname, .{});
317328 defer rff.close();
318 const w = rff.writer();
319329 var iter = map.iterator();
320330 while (iter.next()) |item| {
321 try w.print("pub const @\"/{}\" = @embedFile(\"{}\");\n", .{ std.zig.fmtEscapes(item.key_ptr.*), std.zig.fmtEscapes(item.value_ptr.*) });
331 try rff.print("pub const @\"/{}\" = @embedFile(\"{}\");\n", .{ u.altStringEscape(item.key_ptr.*), u.altStringEscape(item.value_ptr.*) });
322332 }
323333}
324334
325pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]string {
335pub fn parse_lockfile(alloc: std.mem.Allocator, dir: nfs.Dir) ![]const [4]string {
326336 var list = std.ArrayList([4]string).init(alloc);
327337 const max = std.math.maxInt(usize);
328 if (!try extras.doesFileExist(dir, "zigmod.lock")) return &[_][4]string{};
338 if (!try extras.doesFileExist(dir.to_std(), "zigmod.lock")) return &[_][4]string{};
329339 var f = try dir.openFile("zigmod.lock", .{});
330340 defer f.close();
331 var br = std.io.bufferedReader(f.reader());
332 const r = br.reader();
341 var r = nio.BufferedReader(4096, nfs.File).init(f);
333342 var i: usize = 0;
334343 var v: usize = 1;
335344 while (try r.readUntilDelimiterOrEofAlloc(alloc, '\n', max)) |line| : (i += 1) {
......@@ -351,7 +360,7 @@ pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]str
351360 var iter = std.mem.splitScalar(u8, line, ' ');
352361 const asdep = zigmod.Dep{
353362 .type = std.meta.stringToEnum(zigmod.Dep.Type, iter.next().?).?,
354 .path = iter.next().?,
363 .path = try gpa.dupeZ(u8, iter.next().?),
355364 .version = iter.next().?,
356365 .id = zigmod.Dep.EMPTY,
357366 .name = "",
......@@ -374,17 +383,17 @@ pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]str
374383 return list.toOwnedSlice();
375384}
376385
377fn setTreeReadOnly(dir: std.fs.Dir, alloc: std.mem.Allocator) !void {
386fn setTreeReadOnly(dir: nfs.Dir, alloc: std.mem.Allocator) !void {
378387 var walker = try dir.walk(alloc);
379388 defer walker.deinit();
380389
381390 while (try walker.next()) |entry| {
382 if (entry.kind != .file) continue;
391 if (entry.type != .REG) continue;
383392 var file = try dir.openFile(entry.path, .{});
384393 defer file.close();
385 var metadata = try file.metadata();
386 var perms = metadata.permissions();
387 perms.setReadOnly(true);
388 try file.setPermissions(perms);
394 const stat = try file.stat();
395 var mode = stat.mode;
396 mode |= ~@as(nfs.File.Mode, 0o222);
397 try file.chmod(mode);
389398 }
390399}
src/util/dep.zig+6-6
......@@ -14,7 +14,7 @@ pub const Dep = struct {
1414 const Self = @This();
1515
1616 type: Type,
17 path: string,
17 path: [:0]const u8,
1818 id: [48]u8,
1919 name: string,
2020 main: string,
......@@ -33,17 +33,17 @@ pub const Dep = struct {
3333
3434 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) ![:0]const u8 {
3737 if (self.type == .local) {
3838 return self.path;
3939 }
40 var p = self.path;
40 var p: string = self.path;
4141 p = extras.trimPrefix(p, "http://");
4242 p = extras.trimPrefix(p, "https://");
4343 p = extras.trimPrefix(p, "git://");
4444 p = extras.trimSuffix(p, ".git");
45 p = try std.mem.join(alloc, "/", &.{ @tagName(self.type), p });
46 return p;
45 const np = try std.mem.joinZ(alloc, "/", &.{ @tagName(self.type), p });
46 return np;
4747 }
4848
4949 pub fn clean_path_v(self: Dep, alloc: std.mem.Allocator) !string {
......@@ -65,7 +65,7 @@ pub const Dep = struct {
6565 return true;
6666 }
6767
68 pub fn exact_version(self: Dep, alloc: std.mem.Allocator, dpath: string) !string {
68 pub fn exact_version(self: Dep, alloc: std.mem.Allocator, dpath: [:0]const u8) !string {
6969 if (self.version.len == 0) {
7070 return try self.type.exact_version(alloc, dpath);
7171 }
src/util/dep_type.zig+5-4
......@@ -1,6 +1,7 @@
11const std = @import("std");
22const string = []const u8;
33const nio = @import("nio");
4const nfs = @import("nfs");
45
56const u = @import("./funcs.zig");
67
......@@ -17,7 +18,7 @@ pub const DepType = enum {
1718 http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
1819
1920 // zig fmt: on
20 pub fn pull(self: DepType, alloc: std.mem.Allocator, rpath: string, dpath: string) !void {
21 pub fn pull(self: DepType, alloc: std.mem.Allocator, rpath: [:0]const u8, dpath: [:0]const u8) !void {
2122 switch (self) {
2223 .local => {},
2324 .system_lib => {},
......@@ -29,7 +30,7 @@ pub const DepType = enum {
2930 u.assert((try u.run_cmd(alloc, null, &.{ "hg", "clone", rpath, dpath })) == 0, "hg clone {s} failed", .{rpath});
3031 },
3132 .http => {
32 try std.fs.cwd().makePath(dpath);
33 try nfs.cwd().makePath(dpath);
3334 u.assert((try u.run_cmd(alloc, dpath, &.{ "wget", rpath })) == 0, "wget {s} failed", .{rpath});
3435 const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").? + 1 ..];
3536 if (std.mem.endsWith(u8, f, ".zip")) {
......@@ -62,8 +63,8 @@ pub const DepType = enum {
6263 }
6364 }
6465
65 pub fn exact_version(self: DepType, alloc: std.mem.Allocator, mpath: string) !string {
66 var mdir = try std.fs.cwd().openDir(mpath, .{});
66 pub fn exact_version(self: DepType, alloc: std.mem.Allocator, mpath: [:0]const u8) !string {
67 var mdir = try nfs.cwd().openDir(mpath, .{});
6768 defer mdir.close();
6869 return switch (self) {
6970 .local => "",
src/util/funcs.zig+57-22
......@@ -44,10 +44,10 @@ pub fn split(alloc: std.mem.Allocator, in: string, delim: u8) ![]string {
4444 return list.toOwnedSlice();
4545}
4646
47pub fn file_list(alloc: std.mem.Allocator, dpath: string) ![]const string {
48 var dir = try std.fs.cwd().openDir(dpath, .{ .iterate = true });
47pub fn file_list(alloc: std.mem.Allocator, dpath: [:0]const u8) ![]const string {
48 var dir = try nfs.cwd().openDir(dpath, .{});
4949 defer dir.close();
50 return try extras.fileList(alloc, dir);
50 return try extras.fileList(alloc, dir.to_std());
5151}
5252
5353pub fn run_cmd_raw(alloc: std.mem.Allocator, dir: ?string, args: []const string) !std.process.Child.RunResult {
......@@ -121,11 +121,11 @@ pub const HashFn = enum {
121121 sha512,
122122};
123123
124pub fn validate_hash(alloc: std.mem.Allocator, input: string, file_path: string) !bool {
124pub fn validate_hash(alloc: std.mem.Allocator, input: string, file_path: [:0]const u8) !bool {
125125 const hash = parse_split(HashFn, '-').do(input) catch return false;
126 const file = try std.fs.cwd().openFile(file_path, .{});
126 const file = try nfs.cwd().openFile(file_path, .{});
127127 defer file.close();
128 const data = try file.reader().readAllAlloc(alloc, gb);
128 const data = try file.readAllAlloc(alloc, gb);
129129 const expected = hash.string;
130130 const actual = switch (hash.id) {
131131 .blake3 => &try do_hash(std.crypto.hash.Blake3, data),
......@@ -144,9 +144,8 @@ pub fn do_hash(comptime algo: type, data: string) ![algo.digest_length * 2]u8 {
144144}
145145
146146/// Returns the result of running `git rev-parse HEAD`
147pub fn git_rev_HEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !string {
148 const ndir: nfs.Dir = .{ .fd = @enumFromInt(dir.fd) };
149 var dirg = try ndir.openDir(".git", .{});
147pub fn git_rev_HEAD(alloc: std.mem.Allocator, dir: nfs.Dir) !string {
148 var dirg = try dir.openDir(".git", .{});
150149 defer dirg.close();
151150 const commitid = try git.getHEAD(alloc, dirg);
152151 return if (commitid) |_| commitid.?.id else error.NotAGitRepo;
......@@ -158,9 +157,9 @@ pub fn slice(comptime T: type, input: []const T, from: usize, to: usize) []const
158157 return input[f..t];
159158}
160159
161pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: string) !string {
160pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: [:0]const u8) !string {
162161 if (override.len > 0) return override;
163 const dirO = if (dir.len == 0) std.fs.cwd() else try std.fs.cwd().openDir(dir, .{});
162 const dirO = if (dir.len == 0) nfs.cwd() else try nfs.cwd().openDir(dir, .{});
164163 const dpath = try dirO.realpathAlloc(gpa, ".");
165164 const splitP = try split(alloc, dpath, std.fs.path.sep);
166165 var name = splitP[splitP.len - 1];
......@@ -169,28 +168,28 @@ pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: string) !
169168 return name;
170169}
171170
172pub fn detct_mainfile(alloc: std.mem.Allocator, override: string, dir: ?std.fs.Dir, name: string) !string {
171pub fn detct_mainfile(alloc: std.mem.Allocator, override: string, dir: nfs.Dir, name: string) !string {
173172 if (override.len > 0) {
174 if (try extras.doesFileExist(dir, override)) {
173 if (try extras.doesFileExist(dir.to_std(), override)) {
175174 if (std.mem.endsWith(u8, override, ".zig")) {
176175 return override;
177176 }
178177 }
179178 }
180179 const namedotzig = try std.mem.concat(alloc, u8, &.{ name, ".zig" });
181 if (try extras.doesFileExist(dir, namedotzig)) {
180 if (try extras.doesFileExist(dir.to_std(), namedotzig)) {
182181 return namedotzig;
183182 }
184 if (try extras.doesFileExist(dir, "lib.zig")) {
183 if (try extras.doesFileExist(dir.to_std(), "lib.zig")) {
185184 return "lib.zig";
186185 }
187 if (try extras.doesFileExist(dir, "main.zig")) {
186 if (try extras.doesFileExist(dir.to_std(), "main.zig")) {
188187 return "main.zig";
189188 }
190 if (try extras.doesFileExist(dir, try std.fs.path.join(alloc, &.{ "src", "lib.zig" }))) {
189 if (try extras.doesFileExist(dir.to_std(), try std.fs.path.join(alloc, &.{ "src", "lib.zig" }))) {
191190 return "src/lib.zig";
192191 }
193 if (try extras.doesFileExist(dir, try std.fs.path.join(alloc, &.{ "src", "main.zig" }))) {
192 if (try extras.doesFileExist(dir.to_std(), try std.fs.path.join(alloc, &.{ "src", "main.zig" }))) {
194193 return "src/main.zig";
195194 }
196195 return error.CantFindMain;
......@@ -214,12 +213,48 @@ pub fn indexOfAfter(haystack: string, needle: u8, after: usize) ?usize {
214213 return null;
215214}
216215
217pub fn find_cachepath() !string {
218 const haystack = try std.fs.cwd().realpathAlloc(gpa, ".");
216pub fn find_cachepath() ![:0]const u8 {
217 const haystack = try nfs.cwd().realpathAlloc(gpa, ".");
219218 const needle = "/.zigmod/deps";
220219
221220 if (std.mem.indexOf(u8, haystack, needle)) |index| {
222 return haystack[0 .. index + needle.len];
221 return gpa.dupeZ(u8, haystack[0 .. index + needle.len]);
223222 }
224 return try std.fs.path.join(gpa, &.{ haystack, ".zigmod", "deps" });
223 return try std.fs.path.joinZ(gpa, &.{ haystack, ".zigmod", "deps" });
225224}
225
226pub fn altStringEscape(data: []const u8) StringEscape {
227 return .{ .data = data };
228}
229const StringEscape = struct {
230 data: []const u8,
231
232 pub fn nprint(self: StringEscape, writer: anytype) !void {
233 for (self.data) |c| switch (c) {
234 '\n' => try writer.writeAll("\\n"),
235 '\r' => try writer.writeAll("\\r"),
236 '\t' => try writer.writeAll("\\t"),
237 '\\' => try writer.writeAll("\\\\"),
238 '"' => try writer.writeAll("\\\""),
239 '\'' => try writer.writeAll(&.{'\''}),
240 ' ', '!', '#'...'&', '('...'[', ']'...'~' => try writer.writeAll(&.{c}),
241 else => {
242 try writer.print("\\x{x:0>2}", .{c});
243 // try writer.printInt(c, 16, .lower, .{ .width = 2, .fill = '0' });
244 },
245 };
246 }
247};
248
249pub fn altSemanticVersion(data: std.SemanticVersion) SemanticVersion {
250 return .{ .data = data };
251}
252const SemanticVersion = struct {
253 data: std.SemanticVersion,
254
255 pub fn nprint(self: SemanticVersion, writer: anytype) !void {
256 try writer.print("{d}.{d}.{d}", .{ self.data.major, self.data.minor, self.data.patch });
257 if (self.data.pre) |pre| try writer.print("-{s}", .{pre});
258 if (self.data.build) |build| try writer.print("+{s}", .{build});
259 }
260};
src/util/modfile.zig+10-8
......@@ -4,6 +4,7 @@ const yaml = @import("yaml");
44const extras = @import("extras");
55const root = @import("root");
66const build_options = root.build_options;
7const nfs = @import("nfs");
78
89const zigmod = @import("../lib.zig");
910const u = @import("funcs.zig");
......@@ -11,6 +12,7 @@ const u = @import("funcs.zig");
1112//
1213//
1314
15const gpa = std.heap.c_allocator;
1416const b = 1;
1517const kb = b * 1024;
1618const mb = kb * 1024;
......@@ -32,10 +34,10 @@ pub const ModFile = struct {
3234 builddeps: []zigmod.Dep,
3335 min_zig_version: ?std.SemanticVersion,
3436
35 pub fn openFile(dir: std.fs.Dir, ops: std.fs.File.OpenFlags) !struct { string, std.fs.File } {
37 pub fn openFile(dir: nfs.Dir, ops: nfs.Dir.OpenFileFlags) !struct { string, nfs.File } {
3638 return .{ "zig.mod", dir.openFile("zig.mod", ops) catch |err| switch (err) {
37 error.FileNotFound => return .{ "zigmod.yml", dir.openFile("zigmod.yml", ops) catch |err2| switch (err2) {
38 error.FileNotFound => return error.ManifestNotFound,
39 error.ENOENT => return .{ "zigmod.yml", dir.openFile("zigmod.yml", ops) catch |err2| switch (err2) {
40 error.ENOENT => return error.ManifestNotFound,
3941 else => |e2| return e2,
4042 } },
4143 else => |e| return e,
......@@ -43,13 +45,13 @@ pub const ModFile = struct {
4345 }
4446
4547 pub fn init(alloc: std.mem.Allocator) !Self {
46 return try from_dir(alloc, std.fs.cwd(), ".");
48 return try from_dir(alloc, nfs.cwd(), ".");
4749 }
4850
49 pub fn from_dir(alloc: std.mem.Allocator, dir: std.fs.Dir, dir_path: string) !Self {
51 pub fn from_dir(alloc: std.mem.Allocator, dir: nfs.Dir, dir_path: string) !Self {
5052 const file_path, const file = try openFile(dir, .{});
5153 defer file.close();
52 const input = try file.reader().readAllAlloc(alloc, mb);
54 const input = try file.readAllAlloc(alloc, mb);
5355 const doc = try yaml.parse(alloc, input);
5456 return from_mapping(alloc, doc.mapping, dir_path, file_path);
5557 }
......@@ -101,14 +103,14 @@ pub const ModFile = struct {
101103 if (dep_seq != .sequence) continue;
102104 for (dep_seq.sequence) |item| {
103105 var dtype: string = undefined;
104 var path: string = undefined;
106 var path: [:0]const u8 = undefined;
105107 var version: ?string = null;
106108 var main = item.mapping.get_string("main") orelse "";
107109
108110 if (item.mapping.get("src")) |val| {
109111 var src_iter = std.mem.tokenizeScalar(u8, val.string, ' ');
110112 dtype = src_iter.next().?;
111 path = src_iter.next().?;
113 path = try gpa.dupeZ(u8, src_iter.next().?);
112114 if (src_iter.next()) |dver| {
113115 version = dver;
114116 }
src/util/module.zig+9-8
......@@ -4,6 +4,7 @@ const builtin = @import("builtin");
44const yaml = @import("yaml");
55const extras = @import("extras");
66const nio = @import("nio");
7const nfs = @import("nfs");
78
89const zigmod = @import("../lib.zig");
910const u = @import("funcs.zig");
......@@ -24,14 +25,14 @@ pub const Module = struct {
2425 except_os: []const string = &.{},
2526 yaml: ?yaml.Mapping,
2627 deps: []Module,
27 clean_path: string,
28 clean_path: [:0]const u8,
2829 dep: ?zigmod.Dep,
2930 for_build: bool = false,
3031 min_zig_version: ?std.SemanticVersion,
3132
3233 pub const ROOT: [48]u8 = ("root" ++ (" " ** 44)).*;
3334
34 pub fn from(alloc: std.mem.Allocator, dep: zigmod.Dep, cachepath: string, options: *common.CollectOptions) !Module {
35 pub fn from(alloc: std.mem.Allocator, dep: zigmod.Dep, cachepath: [:0]const u8, options: *common.CollectOptions) !Module {
3536 var moddeps = std.ArrayList(Module).init(alloc);
3637 errdefer moddeps.deinit();
3738
......@@ -68,7 +69,7 @@ pub const Module = struct {
6869 }
6970
7071 pub fn get_hash(self: Module, alloc: std.mem.Allocator, cdpath: string) !string {
71 const file_list_1 = try u.file_list(alloc, try std.mem.concat(alloc, u8, &.{ cdpath, "/", self.clean_path }));
72 const file_list_1 = try u.file_list(alloc, try std.mem.concatWithSentinel(alloc, u8, &.{ cdpath, "/", self.clean_path }, 0));
7273
7374 var file_list_2 = std.ArrayList(string).init(alloc);
7475 errdefer file_list_2.deinit();
......@@ -88,10 +89,10 @@ pub const Module = struct {
8889
8990 var h = std.crypto.hash.Blake3.init(.{});
9091 for (file_list_2.items) |item| {
91 const abs_path = try std.fs.path.join(alloc, &.{ cdpath, self.clean_path, item });
92 const file = try std.fs.cwd().openFile(abs_path, .{});
92 const abs_path = try std.fs.path.joinZ(alloc, &.{ cdpath, self.clean_path, item });
93 const file = try nfs.cwd().openFile(abs_path, .{});
9394 defer file.close();
94 const input = try file.reader().readAllAlloc(alloc, u.mb * 100);
95 const input = try file.readAllAlloc(alloc, u.mb * 100);
9596 h.update(input);
9697 }
9798 var out: [32]u8 = undefined;
......@@ -164,13 +165,13 @@ pub const Module = struct {
164165 return false;
165166 }
166167
167 pub fn pin(self: Module, alloc: std.mem.Allocator, cachepath: string, options: *common.CollectOptions) !string {
168 pub fn pin(self: Module, alloc: std.mem.Allocator, cachepath: [:0]const u8, options: *common.CollectOptions) !string {
168169 return switch (self.type) {
169170 .local => "",
170171 .system_lib => "",
171172 .framework => "",
172173 else => |sub| {
173 var cdir = try std.fs.cwd().openDir(cachepath, .{});
174 var cdir = try nfs.cwd().openDir(cachepath, .{});
174175 defer cdir.close();
175176 var mdir = try cdir.openDir(self.clean_path, .{});
176177 defer mdir.close();
zigmod.lock+5-5
......@@ -5,7 +5,7 @@ git https://github.com/nektro/iguanaTLS commit-3450aaf3ca47986540e2b0258c2affc45
55git https://github.com/nektro/zfetch commit-40d141bf7db81f05a83cce5f2edc4b14e41a5c34
66git https://github.com/nektro/zig-ansi commit-5f89211a749aef6bf518889c0467ceb24825c055
77git https://github.com/nektro/zig-detect-license commit-a1a066da88dab50873a56f0349dc12dc76542077
8git https://github.com/nektro/zig-extras commit-c2c581aa6a38438dd9ed8da0f59019691c5dd45d
8git https://github.com/nektro/zig-extras commit-b3457b31a1d1ea2c19c5d0b007c903d3e80add40
99git https://github.com/nektro/zig-git commit-2b3f83cd341764f979969603e4f77e62f353b6a3
1010git https://github.com/nektro/zig-inquirer commit-4cddefa42744d61067567b0b36b5d2bb376e5ae3
1111git https://github.com/nektro/zig-intrusive-parser commit-a31b480914d15f3d13cdfb586aac950c73beebdd
......@@ -13,13 +13,13 @@ git https://github.com/nektro/zig-json commit-428aa8a29e370fdb2e6739d5676b1de415
1313git https://github.com/nektro/zig-leven commit-618eddde4ffbc6d34100e4bc6aa654d41161537a
1414git https://github.com/nektro/zig-licenses commit-16cef5e32b3f8bbcf1064c599615290a720b6547
1515git https://github.com/nektro/zig-licenses-text commit-ba0f00dfb23d28c301e4b54d0a278def2c38dc7b
16git https://github.com/nektro/zig-nfs commit-18b00c5c5d25e230ff4f3ea07fadb2a1d54a773d
16git https://github.com/nektro/zig-nfs commit-c855473c8bd15dd24a4e8b6911b7e006062004ba
1717git https://github.com/nektro/zig-nio commit-c1da2e8a31858880eb3e4cfcf12de0a865617623
18git https://github.com/nektro/zig-sys-darwin commit-c5c1b35492224b0ed8d2570c8e71702947b1e400
19git https://github.com/nektro/zig-sys-linux commit-9edefde5fcf96894b6aa4ab60241940bba65debf
18git https://github.com/nektro/zig-sys-darwin commit-3265d1f06418eb0360d753c12116310a14b97bde
19git https://github.com/nektro/zig-sys-linux commit-f0b155d3627f8c19868be1b2f15d71cda908b575
2020git https://github.com/nektro/zig-time commit-0f4db4c980146e4a3fc86a9a9070452a25ff9317
2121git https://github.com/nektro/zig-tracer commit-3a5fdea4ffd387a53ac2a42fb503557cdbe20696
22git https://github.com/nektro/zig-yaml commit-b1ebd056b9afaaa719cb55359c610455ffe04499
22git https://github.com/nektro/zig-yaml commit-00e899bec815bc2b49c6e5a72a7cfeeda673e133
2323git https://github.com/truemedian/hzzp commit-ab212bd208f0eb54d85861679677c5e3dc9bb543
2424git https://github.com/madler/zlib tag-v1.3.2
2525git https://github.com/yaml/libyaml tag-0.2.5