From 773b09ff745c30c0e02b6d4717e0da9cb10b2978 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sat, 30 May 2026 02:17:38 -0700 Subject: [PATCH] use nfs more --- deps.zig | 30 +++++++-------- src/cmd/ci.zig | 5 ++- src/cmd/explain.zig | 3 +- src/cmd/fetch.zig | 45 +++++++++++----------- src/cmd/generate.zig | 37 +++++++++--------- src/cmd/init.zig | 40 ++++++++++--------- src/cmd/install.zig | 13 ++++--- src/cmd/license.zig | 11 +++--- src/cmd/sum.zig | 5 ++- src/cmd/version.zig | 3 +- src/cmd/zpm/add.zig | 5 ++- src/common.zig | 89 ++++++++++++++++++++++++------------------- src/util/dep.zig | 12 +++--- src/util/dep_type.zig | 9 +++-- src/util/funcs.zig | 79 +++++++++++++++++++++++++++----------- src/util/modfile.zig | 18 +++++---- src/util/module.zig | 17 +++++---- zigmod.lock | 10 ++--- 18 files changed, 245 insertions(+), 186 deletions(-) diff --git a/deps.zig b/deps.zig index 086fdd0f3131ff9e32f53a4f3d9443fe824e267f..a486b07566341ac9b198d516f67a2a7b177fe6fd 100644 --- a/deps.zig +++ b/deps.zig @@ -60,7 +60,7 @@ pub fn fetch(exe: *std.Build.Step.Compile) *std.Build.Step { step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zfetch", "40d141bf7db81f05a83cce5f2edc4b14e41a5c34").step); step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-ansi", "5f89211a749aef6bf518889c0467ceb24825c055").step); step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-detect-license", "a1a066da88dab50873a56f0349dc12dc76542077").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-extras", "c2c581aa6a38438dd9ed8da0f59019691c5dd45d").step); + step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-extras", "b3457b31a1d1ea2c19c5d0b007c903d3e80add40").step); step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-git", "2b3f83cd341764f979969603e4f77e62f353b6a3").step); step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-inquirer", "4cddefa42744d61067567b0b36b5d2bb376e5ae3").step); 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 { step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-leven", "618eddde4ffbc6d34100e4bc6aa654d41161537a").step); step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses", "16cef5e32b3f8bbcf1064c599615290a720b6547").step); step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses-text", "ba0f00dfb23d28c301e4b54d0a278def2c38dc7b").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-nfs", "18b00c5c5d25e230ff4f3ea07fadb2a1d54a773d").step); + step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-nfs", "c855473c8bd15dd24a4e8b6911b7e006062004ba").step); step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-nio", "c1da2e8a31858880eb3e4cfcf12de0a865617623").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-sys-darwin", "c5c1b35492224b0ed8d2570c8e71702947b1e400").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-sys-linux", "9edefde5fcf96894b6aa4ab60241940bba65debf").step); + step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-sys-darwin", "3265d1f06418eb0360d753c12116310a14b97bde").step); + step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-sys-linux", "f0b155d3627f8c19868be1b2f15d71cda908b575").step); step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-time", "0f4db4c980146e4a3fc86a9a9070452a25ff9317").step); step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-tracer", "3a5fdea4ffd387a53ac2a42fb503557cdbe20696").step); - step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-yaml", "b1ebd056b9afaaa719cb55359c610455ffe04499").step); + step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-yaml", "00e899bec815bc2b49c6e5a72a7cfeeda673e133").step); step.dependOn(&GitExactStep.create(b, "https://github.com/truemedian/hzzp", "ab212bd208f0eb54d85861679677c5e3dc9bb543").step); step.dependOn(&GitExactStep.create(b, "https://github.com/madler/zlib", "da607da739fa6047df13e66a2af6b8bec7c2a498").step); step.dependOn(&GitExactStep.create(b, "https://github.com/yaml/libyaml", "2c891fc7a770e8ba2fec34fc6b545c672beb37e6").step); @@ -210,9 +210,9 @@ pub const package_data = struct { .entry = "/git/github.com/nektro/zig-ansi/5f89211a749aef6bf518889c0467ceb24825c055/src/lib.zig", }; pub var _f7dubzb7cyqe = Package{ - .store = "/git/github.com/nektro/zig-extras/c2c581aa6a38438dd9ed8da0f59019691c5dd45d", + .store = "/git/github.com/nektro/zig-extras/b3457b31a1d1ea2c19c5d0b007c903d3e80add40", .name = "extras", - .entry = "/git/github.com/nektro/zig-extras/c2c581aa6a38438dd9ed8da0f59019691c5dd45d/src/lib.zig", + .entry = "/git/github.com/nektro/zig-extras/b3457b31a1d1ea2c19c5d0b007c903d3e80add40/src/lib.zig", }; pub var _c1xirp1ota5p = Package{ .store = "/git/github.com/nektro/zig-inquirer/4cddefa42744d61067567b0b36b5d2bb376e5ae3", @@ -231,14 +231,14 @@ pub const package_data = struct { .entry = "/git/github.com/nektro/zig-licenses/16cef5e32b3f8bbcf1064c599615290a720b6547/src/lib.zig", }; pub var _73bukkeci2u6 = Package{ - .store = "/git/github.com/nektro/zig-sys-darwin/c5c1b35492224b0ed8d2570c8e71702947b1e400", + .store = "/git/github.com/nektro/zig-sys-darwin/3265d1f06418eb0360d753c12116310a14b97bde", .name = "sys-darwin", - .entry = "/git/github.com/nektro/zig-sys-darwin/c5c1b35492224b0ed8d2570c8e71702947b1e400/sys_darwin.zig", + .entry = "/git/github.com/nektro/zig-sys-darwin/3265d1f06418eb0360d753c12116310a14b97bde/sys_darwin.zig", }; pub var _h7tv7ayhffak = Package{ - .store = "/git/github.com/nektro/zig-sys-linux/9edefde5fcf96894b6aa4ab60241940bba65debf", + .store = "/git/github.com/nektro/zig-sys-linux/f0b155d3627f8c19868be1b2f15d71cda908b575", .name = "sys-linux", - .entry = "/git/github.com/nektro/zig-sys-linux/9edefde5fcf96894b6aa4ab60241940bba65debf/mod.zig", + .entry = "/git/github.com/nektro/zig-sys-linux/f0b155d3627f8c19868be1b2f15d71cda908b575/mod.zig", .deps = &[_]*Package{ }, .system_libs = &.{ "c" }, }; @@ -261,9 +261,9 @@ pub const package_data = struct { .deps = &[_]*Package{ &_f7dubzb7cyqe, &_h7tv7ayhffak, &_73bukkeci2u6 }, }; pub var _vph9l0hxpeze = Package{ - .store = "/git/github.com/nektro/zig-nfs/18b00c5c5d25e230ff4f3ea07fadb2a1d54a773d", + .store = "/git/github.com/nektro/zig-nfs/c855473c8bd15dd24a4e8b6911b7e006062004ba", .name = "nfs", - .entry = "/git/github.com/nektro/zig-nfs/18b00c5c5d25e230ff4f3ea07fadb2a1d54a773d/nfs.zig", + .entry = "/git/github.com/nektro/zig-nfs/c855473c8bd15dd24a4e8b6911b7e006062004ba/nfs.zig", .deps = &[_]*Package{ &_h7tv7ayhffak, &_kscsl0145t7x, &_iecwp4b3bsfm, &_73bukkeci2u6 }, }; pub var _ede2wygpe1iy = Package{ @@ -297,9 +297,9 @@ pub const package_data = struct { .deps = &[_]*Package{ &_pt88y5d80m25, &_96h80ezrvj7i }, }; pub var _g982zq6e8wsv = Package{ - .store = "/git/github.com/nektro/zig-yaml/b1ebd056b9afaaa719cb55359c610455ffe04499", + .store = "/git/github.com/nektro/zig-yaml/00e899bec815bc2b49c6e5a72a7cfeeda673e133", .name = "yaml", - .entry = "/git/github.com/nektro/zig-yaml/b1ebd056b9afaaa719cb55359c610455ffe04499/yaml.zig", + .entry = "/git/github.com/nektro/zig-yaml/00e899bec815bc2b49c6e5a72a7cfeeda673e133/yaml.zig", .deps = &[_]*Package{ &_8mdbh0zuneb0 }, }; pub var _9k24gimke1an = Package{ diff --git a/src/cmd/ci.zig b/src/cmd/ci.zig index 7407d971792ab674f2bb0a48b0faa4d4e80b2704..3a97b06288f65b9a9eedcd758988abefee9f60a6 100644 --- a/src/cmd/ci.zig +++ b/src/cmd/ci.zig @@ -1,5 +1,6 @@ const std = @import("std"); const string = []const u8; +const nfs = @import("nfs"); const zigmod = @import("../lib.zig"); const u = @import("./../util/funcs.zig"); @@ -14,11 +15,11 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { const gpa = std.heap.c_allocator; const cachepath = try u.find_cachepath(); - const dir = std.fs.cwd(); + const dir = nfs.cwd(); try do(gpa, cachepath, dir); } -pub fn do(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.Dir) !void { +pub fn do(alloc: std.mem.Allocator, cachepath: [:0]const u8, dir: nfs.Dir) !void { var options = common.CollectOptions{ .log = true, .update = false, diff --git a/src/cmd/explain.zig b/src/cmd/explain.zig index 25f119dfb36decbfbcb6d26527ce30e4da9418ed..7d9e3154989c0d67617ddefc71d31b31581e9766 100644 --- a/src/cmd/explain.zig +++ b/src/cmd/explain.zig @@ -1,6 +1,7 @@ const std = @import("std"); const builtin = @import("builtin"); const extras = @import("extras"); +const nfs = @import("nfs"); const zigmod = @import("../lib.zig"); const u = @import("./../util/funcs.zig"); @@ -14,7 +15,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { const gpa = std.heap.c_allocator; const cachepath = try u.find_cachepath(); - const dir = std.fs.cwd(); + const dir = nfs.cwd(); const should_lock = args.len >= 1 and std.mem.eql(u8, args[0], "--locked"); const format_i: usize = if (should_lock) 1 else 0; const Format = enum { diff --git a/src/cmd/fetch.zig b/src/cmd/fetch.zig index 5416698d69b54b32ecfd084ae086c7ea691209d8..d53d51e429d5959ce0980ce571148533523aece6 100644 --- a/src/cmd/fetch.zig +++ b/src/cmd/fetch.zig @@ -2,6 +2,7 @@ const std = @import("std"); const string = []const u8; const ansi = @import("ansi"); const extras = @import("extras"); +const nfs = @import("nfs"); const zigmod = @import("../lib.zig"); const u = @import("./../util/funcs.zig"); @@ -16,7 +17,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { const gpa = std.heap.c_allocator; const cachepath = try u.find_cachepath(); - const dir = std.fs.cwd(); + const dir = nfs.cwd(); const should_update = !(args.len >= 1 and std.mem.eql(u8, args[0], "--no-update")); var options = common.CollectOptions{ @@ -43,17 +44,17 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { try license.do(cachepath, dir, &options, outfile); } -pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.Dir, top_module: zigmod.Module, list: *std.ArrayList(zigmod.Module)) !void { +pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: nfs.Dir, top_module: zigmod.Module, list: *std.ArrayList(zigmod.Module)) !void { const f = try dir.createFile("deps.zig", .{}); defer f.close(); - const w = f.writer(); + const w = f; try w.writeAll("// zig fmt: off\n"); try w.writeAll("const std = @import(\"std\");\n"); try w.writeAll("const builtin = @import(\"builtin\");\n"); try w.writeAll("const string = []const u8;\n"); try w.writeAll("\n"); - try w.print("pub const cache = \"{}\";\n", .{std.zig.fmtEscapes(cachepath)}); + try w.print("pub const cache = \"{}\";\n", .{u.altStringEscape(cachepath)}); try w.writeAll("pub var skip_libc = false;\n"); try w.writeAll("\n"); try w.writeAll( @@ -148,7 +149,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D \\}} \\ \\ - , .{top_module.minZigVersion()}); + , .{if (top_module.minZigVersion()) |sv| u.altSemanticVersion(sv) else null}); try w.writeAll("pub const dirs = struct {\n"); 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 try w.writeAll("};\n"); } -fn create_lockfile(alloc: std.mem.Allocator, list: *std.ArrayList(zigmod.Module), path: string, dir: std.fs.Dir) !void { +fn create_lockfile(alloc: std.mem.Allocator, list: *std.ArrayList(zigmod.Module), path: string, dir: nfs.Dir) !void { const fl = try dir.createFile("zigmod.lock", .{}); defer fl.close(); std.mem.sort(zigmod.Module, list.items, {}, zigmod.Module.lessThan); - const wl = fl.writer(); + const wl = fl; try wl.writeAll("2\n"); for (list.items) |m| { if (m.dep) |md| { if (md.type.isLocal()) continue; - const mpath = try std.fs.path.join(alloc, &.{ path, m.clean_path }); + const mpath = try std.fs.path.joinZ(alloc, &.{ path, m.clean_path }); const version = try md.exact_version(alloc, mpath); try wl.print("{s} {s} {s}\n", .{ @tagName(md.type), md.path, version }); } @@ -290,7 +291,7 @@ fn diff_printchange(comptime testt: string, comptime replacement: string, item: return false; } -fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module, alloc: std.mem.Allocator) !void { +fn print_dirs(w: nfs.File, list: []const zigmod.Module, alloc: std.mem.Allocator) !void { for (list) |mod| { if (mod.type == .system_lib or mod.type == .framework) continue; 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 continue; } if (std.mem.eql(u8, mod.clean_path, "../..")) { - const cwd_realpath = try std.fs.cwd().realpathAlloc(alloc, "."); - try w.print(" pub const _{s} = \"{}\";\n", .{ mod.short_id(), std.zig.fmtEscapes(cwd_realpath) }); + const cwd_realpath = try nfs.cwd().realpathAlloc(alloc, "."); + try w.print(" pub const _{s} = \"{}\";\n", .{ mod.short_id(), u.altStringEscape(cwd_realpath) }); continue; } - try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.short_id(), std.zig.fmtEscapes(mod.clean_path) }); + try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.short_id(), u.altStringEscape(mod.clean_path) }); } } -fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void { +fn print_deps(w: nfs.File, m: zigmod.Module) !void { try w.writeAll("&[_]*const Package{\n"); for (m.deps) |d| { if (d.main.len == 0) { @@ -320,7 +321,7 @@ fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void { try w.writeAll("}"); } -fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Module), done: *std.ArrayList(zigmod.Module)) !void { +fn print_pkg_data_to(w: nfs.File, notdone: *std.ArrayList(zigmod.Module), done: *std.ArrayList(zigmod.Module)) !void { var len: usize = notdone.items.len; while (notdone.items.len > 0) { 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 if (mod.c_include_dirs.len > 0) { try w.writeAll(" .c_include_dirs = &.{"); for (mod.c_include_dirs, 0..) |item, j| { - try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)}); + try w.print(" \"{}\"", .{u.altStringEscape(item)}); if (j != mod.c_include_dirs.len - 1) try w.writeAll(","); } try w.writeAll(" },\n"); @@ -367,7 +368,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul if (mod.c_source_files.len > 0) { try w.writeAll(" .c_source_files = &.{"); for (mod.c_source_files, 0..) |item, j| { - try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)}); + try w.print(" \"{}\"", .{u.altStringEscape(item)}); if (j != mod.c_source_files.len - 1) try w.writeAll(","); } try w.writeAll(" },\n"); @@ -375,7 +376,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul if (mod.c_source_flags.len > 0) { try w.writeAll(" .c_source_flags = &.{"); for (mod.c_source_flags, 0..) |item, j| { - try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)}); + try w.print(" \"{}\"", .{u.altStringEscape(item)}); if (j != mod.c_source_flags.len - 1) try w.writeAll(","); } try w.writeAll(" },\n"); @@ -384,7 +385,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul try w.writeAll(" .system_libs = &.{"); for (mod.deps, 0..) |item, j| { if (!(item.type == .system_lib)) continue; - try w.print(" \"{}\"", .{std.zig.fmtEscapes(item.name)}); + try w.print(" \"{}\"", .{u.altStringEscape(item.name)}); if (j != mod.deps.len - 1) try w.writeAll(","); } try w.writeAll(" },\n"); @@ -393,7 +394,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul try w.writeAll(" .frameworks = &.{"); for (mod.deps, 0..) |item, j| { if (!(item.type == .system_lib)) continue; - try w.print(" \"{}\"", .{std.zig.fmtEscapes(item.name)}); + try w.print(" \"{}\"", .{u.altStringEscape(item.name)}); if (j != mod.deps.len - 1) try w.writeAll(","); } try w.writeAll(" },\n"); @@ -422,7 +423,7 @@ fn contains_all(needles: []zigmod.Module, haystack: []const zigmod.Module) bool return true; } -fn print_pkgs(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module) !void { +fn print_pkgs(alloc: std.mem.Allocator, w: nfs.File, m: zigmod.Module) !void { try w.writeAll("struct {\n"); for (m.deps) |d| { if (d.main.len == 0) { @@ -437,7 +438,7 @@ fn print_pkgs(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module) try w.writeAll("}"); } -fn print_imports(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module, path: string) !void { +fn print_imports(alloc: std.mem.Allocator, w: nfs.File, m: zigmod.Module, path: string) !void { for (m.deps) |d| { if (d.main.len == 0) { continue; @@ -446,7 +447,7 @@ fn print_imports(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Modu continue; } const ident = try zig_name_from_pkg_name(alloc, d.name); - try w.print(" pub const {s} = @import(\"{}/{}/{s}\");\n", .{ ident, std.zig.fmtEscapes(path), std.zig.fmtEscapes(d.clean_path), d.main }); + try w.print(" pub const {s} = @import(\"{}/{}/{s}\");\n", .{ ident, u.altStringEscape(path), u.altStringEscape(d.clean_path), d.main }); } } diff --git a/src/cmd/generate.zig b/src/cmd/generate.zig index ad6a6a23958bc9aa8255a772620fc74a89cf57f9..192fabb8d7630087c9d5f1aaee75b07097abf2c4 100644 --- a/src/cmd/generate.zig +++ b/src/cmd/generate.zig @@ -1,6 +1,7 @@ const std = @import("std"); const string = []const u8; const extras = @import("extras"); +const nfs = @import("nfs"); const zigmod = @import("../lib.zig"); const u = @import("./../util/funcs.zig"); @@ -15,7 +16,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { // const gpa = std.heap.c_allocator; const cachepath = try u.find_cachepath(); - const dir = std.fs.cwd(); + const dir = nfs.cwd(); const should_lock = args.len >= 1 and std.mem.eql(u8, args[0], "--locked"); var options = common.CollectOptions{ @@ -34,11 +35,11 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { try create_depszig(gpa, cachepath, dir, top_module, list.items, &options); } -pub 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 { +pub 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 { const f = try dir.createFile("deps.zig", .{}); defer f.close(); - const w = f.writer(); + const w = f; try w.writeAll("// zig fmt: off\n"); try w.writeAll("const std = @import(\"std\");\n"); 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 \\}} \\ \\ - , .{top_module.minZigVersion()}); + , .{if (top_module.minZigVersion()) |sv| u.altSemanticVersion(sv) else null}); try w.writeAll("pub const package_data = struct {\n"); 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 try w.writeAll("};\n"); } -fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module) !void { +fn print_dirs(w: nfs.File, list: []const zigmod.Module) !void { for (list) |mod| { if (mod.type == .system_lib or mod.type == .framework) continue; if (std.mem.eql(u8, mod.id, "root")) { try w.writeAll(" pub const _root = \"\";\n"); continue; } - try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.short_id(), std.zig.fmtEscapes(mod.clean_path) }); + try w.print(" pub const _{s} = cache ++ \"/{}\";\n", .{ mod.short_id(), u.altStringEscape(mod.clean_path) }); } } -fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void { +fn print_deps(w: nfs.File, m: zigmod.Module) !void { try w.writeAll("[_]*Package{\n"); for (m.deps) |d| { if (d.main.len == 0) { @@ -277,7 +278,7 @@ fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void { try w.writeAll("}"); } -fn 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 { +fn 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 { var len: usize = notdone.items.len; while (notdone.items.len > 0) { 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: switch (mod.type) { .system_lib, .framework => {}, .local => {}, - .git => try w.print(" .store = \"/{}/{s}\",\n", .{ std.zig.fmtEscapes(fixed_path), try mod.pin(alloc, cachepath, options) }), + .git => try w.print(" .store = \"/{}/{s}\",\n", .{ u.altStringEscape(fixed_path), try mod.pin(alloc, cachepath, options) }), .hg => @panic("TODO"), .http => @panic("TODO"), } if (mod.main.len > 0 and !std.mem.eql(u8, &mod.id, &zigmod.Module.ROOT)) { try w.print(" .name = \"{s}\",\n", .{mod.name}); - try w.print(" .entry = \"/{}/{s}/{s}\",\n", .{ std.zig.fmtEscapes(fixed_path), try mod.pin(alloc, cachepath, options), mod.main }); + try w.print(" .entry = \"/{}/{s}/{s}\",\n", .{ u.altStringEscape(fixed_path), try mod.pin(alloc, cachepath, options), mod.main }); if (mod.deps.len != 0) { try w.writeAll(" .deps = &[_]*Package{"); @@ -313,7 +314,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath: if (mod.c_include_dirs.len > 0) { try w.writeAll(" .c_include_dirs = &.{"); for (mod.c_include_dirs, 0..) |item, j| { - try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)}); + try w.print(" \"{}\"", .{u.altStringEscape(item)}); if (j != mod.c_include_dirs.len - 1) try w.writeAll(","); } try w.writeAll(" },\n"); @@ -321,7 +322,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath: if (mod.c_source_files.len > 0) { try w.writeAll(" .c_source_files = &.{"); for (mod.c_source_files, 0..) |item, j| { - try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)}); + try w.print(" \"{}\"", .{u.altStringEscape(item)}); if (j != mod.c_source_files.len - 1) try w.writeAll(","); } try w.writeAll(" },\n"); @@ -329,7 +330,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath: if (mod.c_source_flags.len > 0) { try w.writeAll(" .c_source_flags = &.{"); for (mod.c_source_flags, 0..) |item, j| { - try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)}); + try w.print(" \"{}\"", .{u.altStringEscape(item)}); if (j != mod.c_source_flags.len - 1) try w.writeAll(","); } try w.writeAll(" },\n"); @@ -338,7 +339,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath: try w.writeAll(" .system_libs = &.{"); for (mod.deps, 0..) |item, j| { if (!(item.type == .system_lib)) continue; - try w.print(" \"{}\"", .{std.zig.fmtEscapes(item.name)}); + try w.print(" \"{}\"", .{u.altStringEscape(item.name)}); if (j != mod.deps.len - 1) try w.writeAll(","); } try w.writeAll(" },\n"); @@ -347,7 +348,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath: try w.writeAll(" .frameworks = &.{"); for (mod.deps, 0..) |item, j| { if (!(item.type == .system_lib)) continue; - try w.print(" \"{}\"", .{std.zig.fmtEscapes(item.name)}); + try w.print(" \"{}\"", .{u.altStringEscape(item.name)}); if (j != mod.deps.len - 1) try w.writeAll(","); } try w.writeAll(" },\n"); @@ -376,7 +377,7 @@ fn contains_all(needles: []zigmod.Module, haystack: []const zigmod.Module) bool return true; } -fn print_pkgs(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module) !void { +fn print_pkgs(alloc: std.mem.Allocator, w: nfs.File, m: zigmod.Module) !void { try w.writeAll("struct {\n"); for (m.deps) |d| { if (d.main.len == 0) { @@ -391,7 +392,7 @@ fn print_pkgs(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module) try w.writeAll("}"); } -fn print_imports(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module, path: string) !void { +fn print_imports(alloc: std.mem.Allocator, w: nfs.File, m: zigmod.Module, path: string) !void { for (m.deps) |d| { if (d.main.len == 0) { continue; @@ -400,7 +401,7 @@ fn print_imports(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Modu continue; } const ident = try zig_name_from_pkg_name(alloc, d.name); - try w.print(" pub const {s} = @import(\"{}/{}/{s}\");\n", .{ ident, std.zig.fmtEscapes(path), std.zig.fmtEscapes(d.clean_path), d.main }); + try w.print(" pub const {s} = @import(\"{}/{}/{s}\");\n", .{ ident, u.altStringEscape(path), u.altStringEscape(d.clean_path), d.main }); } } diff --git a/src/cmd/init.zig b/src/cmd/init.zig index cb17597d3cabb6193d447c7138de4a8ba2f7d124..465e8bfee63686f297871c7d3a1f9381638b2f92 100644 --- a/src/cmd/init.zig +++ b/src/cmd/init.zig @@ -9,6 +9,7 @@ const ini = @import("ini"); const time = @import("time"); const extras = @import("extras"); const nio = @import("nio"); +const nfs = @import("nfs"); const u = @import("./../util/funcs.zig"); const common = @import("./../common.zig"); @@ -25,9 +26,9 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { std.debug.print("Press ^C at any time to quit.\n", .{}); std.debug.print("\n", .{}); - const stdout = std.io.getStdOut().writer(); - const stdin = std.io.getStdIn().reader(); - const cwd = std.fs.cwd(); + const stdout = nfs.stdout(); + const stdin = nfs.stdin(); + const cwd = nfs.cwd(); const id = try inquirer.answer(stdout, "ID (this gets autogenerated):", string, "{s}", &u.random_string(48)); @@ -38,12 +39,13 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { const flatname = try gpa.dupe(u8, name); _ = std.mem.replaceScalar(u8, flatname, '-', '_'); - 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) { + 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) { error.CantFindMain => try std.mem.concat(gpa, u8, &.{ flatname, ".zig" }), else => |ee| return ee, }) else null; + const entry = if (entry_bare) |ent| try gpa.dupeZ(u8, ent) else null; - const maybe_license_text = try detectlicense.detectInDir(gpa, cwd); + const maybe_license_text = try detectlicense.detectInDir(gpa, cwd.to_std()); const license = try inquirer.forString(stdout, stdin, "license:", gpa, maybe_license_text); 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 { true => { const file = try cwd.createFile("zigmod.yml", .{}); defer file.close(); - const w = file.writer(); + const w = file; switch (ptype) { .exe => try writeExeManifest(w, id, name, license, description), .lib => try writeLibManifest(w, id, name, license, description, entry.?), @@ -98,7 +100,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { const file = try cwd.createFile("LICENSE", .{}); defer file.close(); - const w = file.writer(); + const w = file; // properly format license text to fit within 80 columns var start: usize = 0; @@ -140,12 +142,12 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitignore?", gpa); if (do) { const exists = try extras.doesFileExist(null, ".gitignore"); - const file: std.fs.File = try (if (exists) cwd.openFile(".gitignore", .{ .mode = .read_write }) else cwd.createFile(".gitignore", .{})); + const file: nfs.File = try (if (exists) cwd.openFile(".gitignore", .{ .mode = .read_write }) else cwd.createFile(".gitignore", .{})); defer file.close(); const len = try file.getEndPos(); if (len > 0) try file.seekTo(len - 1); - const w = file.writer(); - if (len > 0 and (try file.reader().readByte()) != '\n') { + const w = file; + if (len > 0 and (try file.readByte()) != '\n') { try w.writeAll("\n"); } if (!exists) try w.writeAll(".zig-cache\n"); @@ -162,12 +164,12 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitattributes?", gpa); if (do) { const exists = try extras.doesFileExist(null, ".gitattributes"); - const file: std.fs.File = try (if (exists) cwd.openFile(".gitattributes", .{ .mode = .read_write }) else cwd.createFile(".gitattributes", .{})); + const file: nfs.File = try (if (exists) cwd.openFile(".gitattributes", .{ .mode = .read_write }) else cwd.createFile(".gitattributes", .{})); defer file.close(); const len = try file.getEndPos(); if (len > 0) try file.seekTo(len - 1); - const w = file.writer(); - if (len > 0 and (try file.reader().readByte()) != '\n') { + const w = file; + if (len > 0 and (try file.readByte()) != '\n') { try w.writeAll("\n"); } if (!exists) try w.writeAll("* text=auto\n"); @@ -182,7 +184,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { if (do) { const file = try cwd.createFile("build.zig", .{}); defer file.close(); - const w = file.writer(); + const w = file; switch (ptype) { .exe => { try w.writeAll( @@ -249,7 +251,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { if (do) { const file = try cwd.createFile(entry orelse "main.zig", .{}); defer file.close(); - const w = file.writer(); + const w = file; switch (ptype) { .exe => { try w.print( @@ -283,7 +285,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { if (do) { const file = try cwd.createFile("test.zig", .{}); defer file.close(); - const w = file.writer(); + const w = file; try w.print( \\const std = @import("std"); \\const {s} = @import("{s}"); @@ -301,7 +303,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { { const alloc = gpa; const cachepath = try u.find_cachepath(); - const dir = std.fs.cwd(); + const dir = nfs.cwd(); var options = common.CollectOptions{ .log = true, @@ -318,7 +320,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { } } -pub fn writeExeManifest(w: std.fs.File.Writer, id: string, name: string, license: ?string, description: ?string) !void { +pub fn writeExeManifest(w: nfs.File, id: string, name: string, license: ?string, description: ?string) !void { try w.print("id: {s}\n", .{id}); try w.print("name: {s}\n", .{name}); 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 try w.writeAll("root_dependencies:\n"); } -pub fn writeLibManifest(w: std.fs.File.Writer, id: string, name: string, license: string, description: string, entry: string) !void { +pub fn writeLibManifest(w: nfs.File, id: string, name: string, license: string, description: string, entry: string) !void { try w.print("id: {s}\n", .{id}); try w.print("name: {s}\n", .{name}); try w.print("main: {s}\n", .{entry}); diff --git a/src/cmd/install.zig b/src/cmd/install.zig index 93343b462d9ec6a461cc000445629371d691c511..977ac2dea7946ff6120cdbabf5333e07f63d25ff 100644 --- a/src/cmd/install.zig +++ b/src/cmd/install.zig @@ -4,6 +4,7 @@ const gpa = std.heap.c_allocator; const knownfolders = @import("known-folders"); const extras = @import("extras"); const nio = @import("nio"); +const nfs = @import("nfs"); const zigmod = @import("./../lib.zig"); const u = @import("./../util/funcs.zig"); @@ -48,8 +49,8 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { .for_build = false, }; const clean_path = try dep.clean_path(gpa); - const cachepath = try std.fs.path.join(gpa, &.{ cache, "zigmod", "deps" }); - const modpath = try std.fs.path.join(gpa, &.{ cachepath, clean_path }); + const cachepath = try std.fs.path.joinZ(gpa, &.{ cache, "zigmod", "deps" }); + const modpath = try std.fs.path.joinZ(gpa, &.{ cachepath, clean_path }); std.log.debug("modpath: {s}", .{modpath}); if (!try extras.doesFolderExist(null, modpath)) { @@ -58,14 +59,14 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { try dep.type.update(gpa, modpath, ""); } - const moddir = try std.fs.cwd().openDir(modpath, .{}); + const moddir = try nfs.cwd().openDir(modpath, .{}); const ci = @import("./ci.zig"); try ci.do(gpa, cachepath, moddir); const modfile = try zigmod.ModFile.from_dir(gpa, moddir, modpath); - _ = modfile.min_zig_version orelse u.fail("zigmod manifest requires min_zig_version field", .{}); - const zigversion = try nio.fmt.allocPrint(gpa, "{s}", .{modfile.yaml.get_string("min_zig_version").?}); - const zigpath = try std.fs.path.join(gpa, &.{ datapath, "zig", zigversion, "zig" }); + const zigversion_sv = modfile.min_zig_version orelse u.fail("zigmod manifest requires min_zig_version field", .{}); + const zigversion = try nio.fmt.allocPrint(gpa, "{s}", .{u.altSemanticVersion(zigversion_sv)}); + const zigpath = try std.fs.path.joinZ(gpa, &.{ datapath, "zig", zigversion, "zig" }); // zig build const argv: []const string = &.{ diff --git a/src/cmd/license.zig b/src/cmd/license.zig index 0d0efc7b26aace12c9f3aea2fb3f088ed4f76cd6..6455b3b962382b3acb55433a54c6605e3a15da2d 100644 --- a/src/cmd/license.zig +++ b/src/cmd/license.zig @@ -4,6 +4,7 @@ const string = []const u8; const style = @import("ansi").style; const licenses = @import("licenses"); const extras = @import("extras"); +const nfs = @import("nfs"); const zigmod = @import("../lib.zig"); const u = @import("./../util/funcs.zig"); @@ -20,7 +21,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { _ = args; const cachepath = try u.find_cachepath(); - const dir = std.fs.cwd(); + const dir = nfs.cwd(); var options = common.CollectOptions{ .log = false, @@ -28,10 +29,10 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { .alloc = gpa, }; - try do(cachepath, dir, &options, std.io.getStdOut()); + try do(cachepath, dir, &options, .stdout()); } -pub fn do(cachepath: string, dir: std.fs.Dir, options: *common.CollectOptions, outfile: std.fs.File) !void { +pub fn do(cachepath: [:0]const u8, dir: nfs.Dir, options: *common.CollectOptions, outfile: nfs.File) !void { const top_module = try common.collect_deps_deep(cachepath, dir, options); var master_list = List.init(gpa); @@ -71,8 +72,8 @@ pub fn do(cachepath: string, dir: std.fs.Dir, options: *common.CollectOptions, o try tracking_list.append(item); } - const istty = outfile.isTty(); - const writer = outfile.writer(); + const istty = outfile.isatty(); + const writer = outfile; const Bold = if (!istty) "" else style.Bold; const Faint = if (!istty) "" else style.Faint; const ResetIntensity = if (!istty) "" else style.ResetIntensity; diff --git a/src/cmd/sum.zig b/src/cmd/sum.zig index a34255e3d41054be15a2167e1b6a7f123db9bc65..6bab3665e5cafaa407c4a7d1f3505f743e97e651 100644 --- a/src/cmd/sum.zig +++ b/src/cmd/sum.zig @@ -1,5 +1,6 @@ const std = @import("std"); const gpa = std.heap.c_allocator; +const nfs = @import("nfs"); const zigmod = @import("../lib.zig"); const u = @import("./../util/funcs.zig"); @@ -13,7 +14,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { _ = args; const cachepath = try u.find_cachepath(); - const dir = std.fs.cwd(); + const dir = nfs.cwd(); var options = common.CollectOptions{ .log = false, @@ -25,7 +26,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { // const f = try dir.createFile("zigmod.sum", .{}); defer f.close(); - const w = f.writer(); + const w = f; // var module_list = std.ArrayList(zigmod.Module).init(gpa); diff --git a/src/cmd/version.zig b/src/cmd/version.zig index ff1d38ebddf1d556cf2a7c3985916a7d38644cd9..cafb1f06ef7a3ead344a73fa316f054d32b0f99a 100644 --- a/src/cmd/version.zig +++ b/src/cmd/version.zig @@ -1,6 +1,7 @@ const std = @import("std"); const gpa = std.heap.c_allocator; const builtin = @import("builtin"); +const nfs = @import("nfs"); const u = @import("./../util/funcs.zig"); @@ -14,7 +15,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { const root = @import("root"); const version = root.build_options.version; - var gitversion = u.git_rev_HEAD(gpa, std.fs.cwd()) catch ""; + var gitversion = u.git_rev_HEAD(gpa, nfs.cwd()) catch ""; gitversion = if (gitversion.len > 0) gitversion[0..9] else gitversion; const stdout = std.io.getStdOut(); diff --git a/src/cmd/zpm/add.zig b/src/cmd/zpm/add.zig index 088fb3993bfea0cd48372ebdb060cd61ce53d9c6..01c500580a12dd5a59088c77774efe5ddfcb88cb 100644 --- a/src/cmd/zpm/add.zig +++ b/src/cmd/zpm/add.zig @@ -2,6 +2,7 @@ const std = @import("std"); const gpa = std.heap.c_allocator; const zfetch = @import("zfetch"); const extras = @import("extras"); +const nfs = @import("nfs"); const zigmod = @import("../../lib.zig"); const u = @import("./../../util/funcs.zig"); @@ -57,11 +58,11 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void { break :blk @intFromEnum(_req.status) == 200; }; - _, const file = try zigmod.ModFile.openFile(std.fs.cwd(), .{ .mode = .read_write }); + _, const file = try zigmod.ModFile.openFile(nfs.cwd(), .{ .mode = .read_write }); defer file.close(); try file.seekTo(try file.getEndPos()); - const file_w = file.writer(); + const file_w = file; try file_w.writeAll("\n"); try file_w.print(" - src: git {s}\n", .{extras.trimSuffix(found.git, ".git")}); if (!(has_zigdotmod or has_zigmodyml)) { diff --git a/src/common.zig b/src/common.zig index 5a71967814bba864f69ec70fc4c336073d629dc2..588c405ae9cd97ad69e8994bb13f5b5296e93ae4 100644 --- a/src/common.zig +++ b/src/common.zig @@ -4,10 +4,13 @@ const builtin = @import("builtin"); const ansi = @import("ansi"); const extras = @import("extras"); const nio = @import("nio"); +const nfs = @import("nfs"); const zigmod = @import("./lib.zig"); const u = @import("./util/funcs.zig"); +const gpa = std.heap.c_allocator; + // // @@ -24,8 +27,8 @@ pub const CollectOptions = struct { } }; -pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectOptions) !zigmod.Module { - try std.fs.cwd().makePath(cachepath); +pub fn collect_deps_deep(cachepath: [:0]const u8, mdir: nfs.Dir, options: *CollectOptions) !zigmod.Module { + try nfs.cwd().makePath(cachepath); const m = try zigmod.ModFile.from_dir(options.alloc, mdir, "."); try options.init(); @@ -58,8 +61,8 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO }; } -pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, mdir_path: string, dtype: zigmod.Dep.Type, options: *CollectOptions) anyerror!zigmod.Module { - try std.fs.cwd().makePath(cachepath); +pub fn collect_deps(cachepath: [:0]const u8, mdir: nfs.Dir, mdir_path: string, dtype: zigmod.Dep.Type, options: *CollectOptions) anyerror!zigmod.Module { + try nfs.cwd().makePath(cachepath); const m = try zigmod.ModFile.from_dir(options.alloc, mdir, mdir_path); 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 } } -pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !string { - const p = try std.fs.path.join(options.alloc, &.{ cachepath, try d.clean_path(options.alloc) }); - const pv = try std.fs.path.join(options.alloc, &.{ cachepath, try d.clean_path_v(options.alloc) }); +pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ![:0]const u8 { + const p = try std.fs.path.joinZ(options.alloc, &.{ cachepath, try d.clean_path(options.alloc) }); + const pv = try std.fs.path.joinZ(options.alloc, &.{ cachepath, try d.clean_path_v(options.alloc) }); const nocache = d.type.isLocal(); 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) ! switch (d.type) { .local => { if (!std.mem.endsWith(u8, d.main, ".zig")) { - return d.main; + return gpa.dupeZ(u8, d.main); } return d.path; }, @@ -148,11 +151,11 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! u.fail("fetch: git: {s}: {s} {s} does not exist", .{ d.path, @tagName(vers.id), vers.string }); } if (builtin.os.tag != .windows and vers.id == .commit) { - var pvd = try std.fs.cwd().openDir(pv, .{}); + var pvd = try nfs.cwd().openDir(pv, .{}); defer pvd.close(); try pvd.deleteTree(".git"); } - var pvd = try std.fs.cwd().openDir(pv, .{ .iterate = true }); + var pvd = try nfs.cwd().openDir(pv, .{}); defer pvd.close(); try setTreeReadOnly(pvd, options.alloc); return pv; @@ -185,36 +188,38 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! if (try extras.doesFolderExist(null, pv)) { return pv; } - const file_path = try std.fs.path.join(options.alloc, &.{ pv, file_name }); + const file_path = try std.fs.path.joinZ(options.alloc, &.{ pv, file_name }); try d.type.pull(options.alloc, d.path, pv); if (try u.validate_hash(options.alloc, d.version, file_path)) { - try std.fs.cwd().deleteFile(file_path); - var pvd = try std.fs.cwd().openDir(pv, .{ .iterate = true }); + try nfs.cwd().deleteFile(file_path); + var pvd = try nfs.cwd().openDir(pv, .{}); defer pvd.close(); try setTreeReadOnly(pvd, options.alloc); return pv; } - try std.fs.cwd().deleteTree(pv); + try nfs.cwd().deleteTree(pv); u.fail("{s} does not match hash {s}", .{ d.path, d.version }); return p; } if (try extras.doesFolderExist(null, p)) { - try std.fs.cwd().deleteTree(p); + try nfs.cwd().deleteTree(p); } - const file_path = try std.fs.path.resolve(options.alloc, &.{ p, file_name }); + const file_path_s = try std.fs.path.resolve(options.alloc, &.{ p, file_name }); + defer gpa.free(file_path_s); + const file_path = try gpa.dupeZ(u8, file_path_s); try d.type.pull(options.alloc, d.path, p); - try std.fs.cwd().deleteFile(file_path); + try nfs.cwd().deleteFile(file_path); return p; }, } } -pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectOptions) anyerror!?zigmod.Module { +pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: [:0]const u8, options: *CollectOptions) anyerror!?zigmod.Module { if (options.lock) |lock| { for (lock) |item| { if (std.mem.eql(u8, item[0], try d.clean_path(options.alloc))) { d.type = std.meta.stringToEnum(zigmod.Dep.Type, item[1]).?; - d.path = item[2]; + d.path = try gpa.dupeZ(u8, item[2]); d.version = item[3]; break; } @@ -222,7 +227,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO } if (!d.is_for_this()) return null; const modpath = try get_modpath(cachepath, d.*, options); - const moddir = if (modpath.len == 0) try std.fs.cwd().openDir(cachepath, .{}) else try std.fs.cwd().openDir(modpath, .{}); + const moddir = if (modpath.len == 0) try nfs.cwd().openDir(cachepath, .{}) else try nfs.cwd().openDir(modpath, .{}); const nocache = d.type.isLocal(); 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 error.ManifestNotFound => { if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0 or d.keep) { var mod_from = try zigmod.Module.from(options.alloc, d.*, cachepath, options); - if (d.type != .local) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; + if (d.type != .local) { + const new_clean_path = extras.trimPrefix(modpath, cachepath)[1..]; + mod_from.clean_path = new_clean_path.ptr[0..new_clean_path.len :0]; + } if (mod_from.is_for_this()) return mod_from; return null; } - const moddirO = try std.fs.cwd().openDir(modpath, .{}); + const moddirO = try nfs.cwd().openDir(modpath, .{}); const tryname = try u.detect_pkgname(options.alloc, d.name, modpath); const trymain: ?string = u.detct_mainfile(options.alloc, d.main, moddirO, tryname) catch |err| switch (err) { error.CantFindMain => null, @@ -263,7 +271,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO d.*.name = tryname; d.*.main = trymain.?; var mod_from = try zigmod.Module.from(options.alloc, d.*, cachepath, options); - if (d.type != .local) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; + if (d.type != .local) mod_from.clean_path = extras.trimPrefix(modpath, cachepath)[1..][0.. :0]; if (mod_from.is_for_this()) return mod_from; return null; } @@ -274,7 +282,10 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO dd.dep = d.*; dd.for_build = d.for_build; const save = dd; - if (d.type != .local) dd.clean_path = extras.trimPrefix(modpath, cachepath)[1..]; + if (d.type != .local) { + const new_clean_path = extras.trimPrefix(modpath, cachepath)[1..]; + dd.clean_path = new_clean_path.ptr[0..new_clean_path.len :0]; + } if (std.mem.eql(u8, &dd.id, &zigmod.Dep.EMPTY)) dd.id = u.random_string(48); if (d.name.len > 0) dd.name = d.name; 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 } } -pub fn gen_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: std.fs.Dir, dirs: []const string) !void { +pub fn gen_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: nfs.Dir, dirs: []const string) !void { var map = std.StringHashMap(string).init(alloc); defer map.deinit(); for (dirs) |dir_path| { - const dir = try mdir.openDir(dir_path, .{ .iterate = true }); + const dir = try mdir.openDirC(dir_path, .{}); var walker = try dir.walk(alloc); defer walker.deinit(); while (try walker.next()) |p| { - if (p.kind == .directory) { + if (p.type == .DIR) { continue; } 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. const destdir = mdir; const rff = try destdir.createFile(fname, .{}); defer rff.close(); - const w = rff.writer(); var iter = map.iterator(); while (iter.next()) |item| { - try w.print("pub const @\"/{}\" = @embedFile(\"{}\");\n", .{ std.zig.fmtEscapes(item.key_ptr.*), std.zig.fmtEscapes(item.value_ptr.*) }); + try rff.print("pub const @\"/{}\" = @embedFile(\"{}\");\n", .{ u.altStringEscape(item.key_ptr.*), u.altStringEscape(item.value_ptr.*) }); } } -pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]string { +pub fn parse_lockfile(alloc: std.mem.Allocator, dir: nfs.Dir) ![]const [4]string { var list = std.ArrayList([4]string).init(alloc); const max = std.math.maxInt(usize); - if (!try extras.doesFileExist(dir, "zigmod.lock")) return &[_][4]string{}; + if (!try extras.doesFileExist(dir.to_std(), "zigmod.lock")) return &[_][4]string{}; var f = try dir.openFile("zigmod.lock", .{}); defer f.close(); - var br = std.io.bufferedReader(f.reader()); - const r = br.reader(); + var r = nio.BufferedReader(4096, nfs.File).init(f); var i: usize = 0; var v: usize = 1; 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 var iter = std.mem.splitScalar(u8, line, ' '); const asdep = zigmod.Dep{ .type = std.meta.stringToEnum(zigmod.Dep.Type, iter.next().?).?, - .path = iter.next().?, + .path = try gpa.dupeZ(u8, iter.next().?), .version = iter.next().?, .id = zigmod.Dep.EMPTY, .name = "", @@ -374,17 +383,17 @@ pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]str return list.toOwnedSlice(); } -fn setTreeReadOnly(dir: std.fs.Dir, alloc: std.mem.Allocator) !void { +fn setTreeReadOnly(dir: nfs.Dir, alloc: std.mem.Allocator) !void { var walker = try dir.walk(alloc); defer walker.deinit(); while (try walker.next()) |entry| { - if (entry.kind != .file) continue; + if (entry.type != .REG) continue; var file = try dir.openFile(entry.path, .{}); defer file.close(); - var metadata = try file.metadata(); - var perms = metadata.permissions(); - perms.setReadOnly(true); - try file.setPermissions(perms); + const stat = try file.stat(); + var mode = stat.mode; + mode |= ~@as(nfs.File.Mode, 0o222); + try file.chmod(mode); } } diff --git a/src/util/dep.zig b/src/util/dep.zig index 58412a78f59be3e09b538903a1e94b2be4900f68..85f16a447336edc756824e6ee03268b736d7aac0 100644 --- a/src/util/dep.zig +++ b/src/util/dep.zig @@ -14,7 +14,7 @@ pub const Dep = struct { const Self = @This(); type: Type, - path: string, + path: [:0]const u8, id: [48]u8, name: string, main: string, @@ -33,17 +33,17 @@ pub const Dep = struct { pub const Type = @import("./dep_type.zig").DepType; - pub fn clean_path(self: Dep, alloc: std.mem.Allocator) !string { + pub fn clean_path(self: Dep, alloc: std.mem.Allocator) ![:0]const u8 { if (self.type == .local) { return self.path; } - var p = self.path; + var p: string = self.path; p = extras.trimPrefix(p, "http://"); p = extras.trimPrefix(p, "https://"); p = extras.trimPrefix(p, "git://"); p = extras.trimSuffix(p, ".git"); - p = try std.mem.join(alloc, "/", &.{ @tagName(self.type), p }); - return p; + const np = try std.mem.joinZ(alloc, "/", &.{ @tagName(self.type), p }); + return np; } pub fn clean_path_v(self: Dep, alloc: std.mem.Allocator) !string { @@ -65,7 +65,7 @@ pub const Dep = struct { return true; } - pub fn exact_version(self: Dep, alloc: std.mem.Allocator, dpath: string) !string { + pub fn exact_version(self: Dep, alloc: std.mem.Allocator, dpath: [:0]const u8) !string { if (self.version.len == 0) { return try self.type.exact_version(alloc, dpath); } diff --git a/src/util/dep_type.zig b/src/util/dep_type.zig index 287a2037e7813d260377a5f3ef2a70b03e17066c..621c79fb033a4b7af3e6205f0e9fa6cdcd98cb4d 100644 --- a/src/util/dep_type.zig +++ b/src/util/dep_type.zig @@ -1,6 +1,7 @@ const std = @import("std"); const string = []const u8; const nio = @import("nio"); +const nfs = @import("nfs"); const u = @import("./funcs.zig"); @@ -17,7 +18,7 @@ pub const DepType = enum { http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol // zig fmt: on - pub fn pull(self: DepType, alloc: std.mem.Allocator, rpath: string, dpath: string) !void { + pub fn pull(self: DepType, alloc: std.mem.Allocator, rpath: [:0]const u8, dpath: [:0]const u8) !void { switch (self) { .local => {}, .system_lib => {}, @@ -29,7 +30,7 @@ pub const DepType = enum { u.assert((try u.run_cmd(alloc, null, &.{ "hg", "clone", rpath, dpath })) == 0, "hg clone {s} failed", .{rpath}); }, .http => { - try std.fs.cwd().makePath(dpath); + try nfs.cwd().makePath(dpath); u.assert((try u.run_cmd(alloc, dpath, &.{ "wget", rpath })) == 0, "wget {s} failed", .{rpath}); const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").? + 1 ..]; if (std.mem.endsWith(u8, f, ".zip")) { @@ -62,8 +63,8 @@ pub const DepType = enum { } } - pub fn exact_version(self: DepType, alloc: std.mem.Allocator, mpath: string) !string { - var mdir = try std.fs.cwd().openDir(mpath, .{}); + pub fn exact_version(self: DepType, alloc: std.mem.Allocator, mpath: [:0]const u8) !string { + var mdir = try nfs.cwd().openDir(mpath, .{}); defer mdir.close(); return switch (self) { .local => "", diff --git a/src/util/funcs.zig b/src/util/funcs.zig index 5fa5824f774785be93ac9078840bdcd6aab80427..10c9fa52dc52899bd468d319ea9da87c238cf05a 100644 --- a/src/util/funcs.zig +++ b/src/util/funcs.zig @@ -44,10 +44,10 @@ pub fn split(alloc: std.mem.Allocator, in: string, delim: u8) ![]string { return list.toOwnedSlice(); } -pub fn file_list(alloc: std.mem.Allocator, dpath: string) ![]const string { - var dir = try std.fs.cwd().openDir(dpath, .{ .iterate = true }); +pub fn file_list(alloc: std.mem.Allocator, dpath: [:0]const u8) ![]const string { + var dir = try nfs.cwd().openDir(dpath, .{}); defer dir.close(); - return try extras.fileList(alloc, dir); + return try extras.fileList(alloc, dir.to_std()); } pub 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 { sha512, }; -pub fn validate_hash(alloc: std.mem.Allocator, input: string, file_path: string) !bool { +pub fn validate_hash(alloc: std.mem.Allocator, input: string, file_path: [:0]const u8) !bool { const hash = parse_split(HashFn, '-').do(input) catch return false; - const file = try std.fs.cwd().openFile(file_path, .{}); + const file = try nfs.cwd().openFile(file_path, .{}); defer file.close(); - const data = try file.reader().readAllAlloc(alloc, gb); + const data = try file.readAllAlloc(alloc, gb); const expected = hash.string; const actual = switch (hash.id) { .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 { } /// Returns the result of running `git rev-parse HEAD` -pub fn git_rev_HEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !string { - const ndir: nfs.Dir = .{ .fd = @enumFromInt(dir.fd) }; - var dirg = try ndir.openDir(".git", .{}); +pub fn git_rev_HEAD(alloc: std.mem.Allocator, dir: nfs.Dir) !string { + var dirg = try dir.openDir(".git", .{}); defer dirg.close(); const commitid = try git.getHEAD(alloc, dirg); 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 return input[f..t]; } -pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: string) !string { +pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: [:0]const u8) !string { if (override.len > 0) return override; - const dirO = if (dir.len == 0) std.fs.cwd() else try std.fs.cwd().openDir(dir, .{}); + const dirO = if (dir.len == 0) nfs.cwd() else try nfs.cwd().openDir(dir, .{}); const dpath = try dirO.realpathAlloc(gpa, "."); const splitP = try split(alloc, dpath, std.fs.path.sep); var name = splitP[splitP.len - 1]; @@ -169,28 +168,28 @@ pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: string) ! return name; } -pub fn detct_mainfile(alloc: std.mem.Allocator, override: string, dir: ?std.fs.Dir, name: string) !string { +pub fn detct_mainfile(alloc: std.mem.Allocator, override: string, dir: nfs.Dir, name: string) !string { if (override.len > 0) { - if (try extras.doesFileExist(dir, override)) { + if (try extras.doesFileExist(dir.to_std(), override)) { if (std.mem.endsWith(u8, override, ".zig")) { return override; } } } const namedotzig = try std.mem.concat(alloc, u8, &.{ name, ".zig" }); - if (try extras.doesFileExist(dir, namedotzig)) { + if (try extras.doesFileExist(dir.to_std(), namedotzig)) { return namedotzig; } - if (try extras.doesFileExist(dir, "lib.zig")) { + if (try extras.doesFileExist(dir.to_std(), "lib.zig")) { return "lib.zig"; } - if (try extras.doesFileExist(dir, "main.zig")) { + if (try extras.doesFileExist(dir.to_std(), "main.zig")) { return "main.zig"; } - if (try extras.doesFileExist(dir, try std.fs.path.join(alloc, &.{ "src", "lib.zig" }))) { + if (try extras.doesFileExist(dir.to_std(), try std.fs.path.join(alloc, &.{ "src", "lib.zig" }))) { return "src/lib.zig"; } - if (try extras.doesFileExist(dir, try std.fs.path.join(alloc, &.{ "src", "main.zig" }))) { + if (try extras.doesFileExist(dir.to_std(), try std.fs.path.join(alloc, &.{ "src", "main.zig" }))) { return "src/main.zig"; } return error.CantFindMain; @@ -214,12 +213,48 @@ pub fn indexOfAfter(haystack: string, needle: u8, after: usize) ?usize { return null; } -pub fn find_cachepath() !string { - const haystack = try std.fs.cwd().realpathAlloc(gpa, "."); +pub fn find_cachepath() ![:0]const u8 { + const haystack = try nfs.cwd().realpathAlloc(gpa, "."); const needle = "/.zigmod/deps"; if (std.mem.indexOf(u8, haystack, needle)) |index| { - return haystack[0 .. index + needle.len]; + return gpa.dupeZ(u8, haystack[0 .. index + needle.len]); } - return try std.fs.path.join(gpa, &.{ haystack, ".zigmod", "deps" }); + return try std.fs.path.joinZ(gpa, &.{ haystack, ".zigmod", "deps" }); } + +pub fn altStringEscape(data: []const u8) StringEscape { + return .{ .data = data }; +} +const StringEscape = struct { + data: []const u8, + + pub fn nprint(self: StringEscape, writer: anytype) !void { + for (self.data) |c| switch (c) { + '\n' => try writer.writeAll("\\n"), + '\r' => try writer.writeAll("\\r"), + '\t' => try writer.writeAll("\\t"), + '\\' => try writer.writeAll("\\\\"), + '"' => try writer.writeAll("\\\""), + '\'' => try writer.writeAll(&.{'\''}), + ' ', '!', '#'...'&', '('...'[', ']'...'~' => try writer.writeAll(&.{c}), + else => { + try writer.print("\\x{x:0>2}", .{c}); + // try writer.printInt(c, 16, .lower, .{ .width = 2, .fill = '0' }); + }, + }; + } +}; + +pub fn altSemanticVersion(data: std.SemanticVersion) SemanticVersion { + return .{ .data = data }; +} +const SemanticVersion = struct { + data: std.SemanticVersion, + + pub fn nprint(self: SemanticVersion, writer: anytype) !void { + try writer.print("{d}.{d}.{d}", .{ self.data.major, self.data.minor, self.data.patch }); + if (self.data.pre) |pre| try writer.print("-{s}", .{pre}); + if (self.data.build) |build| try writer.print("+{s}", .{build}); + } +}; diff --git a/src/util/modfile.zig b/src/util/modfile.zig index c5efa2af33ac9cf2ea1f5ea2b3e288e3424e05fb..185e2f87dc0f5fa45a4dd277256846b913182b15 100644 --- a/src/util/modfile.zig +++ b/src/util/modfile.zig @@ -4,6 +4,7 @@ const yaml = @import("yaml"); const extras = @import("extras"); const root = @import("root"); const build_options = root.build_options; +const nfs = @import("nfs"); const zigmod = @import("../lib.zig"); const u = @import("funcs.zig"); @@ -11,6 +12,7 @@ const u = @import("funcs.zig"); // // +const gpa = std.heap.c_allocator; const b = 1; const kb = b * 1024; const mb = kb * 1024; @@ -32,10 +34,10 @@ pub const ModFile = struct { builddeps: []zigmod.Dep, min_zig_version: ?std.SemanticVersion, - pub fn openFile(dir: std.fs.Dir, ops: std.fs.File.OpenFlags) !struct { string, std.fs.File } { + pub fn openFile(dir: nfs.Dir, ops: nfs.Dir.OpenFileFlags) !struct { string, nfs.File } { return .{ "zig.mod", dir.openFile("zig.mod", ops) catch |err| switch (err) { - error.FileNotFound => return .{ "zigmod.yml", dir.openFile("zigmod.yml", ops) catch |err2| switch (err2) { - error.FileNotFound => return error.ManifestNotFound, + error.ENOENT => return .{ "zigmod.yml", dir.openFile("zigmod.yml", ops) catch |err2| switch (err2) { + error.ENOENT => return error.ManifestNotFound, else => |e2| return e2, } }, else => |e| return e, @@ -43,13 +45,13 @@ pub const ModFile = struct { } pub fn init(alloc: std.mem.Allocator) !Self { - return try from_dir(alloc, std.fs.cwd(), "."); + return try from_dir(alloc, nfs.cwd(), "."); } - pub fn from_dir(alloc: std.mem.Allocator, dir: std.fs.Dir, dir_path: string) !Self { + pub fn from_dir(alloc: std.mem.Allocator, dir: nfs.Dir, dir_path: string) !Self { const file_path, const file = try openFile(dir, .{}); defer file.close(); - const input = try file.reader().readAllAlloc(alloc, mb); + const input = try file.readAllAlloc(alloc, mb); const doc = try yaml.parse(alloc, input); return from_mapping(alloc, doc.mapping, dir_path, file_path); } @@ -101,14 +103,14 @@ pub const ModFile = struct { if (dep_seq != .sequence) continue; for (dep_seq.sequence) |item| { var dtype: string = undefined; - var path: string = undefined; + var path: [:0]const u8 = undefined; var version: ?string = null; var main = item.mapping.get_string("main") orelse ""; if (item.mapping.get("src")) |val| { var src_iter = std.mem.tokenizeScalar(u8, val.string, ' '); dtype = src_iter.next().?; - path = src_iter.next().?; + path = try gpa.dupeZ(u8, src_iter.next().?); if (src_iter.next()) |dver| { version = dver; } diff --git a/src/util/module.zig b/src/util/module.zig index 2a897bdcd11a806a1b0bddc8318690c84a9f13e5..576b0f51bc27fb6a80a1231d07f3a32603c3c879 100644 --- a/src/util/module.zig +++ b/src/util/module.zig @@ -4,6 +4,7 @@ const builtin = @import("builtin"); const yaml = @import("yaml"); const extras = @import("extras"); const nio = @import("nio"); +const nfs = @import("nfs"); const zigmod = @import("../lib.zig"); const u = @import("funcs.zig"); @@ -24,14 +25,14 @@ pub const Module = struct { except_os: []const string = &.{}, yaml: ?yaml.Mapping, deps: []Module, - clean_path: string, + clean_path: [:0]const u8, dep: ?zigmod.Dep, for_build: bool = false, min_zig_version: ?std.SemanticVersion, pub const ROOT: [48]u8 = ("root" ++ (" " ** 44)).*; - pub fn from(alloc: std.mem.Allocator, dep: zigmod.Dep, cachepath: string, options: *common.CollectOptions) !Module { + pub fn from(alloc: std.mem.Allocator, dep: zigmod.Dep, cachepath: [:0]const u8, options: *common.CollectOptions) !Module { var moddeps = std.ArrayList(Module).init(alloc); errdefer moddeps.deinit(); @@ -68,7 +69,7 @@ pub const Module = struct { } pub fn get_hash(self: Module, alloc: std.mem.Allocator, cdpath: string) !string { - const file_list_1 = try u.file_list(alloc, try std.mem.concat(alloc, u8, &.{ cdpath, "/", self.clean_path })); + const file_list_1 = try u.file_list(alloc, try std.mem.concatWithSentinel(alloc, u8, &.{ cdpath, "/", self.clean_path }, 0)); var file_list_2 = std.ArrayList(string).init(alloc); errdefer file_list_2.deinit(); @@ -88,10 +89,10 @@ pub const Module = struct { var h = std.crypto.hash.Blake3.init(.{}); for (file_list_2.items) |item| { - const abs_path = try std.fs.path.join(alloc, &.{ cdpath, self.clean_path, item }); - const file = try std.fs.cwd().openFile(abs_path, .{}); + const abs_path = try std.fs.path.joinZ(alloc, &.{ cdpath, self.clean_path, item }); + const file = try nfs.cwd().openFile(abs_path, .{}); defer file.close(); - const input = try file.reader().readAllAlloc(alloc, u.mb * 100); + const input = try file.readAllAlloc(alloc, u.mb * 100); h.update(input); } var out: [32]u8 = undefined; @@ -164,13 +165,13 @@ pub const Module = struct { return false; } - pub fn pin(self: Module, alloc: std.mem.Allocator, cachepath: string, options: *common.CollectOptions) !string { + pub fn pin(self: Module, alloc: std.mem.Allocator, cachepath: [:0]const u8, options: *common.CollectOptions) !string { return switch (self.type) { .local => "", .system_lib => "", .framework => "", else => |sub| { - var cdir = try std.fs.cwd().openDir(cachepath, .{}); + var cdir = try nfs.cwd().openDir(cachepath, .{}); defer cdir.close(); var mdir = try cdir.openDir(self.clean_path, .{}); defer mdir.close(); diff --git a/zigmod.lock b/zigmod.lock index fe76645b99abb3699300bdf084d73cc7d0221192..955f05daafd160fc7ce3f8b29f38c2d1fcf7bab5 100644 --- a/zigmod.lock +++ b/zigmod.lock @@ -5,7 +5,7 @@ git https://github.com/nektro/iguanaTLS commit-3450aaf3ca47986540e2b0258c2affc45 git https://github.com/nektro/zfetch commit-40d141bf7db81f05a83cce5f2edc4b14e41a5c34 git https://github.com/nektro/zig-ansi commit-5f89211a749aef6bf518889c0467ceb24825c055 git https://github.com/nektro/zig-detect-license commit-a1a066da88dab50873a56f0349dc12dc76542077 -git https://github.com/nektro/zig-extras commit-c2c581aa6a38438dd9ed8da0f59019691c5dd45d +git https://github.com/nektro/zig-extras commit-b3457b31a1d1ea2c19c5d0b007c903d3e80add40 git https://github.com/nektro/zig-git commit-2b3f83cd341764f979969603e4f77e62f353b6a3 git https://github.com/nektro/zig-inquirer commit-4cddefa42744d61067567b0b36b5d2bb376e5ae3 git https://github.com/nektro/zig-intrusive-parser commit-a31b480914d15f3d13cdfb586aac950c73beebdd @@ -13,13 +13,13 @@ git https://github.com/nektro/zig-json commit-428aa8a29e370fdb2e6739d5676b1de415 git https://github.com/nektro/zig-leven commit-618eddde4ffbc6d34100e4bc6aa654d41161537a git https://github.com/nektro/zig-licenses commit-16cef5e32b3f8bbcf1064c599615290a720b6547 git https://github.com/nektro/zig-licenses-text commit-ba0f00dfb23d28c301e4b54d0a278def2c38dc7b -git https://github.com/nektro/zig-nfs commit-18b00c5c5d25e230ff4f3ea07fadb2a1d54a773d +git https://github.com/nektro/zig-nfs commit-c855473c8bd15dd24a4e8b6911b7e006062004ba git https://github.com/nektro/zig-nio commit-c1da2e8a31858880eb3e4cfcf12de0a865617623 -git https://github.com/nektro/zig-sys-darwin commit-c5c1b35492224b0ed8d2570c8e71702947b1e400 -git https://github.com/nektro/zig-sys-linux commit-9edefde5fcf96894b6aa4ab60241940bba65debf +git https://github.com/nektro/zig-sys-darwin commit-3265d1f06418eb0360d753c12116310a14b97bde +git https://github.com/nektro/zig-sys-linux commit-f0b155d3627f8c19868be1b2f15d71cda908b575 git https://github.com/nektro/zig-time commit-0f4db4c980146e4a3fc86a9a9070452a25ff9317 git https://github.com/nektro/zig-tracer commit-3a5fdea4ffd387a53ac2a42fb503557cdbe20696 -git https://github.com/nektro/zig-yaml commit-b1ebd056b9afaaa719cb55359c610455ffe04499 +git https://github.com/nektro/zig-yaml commit-00e899bec815bc2b49c6e5a72a7cfeeda673e133 git https://github.com/truemedian/hzzp commit-ab212bd208f0eb54d85861679677c5e3dc9bb543 git https://github.com/madler/zlib tag-v1.3.2 git https://github.com/yaml/libyaml tag-0.2.5 -- 2.54.0