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 {...@@ -60,7 +60,7 @@ pub fn fetch(exe: *std.Build.Step.Compile) *std.Build.Step {
60 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zfetch", "40d141bf7db81f05a83cce5f2edc4b14e41a5c34").step);60 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zfetch", "40d141bf7db81f05a83cce5f2edc4b14e41a5c34").step);
61 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-ansi", "5f89211a749aef6bf518889c0467ceb24825c055").step);61 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-ansi", "5f89211a749aef6bf518889c0467ceb24825c055").step);
62 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-detect-license", "a1a066da88dab50873a56f0349dc12dc76542077").step);62 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);
64 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-git", "2b3f83cd341764f979969603e4f77e62f353b6a3").step);64 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-git", "2b3f83cd341764f979969603e4f77e62f353b6a3").step);
65 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-inquirer", "4cddefa42744d61067567b0b36b5d2bb376e5ae3").step);65 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-inquirer", "4cddefa42744d61067567b0b36b5d2bb376e5ae3").step);
66 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-intrusive-parser", "a31b480914d15f3d13cdfb586aac950c73beebdd").step);66 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 {...@@ -68,13 +68,13 @@ pub fn fetch(exe: *std.Build.Step.Compile) *std.Build.Step {
68 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-leven", "618eddde4ffbc6d34100e4bc6aa654d41161537a").step);68 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-leven", "618eddde4ffbc6d34100e4bc6aa654d41161537a").step);
69 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses", "16cef5e32b3f8bbcf1064c599615290a720b6547").step);69 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses", "16cef5e32b3f8bbcf1064c599615290a720b6547").step);
70 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-licenses-text", "ba0f00dfb23d28c301e4b54d0a278def2c38dc7b").step);70 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);
72 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-nio", "c1da2e8a31858880eb3e4cfcf12de0a865617623").step);72 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);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", "9edefde5fcf96894b6aa4ab60241940bba65debf").step);74 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-sys-linux", "f0b155d3627f8c19868be1b2f15d71cda908b575").step);
75 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-time", "0f4db4c980146e4a3fc86a9a9070452a25ff9317").step);75 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-time", "0f4db4c980146e4a3fc86a9a9070452a25ff9317").step);
76 step.dependOn(&GitExactStep.create(b, "https://github.com/nektro/zig-tracer", "3a5fdea4ffd387a53ac2a42fb503557cdbe20696").step);76 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);
78 step.dependOn(&GitExactStep.create(b, "https://github.com/truemedian/hzzp", "ab212bd208f0eb54d85861679677c5e3dc9bb543").step);78 step.dependOn(&GitExactStep.create(b, "https://github.com/truemedian/hzzp", "ab212bd208f0eb54d85861679677c5e3dc9bb543").step);
79 step.dependOn(&GitExactStep.create(b, "https://github.com/madler/zlib", "da607da739fa6047df13e66a2af6b8bec7c2a498").step);79 step.dependOn(&GitExactStep.create(b, "https://github.com/madler/zlib", "da607da739fa6047df13e66a2af6b8bec7c2a498").step);
80 step.dependOn(&GitExactStep.create(b, "https://github.com/yaml/libyaml", "2c891fc7a770e8ba2fec34fc6b545c672beb37e6").step);80 step.dependOn(&GitExactStep.create(b, "https://github.com/yaml/libyaml", "2c891fc7a770e8ba2fec34fc6b545c672beb37e6").step);
...@@ -210,9 +210,9 @@ pub const package_data = struct {...@@ -210,9 +210,9 @@ pub const package_data = struct {
210 .entry = "/git/github.com/nektro/zig-ansi/5f89211a749aef6bf518889c0467ceb24825c055/src/lib.zig",210 .entry = "/git/github.com/nektro/zig-ansi/5f89211a749aef6bf518889c0467ceb24825c055/src/lib.zig",
211 };211 };
212 pub var _f7dubzb7cyqe = Package{212 pub var _f7dubzb7cyqe = Package{
213 .store = "/git/github.com/nektro/zig-extras/c2c581aa6a38438dd9ed8da0f59019691c5dd45d",213 .store = "/git/github.com/nektro/zig-extras/b3457b31a1d1ea2c19c5d0b007c903d3e80add40",
214 .name = "extras",214 .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",
216 };216 };
217 pub var _c1xirp1ota5p = Package{217 pub var _c1xirp1ota5p = Package{
218 .store = "/git/github.com/nektro/zig-inquirer/4cddefa42744d61067567b0b36b5d2bb376e5ae3",218 .store = "/git/github.com/nektro/zig-inquirer/4cddefa42744d61067567b0b36b5d2bb376e5ae3",
...@@ -231,14 +231,14 @@ pub const package_data = struct {...@@ -231,14 +231,14 @@ pub const package_data = struct {
231 .entry = "/git/github.com/nektro/zig-licenses/16cef5e32b3f8bbcf1064c599615290a720b6547/src/lib.zig",231 .entry = "/git/github.com/nektro/zig-licenses/16cef5e32b3f8bbcf1064c599615290a720b6547/src/lib.zig",
232 };232 };
233 pub var _73bukkeci2u6 = Package{233 pub var _73bukkeci2u6 = Package{
234 .store = "/git/github.com/nektro/zig-sys-darwin/c5c1b35492224b0ed8d2570c8e71702947b1e400",234 .store = "/git/github.com/nektro/zig-sys-darwin/3265d1f06418eb0360d753c12116310a14b97bde",
235 .name = "sys-darwin",235 .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",
237 };237 };
238 pub var _h7tv7ayhffak = Package{238 pub var _h7tv7ayhffak = Package{
239 .store = "/git/github.com/nektro/zig-sys-linux/9edefde5fcf96894b6aa4ab60241940bba65debf",239 .store = "/git/github.com/nektro/zig-sys-linux/f0b155d3627f8c19868be1b2f15d71cda908b575",
240 .name = "sys-linux",240 .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",
242 .deps = &[_]*Package{ },242 .deps = &[_]*Package{ },
243 .system_libs = &.{ "c" },243 .system_libs = &.{ "c" },
244 };244 };
...@@ -261,9 +261,9 @@ pub const package_data = struct {...@@ -261,9 +261,9 @@ pub const package_data = struct {
261 .deps = &[_]*Package{ &_f7dubzb7cyqe, &_h7tv7ayhffak, &_73bukkeci2u6 },261 .deps = &[_]*Package{ &_f7dubzb7cyqe, &_h7tv7ayhffak, &_73bukkeci2u6 },
262 };262 };
263 pub var _vph9l0hxpeze = Package{263 pub var _vph9l0hxpeze = Package{
264 .store = "/git/github.com/nektro/zig-nfs/18b00c5c5d25e230ff4f3ea07fadb2a1d54a773d",264 .store = "/git/github.com/nektro/zig-nfs/c855473c8bd15dd24a4e8b6911b7e006062004ba",
265 .name = "nfs",265 .name = "nfs",
266 .entry = "/git/github.com/nektro/zig-nfs/18b00c5c5d25e230ff4f3ea07fadb2a1d54a773d/nfs.zig",266 .entry = "/git/github.com/nektro/zig-nfs/c855473c8bd15dd24a4e8b6911b7e006062004ba/nfs.zig",
267 .deps = &[_]*Package{ &_h7tv7ayhffak, &_kscsl0145t7x, &_iecwp4b3bsfm, &_73bukkeci2u6 },267 .deps = &[_]*Package{ &_h7tv7ayhffak, &_kscsl0145t7x, &_iecwp4b3bsfm, &_73bukkeci2u6 },
268 };268 };
269 pub var _ede2wygpe1iy = Package{269 pub var _ede2wygpe1iy = Package{
...@@ -297,9 +297,9 @@ pub const package_data = struct {...@@ -297,9 +297,9 @@ pub const package_data = struct {
297 .deps = &[_]*Package{ &_pt88y5d80m25, &_96h80ezrvj7i },297 .deps = &[_]*Package{ &_pt88y5d80m25, &_96h80ezrvj7i },
298 };298 };
299 pub var _g982zq6e8wsv = Package{299 pub var _g982zq6e8wsv = Package{
300 .store = "/git/github.com/nektro/zig-yaml/b1ebd056b9afaaa719cb55359c610455ffe04499",300 .store = "/git/github.com/nektro/zig-yaml/00e899bec815bc2b49c6e5a72a7cfeeda673e133",
301 .name = "yaml",301 .name = "yaml",
302 .entry = "/git/github.com/nektro/zig-yaml/b1ebd056b9afaaa719cb55359c610455ffe04499/yaml.zig",302 .entry = "/git/github.com/nektro/zig-yaml/00e899bec815bc2b49c6e5a72a7cfeeda673e133/yaml.zig",
303 .deps = &[_]*Package{ &_8mdbh0zuneb0 },303 .deps = &[_]*Package{ &_8mdbh0zuneb0 },
304 };304 };
305 pub var _9k24gimke1an = Package{305 pub var _9k24gimke1an = Package{
src/cmd/ci.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const nfs = @import("nfs");
34
4const zigmod = @import("../lib.zig");5const zigmod = @import("../lib.zig");
5const u = @import("./../util/funcs.zig");6const u = @import("./../util/funcs.zig");
...@@ -14,11 +15,11 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -14,11 +15,11 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
1415
15 const gpa = std.heap.c_allocator;16 const gpa = std.heap.c_allocator;
16 const cachepath = try u.find_cachepath();17 const cachepath = try u.find_cachepath();
17 const dir = std.fs.cwd();18 const dir = nfs.cwd();
18 try do(gpa, cachepath, dir);19 try do(gpa, cachepath, dir);
19}20}
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 {
22 var options = common.CollectOptions{23 var options = common.CollectOptions{
23 .log = true,24 .log = true,
24 .update = false,25 .update = false,
src/cmd/explain.zig+2-1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const extras = @import("extras");3const extras = @import("extras");
4const nfs = @import("nfs");
45
5const zigmod = @import("../lib.zig");6const zigmod = @import("../lib.zig");
6const u = @import("./../util/funcs.zig");7const u = @import("./../util/funcs.zig");
...@@ -14,7 +15,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -14,7 +15,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
1415
15 const gpa = std.heap.c_allocator;16 const gpa = std.heap.c_allocator;
16 const cachepath = try u.find_cachepath();17 const cachepath = try u.find_cachepath();
17 const dir = std.fs.cwd();18 const dir = nfs.cwd();
18 const should_lock = args.len >= 1 and std.mem.eql(u8, args[0], "--locked");19 const should_lock = args.len >= 1 and std.mem.eql(u8, args[0], "--locked");
19 const format_i: usize = if (should_lock) 1 else 0;20 const format_i: usize = if (should_lock) 1 else 0;
20 const Format = enum {21 const Format = enum {
src/cmd/fetch.zig+23-22
...@@ -2,6 +2,7 @@ const std = @import("std");...@@ -2,6 +2,7 @@ const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const ansi = @import("ansi");3const ansi = @import("ansi");
4const extras = @import("extras");4const extras = @import("extras");
5const nfs = @import("nfs");
56
6const zigmod = @import("../lib.zig");7const zigmod = @import("../lib.zig");
7const u = @import("./../util/funcs.zig");8const u = @import("./../util/funcs.zig");
...@@ -16,7 +17,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -16,7 +17,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
1617
17 const gpa = std.heap.c_allocator;18 const gpa = std.heap.c_allocator;
18 const cachepath = try u.find_cachepath();19 const cachepath = try u.find_cachepath();
19 const dir = std.fs.cwd();20 const dir = nfs.cwd();
20 const should_update = !(args.len >= 1 and std.mem.eql(u8, args[0], "--no-update"));21 const should_update = !(args.len >= 1 and std.mem.eql(u8, args[0], "--no-update"));
2122
22 var options = common.CollectOptions{23 var options = common.CollectOptions{
...@@ -43,17 +44,17 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -43,17 +44,17 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
43 try license.do(cachepath, dir, &options, outfile);44 try license.do(cachepath, dir, &options, outfile);
44}45}
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 {
47 const f = try dir.createFile("deps.zig", .{});48 const f = try dir.createFile("deps.zig", .{});
48 defer f.close();49 defer f.close();
4950
50 const w = f.writer();51 const w = f;
51 try w.writeAll("// zig fmt: off\n");52 try w.writeAll("// zig fmt: off\n");
52 try w.writeAll("const std = @import(\"std\");\n");53 try w.writeAll("const std = @import(\"std\");\n");
53 try w.writeAll("const builtin = @import(\"builtin\");\n");54 try w.writeAll("const builtin = @import(\"builtin\");\n");
54 try w.writeAll("const string = []const u8;\n");55 try w.writeAll("const string = []const u8;\n");
55 try w.writeAll("\n");56 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)});
57 try w.writeAll("pub var skip_libc = false;\n");58 try w.writeAll("pub var skip_libc = false;\n");
58 try w.writeAll("\n");59 try w.writeAll("\n");
59 try w.writeAll(60 try w.writeAll(
...@@ -148,7 +149,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D...@@ -148,7 +149,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
148 \\}}149 \\}}
149 \\150 \\
150 \\151 \\
151 , .{top_module.minZigVersion()});152 , .{if (top_module.minZigVersion()) |sv| u.altSemanticVersion(sv) else null});
152153
153 try w.writeAll("pub const dirs = struct {\n");154 try w.writeAll("pub const dirs = struct {\n");
154 try print_dirs(w, list.items, alloc);155 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...@@ -179,18 +180,18 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
179 try w.writeAll("};\n");180 try w.writeAll("};\n");
180}181}
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 {
183 const fl = try dir.createFile("zigmod.lock", .{});184 const fl = try dir.createFile("zigmod.lock", .{});
184 defer fl.close();185 defer fl.close();
185186
186 std.mem.sort(zigmod.Module, list.items, {}, zigmod.Module.lessThan);187 std.mem.sort(zigmod.Module, list.items, {}, zigmod.Module.lessThan);
187188
188 const wl = fl.writer();189 const wl = fl;
189 try wl.writeAll("2\n");190 try wl.writeAll("2\n");
190 for (list.items) |m| {191 for (list.items) |m| {
191 if (m.dep) |md| {192 if (m.dep) |md| {
192 if (md.type.isLocal()) continue;193 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 });
194 const version = try md.exact_version(alloc, mpath);195 const version = try md.exact_version(alloc, mpath);
195 try wl.print("{s} {s} {s}\n", .{ @tagName(md.type), md.path, version });196 try wl.print("{s} {s} {s}\n", .{ @tagName(md.type), md.path, version });
196 }197 }
...@@ -290,7 +291,7 @@ fn diff_printchange(comptime testt: string, comptime replacement: string, item:...@@ -290,7 +291,7 @@ fn diff_printchange(comptime testt: string, comptime replacement: string, item:
290 return false;291 return false;
291}292}
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 {
294 for (list) |mod| {295 for (list) |mod| {
295 if (mod.type == .system_lib or mod.type == .framework) continue;296 if (mod.type == .system_lib or mod.type == .framework) continue;
296 if (std.mem.eql(u8, &mod.id, &zigmod.Module.ROOT)) {297 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...@@ -298,15 +299,15 @@ fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module, alloc: std.mem
298 continue;299 continue;
299 }300 }
300 if (std.mem.eql(u8, mod.clean_path, "../..")) {301 if (std.mem.eql(u8, mod.clean_path, "../..")) {
301 const cwd_realpath = try std.fs.cwd().realpathAlloc(alloc, ".");302 const cwd_realpath = try nfs.cwd().realpathAlloc(alloc, ".");
302 try w.print(" pub const _{s} = \"{}\";\n", .{ mod.short_id(), std.zig.fmtEscapes(cwd_realpath) });303 try w.print(" pub const _{s} = \"{}\";\n", .{ mod.short_id(), u.altStringEscape(cwd_realpath) });
303 continue;304 continue;
304 }305 }
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) });
306 }307 }
307}308}
308309
309fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void {310fn print_deps(w: nfs.File, m: zigmod.Module) !void {
310 try w.writeAll("&[_]*const Package{\n");311 try w.writeAll("&[_]*const Package{\n");
311 for (m.deps) |d| {312 for (m.deps) |d| {
312 if (d.main.len == 0) {313 if (d.main.len == 0) {
...@@ -320,7 +321,7 @@ fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void {...@@ -320,7 +321,7 @@ fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void {
320 try w.writeAll("}");321 try w.writeAll("}");
321}322}
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 {
324 var len: usize = notdone.items.len;325 var len: usize = notdone.items.len;
325 while (notdone.items.len > 0) {326 while (notdone.items.len > 0) {
326 for (notdone.items, 0..) |mod, i| {327 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...@@ -359,7 +360,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul
359 if (mod.c_include_dirs.len > 0) {360 if (mod.c_include_dirs.len > 0) {
360 try w.writeAll(" .c_include_dirs = &.{");361 try w.writeAll(" .c_include_dirs = &.{");
361 for (mod.c_include_dirs, 0..) |item, j| {362 for (mod.c_include_dirs, 0..) |item, j| {
362 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)});363 try w.print(" \"{}\"", .{u.altStringEscape(item)});
363 if (j != mod.c_include_dirs.len - 1) try w.writeAll(",");364 if (j != mod.c_include_dirs.len - 1) try w.writeAll(",");
364 }365 }
365 try w.writeAll(" },\n");366 try w.writeAll(" },\n");
...@@ -367,7 +368,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul...@@ -367,7 +368,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul
367 if (mod.c_source_files.len > 0) {368 if (mod.c_source_files.len > 0) {
368 try w.writeAll(" .c_source_files = &.{");369 try w.writeAll(" .c_source_files = &.{");
369 for (mod.c_source_files, 0..) |item, j| {370 for (mod.c_source_files, 0..) |item, j| {
370 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)});371 try w.print(" \"{}\"", .{u.altStringEscape(item)});
371 if (j != mod.c_source_files.len - 1) try w.writeAll(",");372 if (j != mod.c_source_files.len - 1) try w.writeAll(",");
372 }373 }
373 try w.writeAll(" },\n");374 try w.writeAll(" },\n");
...@@ -375,7 +376,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul...@@ -375,7 +376,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul
375 if (mod.c_source_flags.len > 0) {376 if (mod.c_source_flags.len > 0) {
376 try w.writeAll(" .c_source_flags = &.{");377 try w.writeAll(" .c_source_flags = &.{");
377 for (mod.c_source_flags, 0..) |item, j| {378 for (mod.c_source_flags, 0..) |item, j| {
378 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)});379 try w.print(" \"{}\"", .{u.altStringEscape(item)});
379 if (j != mod.c_source_flags.len - 1) try w.writeAll(",");380 if (j != mod.c_source_flags.len - 1) try w.writeAll(",");
380 }381 }
381 try w.writeAll(" },\n");382 try w.writeAll(" },\n");
...@@ -384,7 +385,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul...@@ -384,7 +385,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul
384 try w.writeAll(" .system_libs = &.{");385 try w.writeAll(" .system_libs = &.{");
385 for (mod.deps, 0..) |item, j| {386 for (mod.deps, 0..) |item, j| {
386 if (!(item.type == .system_lib)) continue;387 if (!(item.type == .system_lib)) continue;
387 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item.name)});388 try w.print(" \"{}\"", .{u.altStringEscape(item.name)});
388 if (j != mod.deps.len - 1) try w.writeAll(",");389 if (j != mod.deps.len - 1) try w.writeAll(",");
389 }390 }
390 try w.writeAll(" },\n");391 try w.writeAll(" },\n");
...@@ -393,7 +394,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul...@@ -393,7 +394,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Modul
393 try w.writeAll(" .frameworks = &.{");394 try w.writeAll(" .frameworks = &.{");
394 for (mod.deps, 0..) |item, j| {395 for (mod.deps, 0..) |item, j| {
395 if (!(item.type == .system_lib)) continue;396 if (!(item.type == .system_lib)) continue;
396 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item.name)});397 try w.print(" \"{}\"", .{u.altStringEscape(item.name)});
397 if (j != mod.deps.len - 1) try w.writeAll(",");398 if (j != mod.deps.len - 1) try w.writeAll(",");
398 }399 }
399 try w.writeAll(" },\n");400 try w.writeAll(" },\n");
...@@ -422,7 +423,7 @@ fn contains_all(needles: []zigmod.Module, haystack: []const zigmod.Module) bool...@@ -422,7 +423,7 @@ fn contains_all(needles: []zigmod.Module, haystack: []const zigmod.Module) bool
422 return true;423 return true;
423}424}
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 {
426 try w.writeAll("struct {\n");427 try w.writeAll("struct {\n");
427 for (m.deps) |d| {428 for (m.deps) |d| {
428 if (d.main.len == 0) {429 if (d.main.len == 0) {
...@@ -437,7 +438,7 @@ fn print_pkgs(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module)...@@ -437,7 +438,7 @@ fn print_pkgs(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module)
437 try w.writeAll("}");438 try w.writeAll("}");
438}439}
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 {
441 for (m.deps) |d| {442 for (m.deps) |d| {
442 if (d.main.len == 0) {443 if (d.main.len == 0) {
443 continue;444 continue;
...@@ -446,7 +447,7 @@ fn print_imports(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Modu...@@ -446,7 +447,7 @@ fn print_imports(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Modu
446 continue;447 continue;
447 }448 }
448 const ident = try zig_name_from_pkg_name(alloc, d.name);449 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 });
450 }451 }
451}452}
452453
src/cmd/generate.zig+19-18
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const extras = @import("extras");3const extras = @import("extras");
4const nfs = @import("nfs");
45
5const zigmod = @import("../lib.zig");6const zigmod = @import("../lib.zig");
6const u = @import("./../util/funcs.zig");7const u = @import("./../util/funcs.zig");
...@@ -15,7 +16,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -15,7 +16,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
15 //16 //
16 const gpa = std.heap.c_allocator;17 const gpa = std.heap.c_allocator;
17 const cachepath = try u.find_cachepath();18 const cachepath = try u.find_cachepath();
18 const dir = std.fs.cwd();19 const dir = nfs.cwd();
19 const should_lock = args.len >= 1 and std.mem.eql(u8, args[0], "--locked");20 const should_lock = args.len >= 1 and std.mem.eql(u8, args[0], "--locked");
2021
21 var options = common.CollectOptions{22 var options = common.CollectOptions{
...@@ -34,11 +35,11 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -34,11 +35,11 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
34 try create_depszig(gpa, cachepath, dir, top_module, list.items, &options);35 try create_depszig(gpa, cachepath, dir, top_module, list.items, &options);
35}36}
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 {
38 const f = try dir.createFile("deps.zig", .{});39 const f = try dir.createFile("deps.zig", .{});
39 defer f.close();40 defer f.close();
4041
41 const w = f.writer();42 const w = f;
42 try w.writeAll("// zig fmt: off\n");43 try w.writeAll("// zig fmt: off\n");
43 try w.writeAll("const std = @import(\"std\");\n");44 try w.writeAll("const std = @import(\"std\");\n");
44 try w.writeAll("const builtin = @import(\"builtin\");\n");45 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...@@ -225,7 +226,7 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
225 \\}}226 \\}}
226 \\227 \\
227 \\228 \\
228 , .{top_module.minZigVersion()});229 , .{if (top_module.minZigVersion()) |sv| u.altSemanticVersion(sv) else null});
229230
230 try w.writeAll("pub const package_data = struct {\n");231 try w.writeAll("pub const package_data = struct {\n");
231 var duped = std.ArrayList(zigmod.Module).init(alloc);232 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...@@ -252,18 +253,18 @@ pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.D
252 try w.writeAll("};\n");253 try w.writeAll("};\n");
253}254}
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 {
256 for (list) |mod| {257 for (list) |mod| {
257 if (mod.type == .system_lib or mod.type == .framework) continue;258 if (mod.type == .system_lib or mod.type == .framework) continue;
258 if (std.mem.eql(u8, mod.id, "root")) {259 if (std.mem.eql(u8, mod.id, "root")) {
259 try w.writeAll(" pub const _root = \"\";\n");260 try w.writeAll(" pub const _root = \"\";\n");
260 continue;261 continue;
261 }262 }
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) });
263 }264 }
264}265}
265266
266fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void {267fn print_deps(w: nfs.File, m: zigmod.Module) !void {
267 try w.writeAll("[_]*Package{\n");268 try w.writeAll("[_]*Package{\n");
268 for (m.deps) |d| {269 for (m.deps) |d| {
269 if (d.main.len == 0) {270 if (d.main.len == 0) {
...@@ -277,7 +278,7 @@ fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void {...@@ -277,7 +278,7 @@ fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void {
277 try w.writeAll("}");278 try w.writeAll("}");
278}279}
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 {
281 var len: usize = notdone.items.len;282 var len: usize = notdone.items.len;
282 while (notdone.items.len > 0) {283 while (notdone.items.len > 0) {
283 for (notdone.items, 0..) |mod, i| {284 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:...@@ -292,13 +293,13 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
292 switch (mod.type) {293 switch (mod.type) {
293 .system_lib, .framework => {},294 .system_lib, .framework => {},
294 .local => {},295 .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) }),
296 .hg => @panic("TODO"),297 .hg => @panic("TODO"),
297 .http => @panic("TODO"),298 .http => @panic("TODO"),
298 }299 }
299 if (mod.main.len > 0 and !std.mem.eql(u8, &mod.id, &zigmod.Module.ROOT)) {300 if (mod.main.len > 0 and !std.mem.eql(u8, &mod.id, &zigmod.Module.ROOT)) {
300 try w.print(" .name = \"{s}\",\n", .{mod.name});301 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
303 if (mod.deps.len != 0) {304 if (mod.deps.len != 0) {
304 try w.writeAll(" .deps = &[_]*Package{");305 try w.writeAll(" .deps = &[_]*Package{");
...@@ -313,7 +314,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:...@@ -313,7 +314,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
313 if (mod.c_include_dirs.len > 0) {314 if (mod.c_include_dirs.len > 0) {
314 try w.writeAll(" .c_include_dirs = &.{");315 try w.writeAll(" .c_include_dirs = &.{");
315 for (mod.c_include_dirs, 0..) |item, j| {316 for (mod.c_include_dirs, 0..) |item, j| {
316 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)});317 try w.print(" \"{}\"", .{u.altStringEscape(item)});
317 if (j != mod.c_include_dirs.len - 1) try w.writeAll(",");318 if (j != mod.c_include_dirs.len - 1) try w.writeAll(",");
318 }319 }
319 try w.writeAll(" },\n");320 try w.writeAll(" },\n");
...@@ -321,7 +322,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:...@@ -321,7 +322,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
321 if (mod.c_source_files.len > 0) {322 if (mod.c_source_files.len > 0) {
322 try w.writeAll(" .c_source_files = &.{");323 try w.writeAll(" .c_source_files = &.{");
323 for (mod.c_source_files, 0..) |item, j| {324 for (mod.c_source_files, 0..) |item, j| {
324 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)});325 try w.print(" \"{}\"", .{u.altStringEscape(item)});
325 if (j != mod.c_source_files.len - 1) try w.writeAll(",");326 if (j != mod.c_source_files.len - 1) try w.writeAll(",");
326 }327 }
327 try w.writeAll(" },\n");328 try w.writeAll(" },\n");
...@@ -329,7 +330,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:...@@ -329,7 +330,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
329 if (mod.c_source_flags.len > 0) {330 if (mod.c_source_flags.len > 0) {
330 try w.writeAll(" .c_source_flags = &.{");331 try w.writeAll(" .c_source_flags = &.{");
331 for (mod.c_source_flags, 0..) |item, j| {332 for (mod.c_source_flags, 0..) |item, j| {
332 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item)});333 try w.print(" \"{}\"", .{u.altStringEscape(item)});
333 if (j != mod.c_source_flags.len - 1) try w.writeAll(",");334 if (j != mod.c_source_flags.len - 1) try w.writeAll(",");
334 }335 }
335 try w.writeAll(" },\n");336 try w.writeAll(" },\n");
...@@ -338,7 +339,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:...@@ -338,7 +339,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
338 try w.writeAll(" .system_libs = &.{");339 try w.writeAll(" .system_libs = &.{");
339 for (mod.deps, 0..) |item, j| {340 for (mod.deps, 0..) |item, j| {
340 if (!(item.type == .system_lib)) continue;341 if (!(item.type == .system_lib)) continue;
341 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item.name)});342 try w.print(" \"{}\"", .{u.altStringEscape(item.name)});
342 if (j != mod.deps.len - 1) try w.writeAll(",");343 if (j != mod.deps.len - 1) try w.writeAll(",");
343 }344 }
344 try w.writeAll(" },\n");345 try w.writeAll(" },\n");
...@@ -347,7 +348,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:...@@ -347,7 +348,7 @@ fn print_pkg_data_to(w: std.fs.File.Writer, alloc: std.mem.Allocator, cachepath:
347 try w.writeAll(" .frameworks = &.{");348 try w.writeAll(" .frameworks = &.{");
348 for (mod.deps, 0..) |item, j| {349 for (mod.deps, 0..) |item, j| {
349 if (!(item.type == .system_lib)) continue;350 if (!(item.type == .system_lib)) continue;
350 try w.print(" \"{}\"", .{std.zig.fmtEscapes(item.name)});351 try w.print(" \"{}\"", .{u.altStringEscape(item.name)});
351 if (j != mod.deps.len - 1) try w.writeAll(",");352 if (j != mod.deps.len - 1) try w.writeAll(",");
352 }353 }
353 try w.writeAll(" },\n");354 try w.writeAll(" },\n");
...@@ -376,7 +377,7 @@ fn contains_all(needles: []zigmod.Module, haystack: []const zigmod.Module) bool...@@ -376,7 +377,7 @@ fn contains_all(needles: []zigmod.Module, haystack: []const zigmod.Module) bool
376 return true;377 return true;
377}378}
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 {
380 try w.writeAll("struct {\n");381 try w.writeAll("struct {\n");
381 for (m.deps) |d| {382 for (m.deps) |d| {
382 if (d.main.len == 0) {383 if (d.main.len == 0) {
...@@ -391,7 +392,7 @@ fn print_pkgs(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module)...@@ -391,7 +392,7 @@ fn print_pkgs(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module)
391 try w.writeAll("}");392 try w.writeAll("}");
392}393}
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 {
395 for (m.deps) |d| {396 for (m.deps) |d| {
396 if (d.main.len == 0) {397 if (d.main.len == 0) {
397 continue;398 continue;
...@@ -400,7 +401,7 @@ fn print_imports(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Modu...@@ -400,7 +401,7 @@ fn print_imports(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Modu
400 continue;401 continue;
401 }402 }
402 const ident = try zig_name_from_pkg_name(alloc, d.name);403 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 });
404 }405 }
405}406}
406407
src/cmd/init.zig+21-19
...@@ -9,6 +9,7 @@ const ini = @import("ini");...@@ -9,6 +9,7 @@ const ini = @import("ini");
9const time = @import("time");9const time = @import("time");
10const extras = @import("extras");10const extras = @import("extras");
11const nio = @import("nio");11const nio = @import("nio");
12const nfs = @import("nfs");
1213
13const u = @import("./../util/funcs.zig");14const u = @import("./../util/funcs.zig");
14const common = @import("./../common.zig");15const common = @import("./../common.zig");
...@@ -25,9 +26,9 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -25,9 +26,9 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
25 std.debug.print("Press ^C at any time to quit.\n", .{});26 std.debug.print("Press ^C at any time to quit.\n", .{});
26 std.debug.print("\n", .{});27 std.debug.print("\n", .{});
2728
28 const stdout = std.io.getStdOut().writer();29 const stdout = nfs.stdout();
29 const stdin = std.io.getStdIn().reader();30 const stdin = nfs.stdin();
30 const cwd = std.fs.cwd();31 const cwd = nfs.cwd();
3132
32 const id = try inquirer.answer(stdout, "ID (this gets autogenerated):", string, "{s}", &u.random_string(48));33 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 {...@@ -38,12 +39,13 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
38 const flatname = try gpa.dupe(u8, name);39 const flatname = try gpa.dupe(u8, name);
39 _ = std.mem.replaceScalar(u8, flatname, '-', '_');40 _ = 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) {
42 error.CantFindMain => try std.mem.concat(gpa, u8, &.{ flatname, ".zig" }),43 error.CantFindMain => try std.mem.concat(gpa, u8, &.{ flatname, ".zig" }),
43 else => |ee| return ee,44 else => |ee| return ee,
44 }) else null;45 }) 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());
47 const license = try inquirer.forString(stdout, stdin, "license:", gpa, maybe_license_text);49 const license = try inquirer.forString(stdout, stdin, "license:", gpa, maybe_license_text);
4850
49 const description = try inquirer.forString(stdout, stdin, "description:", gpa, null);51 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 {...@@ -66,7 +68,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
66 true => {68 true => {
67 const file = try cwd.createFile("zigmod.yml", .{});69 const file = try cwd.createFile("zigmod.yml", .{});
68 defer file.close();70 defer file.close();
69 const w = file.writer();71 const w = file;
70 switch (ptype) {72 switch (ptype) {
71 .exe => try writeExeManifest(w, id, name, license, description),73 .exe => try writeExeManifest(w, id, name, license, description),
72 .lib => try writeLibManifest(w, id, name, license, description, entry.?),74 .lib => try writeLibManifest(w, id, name, license, description, entry.?),
...@@ -98,7 +100,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -98,7 +100,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
98100
99 const file = try cwd.createFile("LICENSE", .{});101 const file = try cwd.createFile("LICENSE", .{});
100 defer file.close();102 defer file.close();
101 const w = file.writer();103 const w = file;
102104
103 // properly format license text to fit within 80 columns105 // properly format license text to fit within 80 columns
104 var start: usize = 0;106 var start: usize = 0;
...@@ -140,12 +142,12 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -140,12 +142,12 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
140 const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitignore?", gpa);142 const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitignore?", gpa);
141 if (do) {143 if (do) {
142 const exists = try extras.doesFileExist(null, ".gitignore");144 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", .{}));
144 defer file.close();146 defer file.close();
145 const len = try file.getEndPos();147 const len = try file.getEndPos();
146 if (len > 0) try file.seekTo(len - 1);148 if (len > 0) try file.seekTo(len - 1);
147 const w = file.writer();149 const w = file;
148 if (len > 0 and (try file.reader().readByte()) != '\n') {150 if (len > 0 and (try file.readByte()) != '\n') {
149 try w.writeAll("\n");151 try w.writeAll("\n");
150 }152 }
151 if (!exists) try w.writeAll(".zig-cache\n");153 if (!exists) try w.writeAll(".zig-cache\n");
...@@ -162,12 +164,12 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -162,12 +164,12 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
162 const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitattributes?", gpa);164 const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitattributes?", gpa);
163 if (do) {165 if (do) {
164 const exists = try extras.doesFileExist(null, ".gitattributes");166 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", .{}));
166 defer file.close();168 defer file.close();
167 const len = try file.getEndPos();169 const len = try file.getEndPos();
168 if (len > 0) try file.seekTo(len - 1);170 if (len > 0) try file.seekTo(len - 1);
169 const w = file.writer();171 const w = file;
170 if (len > 0 and (try file.reader().readByte()) != '\n') {172 if (len > 0 and (try file.readByte()) != '\n') {
171 try w.writeAll("\n");173 try w.writeAll("\n");
172 }174 }
173 if (!exists) try w.writeAll("* text=auto\n");175 if (!exists) try w.writeAll("* text=auto\n");
...@@ -182,7 +184,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -182,7 +184,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
182 if (do) {184 if (do) {
183 const file = try cwd.createFile("build.zig", .{});185 const file = try cwd.createFile("build.zig", .{});
184 defer file.close();186 defer file.close();
185 const w = file.writer();187 const w = file;
186 switch (ptype) {188 switch (ptype) {
187 .exe => {189 .exe => {
188 try w.writeAll(190 try w.writeAll(
...@@ -249,7 +251,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -249,7 +251,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
249 if (do) {251 if (do) {
250 const file = try cwd.createFile(entry orelse "main.zig", .{});252 const file = try cwd.createFile(entry orelse "main.zig", .{});
251 defer file.close();253 defer file.close();
252 const w = file.writer();254 const w = file;
253 switch (ptype) {255 switch (ptype) {
254 .exe => {256 .exe => {
255 try w.print(257 try w.print(
...@@ -283,7 +285,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -283,7 +285,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
283 if (do) {285 if (do) {
284 const file = try cwd.createFile("test.zig", .{});286 const file = try cwd.createFile("test.zig", .{});
285 defer file.close();287 defer file.close();
286 const w = file.writer();288 const w = file;
287 try w.print(289 try w.print(
288 \\const std = @import("std");290 \\const std = @import("std");
289 \\const {s} = @import("{s}");291 \\const {s} = @import("{s}");
...@@ -301,7 +303,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -301,7 +303,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
301 {303 {
302 const alloc = gpa;304 const alloc = gpa;
303 const cachepath = try u.find_cachepath();305 const cachepath = try u.find_cachepath();
304 const dir = std.fs.cwd();306 const dir = nfs.cwd();
305307
306 var options = common.CollectOptions{308 var options = common.CollectOptions{
307 .log = true,309 .log = true,
...@@ -318,7 +320,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -318,7 +320,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
318 }320 }
319}321}
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 {
322 try w.print("id: {s}\n", .{id});324 try w.print("id: {s}\n", .{id});
323 try w.print("name: {s}\n", .{name});325 try w.print("name: {s}\n", .{name});
324 if (license) |_| try w.print("license: {s}\n", .{license.?});326 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...@@ -328,7 +330,7 @@ pub fn writeExeManifest(w: std.fs.File.Writer, id: string, name: string, license
328 try w.writeAll("root_dependencies:\n");330 try w.writeAll("root_dependencies:\n");
329}331}
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 {
332 try w.print("id: {s}\n", .{id});334 try w.print("id: {s}\n", .{id});
333 try w.print("name: {s}\n", .{name});335 try w.print("name: {s}\n", .{name});
334 try w.print("main: {s}\n", .{entry});336 try w.print("main: {s}\n", .{entry});
src/cmd/install.zig+7-6
...@@ -4,6 +4,7 @@ const gpa = std.heap.c_allocator;...@@ -4,6 +4,7 @@ const gpa = std.heap.c_allocator;
4const knownfolders = @import("known-folders");4const knownfolders = @import("known-folders");
5const extras = @import("extras");5const extras = @import("extras");
6const nio = @import("nio");6const nio = @import("nio");
7const nfs = @import("nfs");
78
8const zigmod = @import("./../lib.zig");9const zigmod = @import("./../lib.zig");
9const u = @import("./../util/funcs.zig");10const u = @import("./../util/funcs.zig");
...@@ -48,8 +49,8 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -48,8 +49,8 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
48 .for_build = false,49 .for_build = false,
49 };50 };
50 const clean_path = try dep.clean_path(gpa);51 const clean_path = try dep.clean_path(gpa);
51 const cachepath = try std.fs.path.join(gpa, &.{ cache, "zigmod", "deps" });52 const cachepath = try std.fs.path.joinZ(gpa, &.{ cache, "zigmod", "deps" });
52 const modpath = try std.fs.path.join(gpa, &.{ cachepath, clean_path });53 const modpath = try std.fs.path.joinZ(gpa, &.{ cachepath, clean_path });
53 std.log.debug("modpath: {s}", .{modpath});54 std.log.debug("modpath: {s}", .{modpath});
5455
55 if (!try extras.doesFolderExist(null, modpath)) {56 if (!try extras.doesFolderExist(null, modpath)) {
...@@ -58,14 +59,14 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -58,14 +59,14 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
58 try dep.type.update(gpa, modpath, "");59 try dep.type.update(gpa, modpath, "");
59 }60 }
6061
61 const moddir = try std.fs.cwd().openDir(modpath, .{});62 const moddir = try nfs.cwd().openDir(modpath, .{});
62 const ci = @import("./ci.zig");63 const ci = @import("./ci.zig");
63 try ci.do(gpa, cachepath, moddir);64 try ci.do(gpa, cachepath, moddir);
6465
65 const modfile = try zigmod.ModFile.from_dir(gpa, moddir, modpath);66 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_sv = 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 zigversion = try nio.fmt.allocPrint(gpa, "{s}", .{u.altSemanticVersion(zigversion_sv)});
68 const zigpath = try std.fs.path.join(gpa, &.{ datapath, "zig", zigversion, "zig" });69 const zigpath = try std.fs.path.joinZ(gpa, &.{ datapath, "zig", zigversion, "zig" });
6970
70 // zig build71 // zig build
71 const argv: []const string = &.{72 const argv: []const string = &.{
src/cmd/license.zig+6-5
...@@ -4,6 +4,7 @@ const string = []const u8;...@@ -4,6 +4,7 @@ const string = []const u8;
4const style = @import("ansi").style;4const style = @import("ansi").style;
5const licenses = @import("licenses");5const licenses = @import("licenses");
6const extras = @import("extras");6const extras = @import("extras");
7const nfs = @import("nfs");
78
8const zigmod = @import("../lib.zig");9const zigmod = @import("../lib.zig");
9const u = @import("./../util/funcs.zig");10const u = @import("./../util/funcs.zig");
...@@ -20,7 +21,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -20,7 +21,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
20 _ = args;21 _ = args;
2122
22 const cachepath = try u.find_cachepath();23 const cachepath = try u.find_cachepath();
23 const dir = std.fs.cwd();24 const dir = nfs.cwd();
2425
25 var options = common.CollectOptions{26 var options = common.CollectOptions{
26 .log = false,27 .log = false,
...@@ -28,10 +29,10 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -28,10 +29,10 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
28 .alloc = gpa,29 .alloc = gpa,
29 };30 };
3031
31 try do(cachepath, dir, &options, std.io.getStdOut());32 try do(cachepath, dir, &options, .stdout());
32}33}
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 {
35 const top_module = try common.collect_deps_deep(cachepath, dir, options);36 const top_module = try common.collect_deps_deep(cachepath, dir, options);
3637
37 var master_list = List.init(gpa);38 var master_list = List.init(gpa);
...@@ -71,8 +72,8 @@ pub fn do(cachepath: string, dir: std.fs.Dir, options: *common.CollectOptions, o...@@ -71,8 +72,8 @@ pub fn do(cachepath: string, dir: std.fs.Dir, options: *common.CollectOptions, o
71 try tracking_list.append(item);72 try tracking_list.append(item);
72 }73 }
7374
74 const istty = outfile.isTty();75 const istty = outfile.isatty();
75 const writer = outfile.writer();76 const writer = outfile;
76 const Bold = if (!istty) "" else style.Bold;77 const Bold = if (!istty) "" else style.Bold;
77 const Faint = if (!istty) "" else style.Faint;78 const Faint = if (!istty) "" else style.Faint;
78 const ResetIntensity = if (!istty) "" else style.ResetIntensity;79 const ResetIntensity = if (!istty) "" else style.ResetIntensity;
src/cmd/sum.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const gpa = std.heap.c_allocator;2const gpa = std.heap.c_allocator;
3const nfs = @import("nfs");
34
4const zigmod = @import("../lib.zig");5const zigmod = @import("../lib.zig");
5const u = @import("./../util/funcs.zig");6const u = @import("./../util/funcs.zig");
...@@ -13,7 +14,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -13,7 +14,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
13 _ = args;14 _ = args;
1415
15 const cachepath = try u.find_cachepath();16 const cachepath = try u.find_cachepath();
16 const dir = std.fs.cwd();17 const dir = nfs.cwd();
1718
18 var options = common.CollectOptions{19 var options = common.CollectOptions{
19 .log = false,20 .log = false,
...@@ -25,7 +26,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -25,7 +26,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
25 //26 //
26 const f = try dir.createFile("zigmod.sum", .{});27 const f = try dir.createFile("zigmod.sum", .{});
27 defer f.close();28 defer f.close();
28 const w = f.writer();29 const w = f;
2930
30 //31 //
31 var module_list = std.ArrayList(zigmod.Module).init(gpa);32 var module_list = std.ArrayList(zigmod.Module).init(gpa);
src/cmd/version.zig+2-1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const gpa = std.heap.c_allocator;2const gpa = std.heap.c_allocator;
3const builtin = @import("builtin");3const builtin = @import("builtin");
4const nfs = @import("nfs");
45
5const u = @import("./../util/funcs.zig");6const u = @import("./../util/funcs.zig");
67
...@@ -14,7 +15,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -14,7 +15,7 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
14 const root = @import("root");15 const root = @import("root");
15 const version = root.build_options.version;16 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 "";
18 gitversion = if (gitversion.len > 0) gitversion[0..9] else gitversion;19 gitversion = if (gitversion.len > 0) gitversion[0..9] else gitversion;
1920
20 const stdout = std.io.getStdOut();21 const stdout = std.io.getStdOut();
src/cmd/zpm/add.zig+3-2
...@@ -2,6 +2,7 @@ const std = @import("std");...@@ -2,6 +2,7 @@ const std = @import("std");
2const gpa = std.heap.c_allocator;2const gpa = std.heap.c_allocator;
3const zfetch = @import("zfetch");3const zfetch = @import("zfetch");
4const extras = @import("extras");4const extras = @import("extras");
5const nfs = @import("nfs");
56
6const zigmod = @import("../../lib.zig");7const zigmod = @import("../../lib.zig");
7const u = @import("./../../util/funcs.zig");8const u = @import("./../../util/funcs.zig");
...@@ -57,11 +58,11 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {...@@ -57,11 +58,11 @@ pub fn execute(self_name: []const u8, args: [][:0]u8) !void {
57 break :blk @intFromEnum(_req.status) == 200;58 break :blk @intFromEnum(_req.status) == 200;
58 };59 };
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 });
61 defer file.close();62 defer file.close();
62 try file.seekTo(try file.getEndPos());63 try file.seekTo(try file.getEndPos());
6364
64 const file_w = file.writer();65 const file_w = file;
65 try file_w.writeAll("\n");66 try file_w.writeAll("\n");
66 try file_w.print(" - src: git {s}\n", .{extras.trimSuffix(found.git, ".git")});67 try file_w.print(" - src: git {s}\n", .{extras.trimSuffix(found.git, ".git")});
67 if (!(has_zigdotmod or has_zigmodyml)) {68 if (!(has_zigdotmod or has_zigmodyml)) {
src/common.zig+49-40
...@@ -4,10 +4,13 @@ const builtin = @import("builtin");...@@ -4,10 +4,13 @@ const builtin = @import("builtin");
4const ansi = @import("ansi");4const ansi = @import("ansi");
5const extras = @import("extras");5const extras = @import("extras");
6const nio = @import("nio");6const nio = @import("nio");
7const nfs = @import("nfs");
78
8const zigmod = @import("./lib.zig");9const zigmod = @import("./lib.zig");
9const u = @import("./util/funcs.zig");10const u = @import("./util/funcs.zig");
1011
12const gpa = std.heap.c_allocator;
13
11//14//
12//15//
1316
...@@ -24,8 +27,8 @@ pub const CollectOptions = struct {...@@ -24,8 +27,8 @@ pub const CollectOptions = struct {
24 }27 }
25};28};
2629
27pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectOptions) !zigmod.Module {30pub fn collect_deps_deep(cachepath: [:0]const u8, mdir: nfs.Dir, options: *CollectOptions) !zigmod.Module {
28 try std.fs.cwd().makePath(cachepath);31 try nfs.cwd().makePath(cachepath);
2932
30 const m = try zigmod.ModFile.from_dir(options.alloc, mdir, ".");33 const m = try zigmod.ModFile.from_dir(options.alloc, mdir, ".");
31 try options.init();34 try options.init();
...@@ -58,8 +61,8 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO...@@ -58,8 +61,8 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO
58 };61 };
59}62}
6063
61pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, mdir_path: string, dtype: zigmod.Dep.Type, options: *CollectOptions) anyerror!zigmod.Module {64pub fn collect_deps(cachepath: [:0]const u8, mdir: nfs.Dir, mdir_path: string, dtype: zigmod.Dep.Type, options: *CollectOptions) anyerror!zigmod.Module {
62 try std.fs.cwd().makePath(cachepath);65 try nfs.cwd().makePath(cachepath);
6366
64 const m = try zigmod.ModFile.from_dir(options.alloc, mdir, mdir_path);67 const m = try zigmod.ModFile.from_dir(options.alloc, mdir, mdir_path);
65 var moduledeps = std.ArrayList(zigmod.Module).init(options.alloc);68 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...@@ -98,9 +101,9 @@ pub fn collect_pkgs(mod: zigmod.Module, list: *std.ArrayList(zigmod.Module)) any
98 }101 }
99}102}
100103
101pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !string {104pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ![:0]const u8 {
102 const p = try std.fs.path.join(options.alloc, &.{ cachepath, try d.clean_path(options.alloc) });105 const p = try std.fs.path.joinZ(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) });106 const pv = try std.fs.path.joinZ(options.alloc, &.{ cachepath, try d.clean_path_v(options.alloc) });
104107
105 const nocache = d.type.isLocal();108 const nocache = d.type.isLocal();
106 if (!nocache and extras.containsString(options.already_fetched.items, p)) return p;109 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) !...@@ -118,7 +121,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
118 switch (d.type) {121 switch (d.type) {
119 .local => {122 .local => {
120 if (!std.mem.endsWith(u8, d.main, ".zig")) {123 if (!std.mem.endsWith(u8, d.main, ".zig")) {
121 return d.main;124 return gpa.dupeZ(u8, d.main);
122 }125 }
123 return d.path;126 return d.path;
124 },127 },
...@@ -148,11 +151,11 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !...@@ -148,11 +151,11 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
148 u.fail("fetch: git: {s}: {s} {s} does not exist", .{ d.path, @tagName(vers.id), vers.string });151 u.fail("fetch: git: {s}: {s} {s} does not exist", .{ d.path, @tagName(vers.id), vers.string });
149 }152 }
150 if (builtin.os.tag != .windows and vers.id == .commit) {153 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, .{});
152 defer pvd.close();155 defer pvd.close();
153 try pvd.deleteTree(".git");156 try pvd.deleteTree(".git");
154 }157 }
155 var pvd = try std.fs.cwd().openDir(pv, .{ .iterate = true });158 var pvd = try nfs.cwd().openDir(pv, .{});
156 defer pvd.close();159 defer pvd.close();
157 try setTreeReadOnly(pvd, options.alloc);160 try setTreeReadOnly(pvd, options.alloc);
158 return pv;161 return pv;
...@@ -185,36 +188,38 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !...@@ -185,36 +188,38 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
185 if (try extras.doesFolderExist(null, pv)) {188 if (try extras.doesFolderExist(null, pv)) {
186 return pv;189 return pv;
187 }190 }
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 });
189 try d.type.pull(options.alloc, d.path, pv);192 try d.type.pull(options.alloc, d.path, pv);
190 if (try u.validate_hash(options.alloc, d.version, file_path)) {193 if (try u.validate_hash(options.alloc, d.version, file_path)) {
191 try std.fs.cwd().deleteFile(file_path);194 try nfs.cwd().deleteFile(file_path);
192 var pvd = try std.fs.cwd().openDir(pv, .{ .iterate = true });195 var pvd = try nfs.cwd().openDir(pv, .{});
193 defer pvd.close();196 defer pvd.close();
194 try setTreeReadOnly(pvd, options.alloc);197 try setTreeReadOnly(pvd, options.alloc);
195 return pv;198 return pv;
196 }199 }
197 try std.fs.cwd().deleteTree(pv);200 try nfs.cwd().deleteTree(pv);
198 u.fail("{s} does not match hash {s}", .{ d.path, d.version });201 u.fail("{s} does not match hash {s}", .{ d.path, d.version });
199 return p;202 return p;
200 }203 }
201 if (try extras.doesFolderExist(null, p)) {204 if (try extras.doesFolderExist(null, p)) {
202 try std.fs.cwd().deleteTree(p);205 try nfs.cwd().deleteTree(p);
203 }206 }
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);
205 try d.type.pull(options.alloc, d.path, p);210 try d.type.pull(options.alloc, d.path, p);
206 try std.fs.cwd().deleteFile(file_path);211 try nfs.cwd().deleteFile(file_path);
207 return p;212 return p;
208 },213 },
209 }214 }
210}215}
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 {
213 if (options.lock) |lock| {218 if (options.lock) |lock| {
214 for (lock) |item| {219 for (lock) |item| {
215 if (std.mem.eql(u8, item[0], try d.clean_path(options.alloc))) {220 if (std.mem.eql(u8, item[0], try d.clean_path(options.alloc))) {
216 d.type = std.meta.stringToEnum(zigmod.Dep.Type, item[1]).?;221 d.type = std.meta.stringToEnum(zigmod.Dep.Type, item[1]).?;
217 d.path = item[2];222 d.path = try gpa.dupeZ(u8, item[2]);
218 d.version = item[3];223 d.version = item[3];
219 break;224 break;
220 }225 }
...@@ -222,7 +227,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO...@@ -222,7 +227,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
222 }227 }
223 if (!d.is_for_this()) return null;228 if (!d.is_for_this()) return null;
224 const modpath = try get_modpath(cachepath, d.*, options);229 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
227 const nocache = d.type.isLocal();232 const nocache = d.type.isLocal();
228 if (!nocache) try options.already_fetched.append(modpath);233 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...@@ -249,11 +254,14 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
249 error.ManifestNotFound => {254 error.ManifestNotFound => {
250 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0 or d.keep) {255 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0 or d.keep) {
251 var mod_from = try zigmod.Module.from(options.alloc, d.*, cachepath, options);256 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 }
253 if (mod_from.is_for_this()) return mod_from;261 if (mod_from.is_for_this()) return mod_from;
254 return null;262 return null;
255 }263 }
256 const moddirO = try std.fs.cwd().openDir(modpath, .{});264 const moddirO = try nfs.cwd().openDir(modpath, .{});
257 const tryname = try u.detect_pkgname(options.alloc, d.name, modpath);265 const tryname = try u.detect_pkgname(options.alloc, d.name, modpath);
258 const trymain: ?string = u.detct_mainfile(options.alloc, d.main, moddirO, tryname) catch |err| switch (err) {266 const trymain: ?string = u.detct_mainfile(options.alloc, d.main, moddirO, tryname) catch |err| switch (err) {
259 error.CantFindMain => null,267 error.CantFindMain => null,
...@@ -263,7 +271,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO...@@ -263,7 +271,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
263 d.*.name = tryname;271 d.*.name = tryname;
264 d.*.main = trymain.?;272 d.*.main = trymain.?;
265 var mod_from = try zigmod.Module.from(options.alloc, d.*, cachepath, options);273 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];
267 if (mod_from.is_for_this()) return mod_from;275 if (mod_from.is_for_this()) return mod_from;
268 return null;276 return null;
269 }277 }
...@@ -274,7 +282,10 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO...@@ -274,7 +282,10 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
274 dd.dep = d.*;282 dd.dep = d.*;
275 dd.for_build = d.for_build;283 dd.for_build = d.for_build;
276 const save = dd;284 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 }
278 if (std.mem.eql(u8, &dd.id, &zigmod.Dep.EMPTY)) dd.id = u.random_string(48);289 if (std.mem.eql(u8, &dd.id, &zigmod.Dep.EMPTY)) dd.id = u.random_string(48);
279 if (d.name.len > 0) dd.name = d.name;290 if (d.name.len > 0) dd.name = d.name;
280 if (d.main.len > 0) dd.main = d.main;291 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...@@ -290,16 +301,16 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
290 }301 }
291}302}
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 {
294 var map = std.StringHashMap(string).init(alloc);305 var map = std.StringHashMap(string).init(alloc);
295 defer map.deinit();306 defer map.deinit();
296307
297 for (dirs) |dir_path| {308 for (dirs) |dir_path| {
298 const dir = try mdir.openDir(dir_path, .{ .iterate = true });309 const dir = try mdir.openDirC(dir_path, .{});
299 var walker = try dir.walk(alloc);310 var walker = try dir.walk(alloc);
300 defer walker.deinit();311 defer walker.deinit();
301 while (try walker.next()) |p| {312 while (try walker.next()) |p| {
302 if (p.kind == .directory) {313 if (p.type == .DIR) {
303 continue;314 continue;
304 }315 }
305 const path = try alloc.dupe(u8, p.path);316 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....@@ -315,21 +326,19 @@ pub fn gen_files_package(alloc: std.mem.Allocator, cachepath: string, mdir: std.
315 const destdir = mdir;326 const destdir = mdir;
316 const rff = try destdir.createFile(fname, .{});327 const rff = try destdir.createFile(fname, .{});
317 defer rff.close();328 defer rff.close();
318 const w = rff.writer();
319 var iter = map.iterator();329 var iter = map.iterator();
320 while (iter.next()) |item| {330 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.*) });
322 }332 }
323}333}
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 {
326 var list = std.ArrayList([4]string).init(alloc);336 var list = std.ArrayList([4]string).init(alloc);
327 const max = std.math.maxInt(usize);337 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{};
329 var f = try dir.openFile("zigmod.lock", .{});339 var f = try dir.openFile("zigmod.lock", .{});
330 defer f.close();340 defer f.close();
331 var br = std.io.bufferedReader(f.reader());341 var r = nio.BufferedReader(4096, nfs.File).init(f);
332 const r = br.reader();
333 var i: usize = 0;342 var i: usize = 0;
334 var v: usize = 1;343 var v: usize = 1;
335 while (try r.readUntilDelimiterOrEofAlloc(alloc, '\n', max)) |line| : (i += 1) {344 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...@@ -351,7 +360,7 @@ pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]str
351 var iter = std.mem.splitScalar(u8, line, ' ');360 var iter = std.mem.splitScalar(u8, line, ' ');
352 const asdep = zigmod.Dep{361 const asdep = zigmod.Dep{
353 .type = std.meta.stringToEnum(zigmod.Dep.Type, iter.next().?).?,362 .type = std.meta.stringToEnum(zigmod.Dep.Type, iter.next().?).?,
354 .path = iter.next().?,363 .path = try gpa.dupeZ(u8, iter.next().?),
355 .version = iter.next().?,364 .version = iter.next().?,
356 .id = zigmod.Dep.EMPTY,365 .id = zigmod.Dep.EMPTY,
357 .name = "",366 .name = "",
...@@ -374,17 +383,17 @@ pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]str...@@ -374,17 +383,17 @@ pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]str
374 return list.toOwnedSlice();383 return list.toOwnedSlice();
375}384}
376385
377fn setTreeReadOnly(dir: std.fs.Dir, alloc: std.mem.Allocator) !void {386fn setTreeReadOnly(dir: nfs.Dir, alloc: std.mem.Allocator) !void {
378 var walker = try dir.walk(alloc);387 var walker = try dir.walk(alloc);
379 defer walker.deinit();388 defer walker.deinit();
380389
381 while (try walker.next()) |entry| {390 while (try walker.next()) |entry| {
382 if (entry.kind != .file) continue;391 if (entry.type != .REG) continue;
383 var file = try dir.openFile(entry.path, .{});392 var file = try dir.openFile(entry.path, .{});
384 defer file.close();393 defer file.close();
385 var metadata = try file.metadata();394 const stat = try file.stat();
386 var perms = metadata.permissions();395 var mode = stat.mode;
387 perms.setReadOnly(true);396 mode |= ~@as(nfs.File.Mode, 0o222);
388 try file.setPermissions(perms);397 try file.chmod(mode);
389 }398 }
390}399}
src/util/dep.zig+6-6
...@@ -14,7 +14,7 @@ pub const Dep = struct {...@@ -14,7 +14,7 @@ pub const Dep = struct {
14 const Self = @This();14 const Self = @This();
1515
16 type: Type,16 type: Type,
17 path: string,17 path: [:0]const u8,
18 id: [48]u8,18 id: [48]u8,
19 name: string,19 name: string,
20 main: string,20 main: string,
...@@ -33,17 +33,17 @@ pub const Dep = struct {...@@ -33,17 +33,17 @@ pub const Dep = struct {
3333
34 pub const Type = @import("./dep_type.zig").DepType;34 pub const Type = @import("./dep_type.zig").DepType;
3535
36 pub fn clean_path(self: Dep, alloc: std.mem.Allocator) !string {36 pub fn clean_path(self: Dep, alloc: std.mem.Allocator) ![:0]const u8 {
37 if (self.type == .local) {37 if (self.type == .local) {
38 return self.path;38 return self.path;
39 }39 }
40 var p = self.path;40 var p: string = self.path;
41 p = extras.trimPrefix(p, "http://");41 p = extras.trimPrefix(p, "http://");
42 p = extras.trimPrefix(p, "https://");42 p = extras.trimPrefix(p, "https://");
43 p = extras.trimPrefix(p, "git://");43 p = extras.trimPrefix(p, "git://");
44 p = extras.trimSuffix(p, ".git");44 p = extras.trimSuffix(p, ".git");
45 p = try std.mem.join(alloc, "/", &.{ @tagName(self.type), p });45 const np = try std.mem.joinZ(alloc, "/", &.{ @tagName(self.type), p });
46 return p;46 return np;
47 }47 }
4848
49 pub fn clean_path_v(self: Dep, alloc: std.mem.Allocator) !string {49 pub fn clean_path_v(self: Dep, alloc: std.mem.Allocator) !string {
...@@ -65,7 +65,7 @@ pub const Dep = struct {...@@ -65,7 +65,7 @@ pub const Dep = struct {
65 return true;65 return true;
66 }66 }
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 {
69 if (self.version.len == 0) {69 if (self.version.len == 0) {
70 return try self.type.exact_version(alloc, dpath);70 return try self.type.exact_version(alloc, dpath);
71 }71 }
src/util/dep_type.zig+5-4
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;2const string = []const u8;
3const nio = @import("nio");3const nio = @import("nio");
4const nfs = @import("nfs");
45
5const u = @import("./funcs.zig");6const u = @import("./funcs.zig");
67
...@@ -17,7 +18,7 @@ pub const DepType = enum {...@@ -17,7 +18,7 @@ pub const DepType = enum {
17 http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol18 http, // https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol
1819
19 // zig fmt: on20 // 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 {
21 switch (self) {22 switch (self) {
22 .local => {},23 .local => {},
23 .system_lib => {},24 .system_lib => {},
...@@ -29,7 +30,7 @@ pub const DepType = enum {...@@ -29,7 +30,7 @@ pub const DepType = enum {
29 u.assert((try u.run_cmd(alloc, null, &.{ "hg", "clone", rpath, dpath })) == 0, "hg clone {s} failed", .{rpath});30 u.assert((try u.run_cmd(alloc, null, &.{ "hg", "clone", rpath, dpath })) == 0, "hg clone {s} failed", .{rpath});
30 },31 },
31 .http => {32 .http => {
32 try std.fs.cwd().makePath(dpath);33 try nfs.cwd().makePath(dpath);
33 u.assert((try u.run_cmd(alloc, dpath, &.{ "wget", rpath })) == 0, "wget {s} failed", .{rpath});34 u.assert((try u.run_cmd(alloc, dpath, &.{ "wget", rpath })) == 0, "wget {s} failed", .{rpath});
34 const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").? + 1 ..];35 const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").? + 1 ..];
35 if (std.mem.endsWith(u8, f, ".zip")) {36 if (std.mem.endsWith(u8, f, ".zip")) {
...@@ -62,8 +63,8 @@ pub const DepType = enum {...@@ -62,8 +63,8 @@ pub const DepType = enum {
62 }63 }
63 }64 }
6465
65 pub fn exact_version(self: DepType, alloc: std.mem.Allocator, mpath: string) !string {66 pub fn exact_version(self: DepType, alloc: std.mem.Allocator, mpath: [:0]const u8) !string {
66 var mdir = try std.fs.cwd().openDir(mpath, .{});67 var mdir = try nfs.cwd().openDir(mpath, .{});
67 defer mdir.close();68 defer mdir.close();
68 return switch (self) {69 return switch (self) {
69 .local => "",70 .local => "",
src/util/funcs.zig+57-22
...@@ -44,10 +44,10 @@ pub fn split(alloc: std.mem.Allocator, in: string, delim: u8) ![]string {...@@ -44,10 +44,10 @@ pub fn split(alloc: std.mem.Allocator, in: string, delim: u8) ![]string {
44 return list.toOwnedSlice();44 return list.toOwnedSlice();
45}45}
4646
47pub fn file_list(alloc: std.mem.Allocator, dpath: string) ![]const string {47pub fn file_list(alloc: std.mem.Allocator, dpath: [:0]const u8) ![]const string {
48 var dir = try std.fs.cwd().openDir(dpath, .{ .iterate = true });48 var dir = try nfs.cwd().openDir(dpath, .{});
49 defer dir.close();49 defer dir.close();
50 return try extras.fileList(alloc, dir);50 return try extras.fileList(alloc, dir.to_std());
51}51}
5252
53pub fn run_cmd_raw(alloc: std.mem.Allocator, dir: ?string, args: []const string) !std.process.Child.RunResult {53pub 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 {...@@ -121,11 +121,11 @@ pub const HashFn = enum {
121 sha512,121 sha512,
122};122};
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 {
125 const hash = parse_split(HashFn, '-').do(input) catch return false;125 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, .{});
127 defer file.close();127 defer file.close();
128 const data = try file.reader().readAllAlloc(alloc, gb);128 const data = try file.readAllAlloc(alloc, gb);
129 const expected = hash.string;129 const expected = hash.string;
130 const actual = switch (hash.id) {130 const actual = switch (hash.id) {
131 .blake3 => &try do_hash(std.crypto.hash.Blake3, data),131 .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 {...@@ -144,9 +144,8 @@ pub fn do_hash(comptime algo: type, data: string) ![algo.digest_length * 2]u8 {
144}144}
145145
146/// Returns the result of running `git rev-parse HEAD`146/// Returns the result of running `git rev-parse HEAD`
147pub fn git_rev_HEAD(alloc: std.mem.Allocator, dir: std.fs.Dir) !string {147pub fn git_rev_HEAD(alloc: std.mem.Allocator, dir: nfs.Dir) !string {
148 const ndir: nfs.Dir = .{ .fd = @enumFromInt(dir.fd) };148 var dirg = try dir.openDir(".git", .{});
149 var dirg = try ndir.openDir(".git", .{});
150 defer dirg.close();149 defer dirg.close();
151 const commitid = try git.getHEAD(alloc, dirg);150 const commitid = try git.getHEAD(alloc, dirg);
152 return if (commitid) |_| commitid.?.id else error.NotAGitRepo;151 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...@@ -158,9 +157,9 @@ pub fn slice(comptime T: type, input: []const T, from: usize, to: usize) []const
158 return input[f..t];157 return input[f..t];
159}158}
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 {
162 if (override.len > 0) return override;161 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, .{});
164 const dpath = try dirO.realpathAlloc(gpa, ".");163 const dpath = try dirO.realpathAlloc(gpa, ".");
165 const splitP = try split(alloc, dpath, std.fs.path.sep);164 const splitP = try split(alloc, dpath, std.fs.path.sep);
166 var name = splitP[splitP.len - 1];165 var name = splitP[splitP.len - 1];
...@@ -169,28 +168,28 @@ pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: string) !...@@ -169,28 +168,28 @@ pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: string) !
169 return name;168 return name;
170}169}
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 {
173 if (override.len > 0) {172 if (override.len > 0) {
174 if (try extras.doesFileExist(dir, override)) {173 if (try extras.doesFileExist(dir.to_std(), override)) {
175 if (std.mem.endsWith(u8, override, ".zig")) {174 if (std.mem.endsWith(u8, override, ".zig")) {
176 return override;175 return override;
177 }176 }
178 }177 }
179 }178 }
180 const namedotzig = try std.mem.concat(alloc, u8, &.{ name, ".zig" });179 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)) {
182 return namedotzig;181 return namedotzig;
183 }182 }
184 if (try extras.doesFileExist(dir, "lib.zig")) {183 if (try extras.doesFileExist(dir.to_std(), "lib.zig")) {
185 return "lib.zig";184 return "lib.zig";
186 }185 }
187 if (try extras.doesFileExist(dir, "main.zig")) {186 if (try extras.doesFileExist(dir.to_std(), "main.zig")) {
188 return "main.zig";187 return "main.zig";
189 }188 }
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" }))) {
191 return "src/lib.zig";190 return "src/lib.zig";
192 }191 }
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" }))) {
194 return "src/main.zig";193 return "src/main.zig";
195 }194 }
196 return error.CantFindMain;195 return error.CantFindMain;
...@@ -214,12 +213,48 @@ pub fn indexOfAfter(haystack: string, needle: u8, after: usize) ?usize {...@@ -214,12 +213,48 @@ pub fn indexOfAfter(haystack: string, needle: u8, after: usize) ?usize {
214 return null;213 return null;
215}214}
216215
217pub fn find_cachepath() !string {216pub fn find_cachepath() ![:0]const u8 {
218 const haystack = try std.fs.cwd().realpathAlloc(gpa, ".");217 const haystack = try nfs.cwd().realpathAlloc(gpa, ".");
219 const needle = "/.zigmod/deps";218 const needle = "/.zigmod/deps";
220219
221 if (std.mem.indexOf(u8, haystack, needle)) |index| {220 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]);
223 }222 }
224 return try std.fs.path.join(gpa, &.{ haystack, ".zigmod", "deps" });223 return try std.fs.path.joinZ(gpa, &.{ haystack, ".zigmod", "deps" });
225}224}
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");...@@ -4,6 +4,7 @@ const yaml = @import("yaml");
4const extras = @import("extras");4const extras = @import("extras");
5const root = @import("root");5const root = @import("root");
6const build_options = root.build_options;6const build_options = root.build_options;
7const nfs = @import("nfs");
78
8const zigmod = @import("../lib.zig");9const zigmod = @import("../lib.zig");
9const u = @import("funcs.zig");10const u = @import("funcs.zig");
...@@ -11,6 +12,7 @@ const u = @import("funcs.zig");...@@ -11,6 +12,7 @@ const u = @import("funcs.zig");
11//12//
12//13//
1314
15const gpa = std.heap.c_allocator;
14const b = 1;16const b = 1;
15const kb = b * 1024;17const kb = b * 1024;
16const mb = kb * 1024;18const mb = kb * 1024;
...@@ -32,10 +34,10 @@ pub const ModFile = struct {...@@ -32,10 +34,10 @@ pub const ModFile = struct {
32 builddeps: []zigmod.Dep,34 builddeps: []zigmod.Dep,
33 min_zig_version: ?std.SemanticVersion,35 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 } {
36 return .{ "zig.mod", dir.openFile("zig.mod", ops) catch |err| switch (err) {38 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) {39 error.ENOENT => return .{ "zigmod.yml", dir.openFile("zigmod.yml", ops) catch |err2| switch (err2) {
38 error.FileNotFound => return error.ManifestNotFound,40 error.ENOENT => return error.ManifestNotFound,
39 else => |e2| return e2,41 else => |e2| return e2,
40 } },42 } },
41 else => |e| return e,43 else => |e| return e,
...@@ -43,13 +45,13 @@ pub const ModFile = struct {...@@ -43,13 +45,13 @@ pub const ModFile = struct {
43 }45 }
4446
45 pub fn init(alloc: std.mem.Allocator) !Self {47 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(), ".");
47 }49 }
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 {
50 const file_path, const file = try openFile(dir, .{});52 const file_path, const file = try openFile(dir, .{});
51 defer file.close();53 defer file.close();
52 const input = try file.reader().readAllAlloc(alloc, mb);54 const input = try file.readAllAlloc(alloc, mb);
53 const doc = try yaml.parse(alloc, input);55 const doc = try yaml.parse(alloc, input);
54 return from_mapping(alloc, doc.mapping, dir_path, file_path);56 return from_mapping(alloc, doc.mapping, dir_path, file_path);
55 }57 }
...@@ -101,14 +103,14 @@ pub const ModFile = struct {...@@ -101,14 +103,14 @@ pub const ModFile = struct {
101 if (dep_seq != .sequence) continue;103 if (dep_seq != .sequence) continue;
102 for (dep_seq.sequence) |item| {104 for (dep_seq.sequence) |item| {
103 var dtype: string = undefined;105 var dtype: string = undefined;
104 var path: string = undefined;106 var path: [:0]const u8 = undefined;
105 var version: ?string = null;107 var version: ?string = null;
106 var main = item.mapping.get_string("main") orelse "";108 var main = item.mapping.get_string("main") orelse "";
107109
108 if (item.mapping.get("src")) |val| {110 if (item.mapping.get("src")) |val| {
109 var src_iter = std.mem.tokenizeScalar(u8, val.string, ' ');111 var src_iter = std.mem.tokenizeScalar(u8, val.string, ' ');
110 dtype = src_iter.next().?;112 dtype = src_iter.next().?;
111 path = src_iter.next().?;113 path = try gpa.dupeZ(u8, src_iter.next().?);
112 if (src_iter.next()) |dver| {114 if (src_iter.next()) |dver| {
113 version = dver;115 version = dver;
114 }116 }
src/util/module.zig+9-8
...@@ -4,6 +4,7 @@ const builtin = @import("builtin");...@@ -4,6 +4,7 @@ const builtin = @import("builtin");
4const yaml = @import("yaml");4const yaml = @import("yaml");
5const extras = @import("extras");5const extras = @import("extras");
6const nio = @import("nio");6const nio = @import("nio");
7const nfs = @import("nfs");
78
8const zigmod = @import("../lib.zig");9const zigmod = @import("../lib.zig");
9const u = @import("funcs.zig");10const u = @import("funcs.zig");
...@@ -24,14 +25,14 @@ pub const Module = struct {...@@ -24,14 +25,14 @@ pub const Module = struct {
24 except_os: []const string = &.{},25 except_os: []const string = &.{},
25 yaml: ?yaml.Mapping,26 yaml: ?yaml.Mapping,
26 deps: []Module,27 deps: []Module,
27 clean_path: string,28 clean_path: [:0]const u8,
28 dep: ?zigmod.Dep,29 dep: ?zigmod.Dep,
29 for_build: bool = false,30 for_build: bool = false,
30 min_zig_version: ?std.SemanticVersion,31 min_zig_version: ?std.SemanticVersion,
3132
32 pub const ROOT: [48]u8 = ("root" ++ (" " ** 44)).*;33 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 {
35 var moddeps = std.ArrayList(Module).init(alloc);36 var moddeps = std.ArrayList(Module).init(alloc);
36 errdefer moddeps.deinit();37 errdefer moddeps.deinit();
3738
...@@ -68,7 +69,7 @@ pub const Module = struct {...@@ -68,7 +69,7 @@ pub const Module = struct {
68 }69 }
6970
70 pub fn get_hash(self: Module, alloc: std.mem.Allocator, cdpath: string) !string {71 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
73 var file_list_2 = std.ArrayList(string).init(alloc);74 var file_list_2 = std.ArrayList(string).init(alloc);
74 errdefer file_list_2.deinit();75 errdefer file_list_2.deinit();
...@@ -88,10 +89,10 @@ pub const Module = struct {...@@ -88,10 +89,10 @@ pub const Module = struct {
8889
89 var h = std.crypto.hash.Blake3.init(.{});90 var h = std.crypto.hash.Blake3.init(.{});
90 for (file_list_2.items) |item| {91 for (file_list_2.items) |item| {
91 const abs_path = try std.fs.path.join(alloc, &.{ cdpath, self.clean_path, item });92 const abs_path = try std.fs.path.joinZ(alloc, &.{ cdpath, self.clean_path, item });
92 const file = try std.fs.cwd().openFile(abs_path, .{});93 const file = try nfs.cwd().openFile(abs_path, .{});
93 defer file.close();94 defer file.close();
94 const input = try file.reader().readAllAlloc(alloc, u.mb * 100);95 const input = try file.readAllAlloc(alloc, u.mb * 100);
95 h.update(input);96 h.update(input);
96 }97 }
97 var out: [32]u8 = undefined;98 var out: [32]u8 = undefined;
...@@ -164,13 +165,13 @@ pub const Module = struct {...@@ -164,13 +165,13 @@ pub const Module = struct {
164 return false;165 return false;
165 }166 }
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 {
168 return switch (self.type) {169 return switch (self.type) {
169 .local => "",170 .local => "",
170 .system_lib => "",171 .system_lib => "",
171 .framework => "",172 .framework => "",
172 else => |sub| {173 else => |sub| {
173 var cdir = try std.fs.cwd().openDir(cachepath, .{});174 var cdir = try nfs.cwd().openDir(cachepath, .{});
174 defer cdir.close();175 defer cdir.close();
175 var mdir = try cdir.openDir(self.clean_path, .{});176 var mdir = try cdir.openDir(self.clean_path, .{});
176 defer mdir.close();177 defer mdir.close();
zigmod.lock+5-5
...@@ -5,7 +5,7 @@ git https://github.com/nektro/iguanaTLS commit-3450aaf3ca47986540e2b0258c2affc45...@@ -5,7 +5,7 @@ git https://github.com/nektro/iguanaTLS commit-3450aaf3ca47986540e2b0258c2affc45
5git https://github.com/nektro/zfetch commit-40d141bf7db81f05a83cce5f2edc4b14e41a5c345git https://github.com/nektro/zfetch commit-40d141bf7db81f05a83cce5f2edc4b14e41a5c34
6git https://github.com/nektro/zig-ansi commit-5f89211a749aef6bf518889c0467ceb24825c0556git https://github.com/nektro/zig-ansi commit-5f89211a749aef6bf518889c0467ceb24825c055
7git https://github.com/nektro/zig-detect-license commit-a1a066da88dab50873a56f0349dc12dc765420777git https://github.com/nektro/zig-detect-license commit-a1a066da88dab50873a56f0349dc12dc76542077
8git https://github.com/nektro/zig-extras commit-c2c581aa6a38438dd9ed8da0f59019691c5dd45d8git https://github.com/nektro/zig-extras commit-b3457b31a1d1ea2c19c5d0b007c903d3e80add40
9git https://github.com/nektro/zig-git commit-2b3f83cd341764f979969603e4f77e62f353b6a39git https://github.com/nektro/zig-git commit-2b3f83cd341764f979969603e4f77e62f353b6a3
10git https://github.com/nektro/zig-inquirer commit-4cddefa42744d61067567b0b36b5d2bb376e5ae310git https://github.com/nektro/zig-inquirer commit-4cddefa42744d61067567b0b36b5d2bb376e5ae3
11git https://github.com/nektro/zig-intrusive-parser commit-a31b480914d15f3d13cdfb586aac950c73beebdd11git https://github.com/nektro/zig-intrusive-parser commit-a31b480914d15f3d13cdfb586aac950c73beebdd
...@@ -13,13 +13,13 @@ git https://github.com/nektro/zig-json commit-428aa8a29e370fdb2e6739d5676b1de415...@@ -13,13 +13,13 @@ git https://github.com/nektro/zig-json commit-428aa8a29e370fdb2e6739d5676b1de415
13git https://github.com/nektro/zig-leven commit-618eddde4ffbc6d34100e4bc6aa654d41161537a13git https://github.com/nektro/zig-leven commit-618eddde4ffbc6d34100e4bc6aa654d41161537a
14git https://github.com/nektro/zig-licenses commit-16cef5e32b3f8bbcf1064c599615290a720b654714git https://github.com/nektro/zig-licenses commit-16cef5e32b3f8bbcf1064c599615290a720b6547
15git https://github.com/nektro/zig-licenses-text commit-ba0f00dfb23d28c301e4b54d0a278def2c38dc7b15git https://github.com/nektro/zig-licenses-text commit-ba0f00dfb23d28c301e4b54d0a278def2c38dc7b
16git https://github.com/nektro/zig-nfs commit-18b00c5c5d25e230ff4f3ea07fadb2a1d54a773d16git https://github.com/nektro/zig-nfs commit-c855473c8bd15dd24a4e8b6911b7e006062004ba
17git https://github.com/nektro/zig-nio commit-c1da2e8a31858880eb3e4cfcf12de0a86561762317git https://github.com/nektro/zig-nio commit-c1da2e8a31858880eb3e4cfcf12de0a865617623
18git https://github.com/nektro/zig-sys-darwin commit-c5c1b35492224b0ed8d2570c8e71702947b1e40018git https://github.com/nektro/zig-sys-darwin commit-3265d1f06418eb0360d753c12116310a14b97bde
19git https://github.com/nektro/zig-sys-linux commit-9edefde5fcf96894b6aa4ab60241940bba65debf19git https://github.com/nektro/zig-sys-linux commit-f0b155d3627f8c19868be1b2f15d71cda908b575
20git https://github.com/nektro/zig-time commit-0f4db4c980146e4a3fc86a9a9070452a25ff931720git https://github.com/nektro/zig-time commit-0f4db4c980146e4a3fc86a9a9070452a25ff9317
21git https://github.com/nektro/zig-tracer commit-3a5fdea4ffd387a53ac2a42fb503557cdbe2069621git https://github.com/nektro/zig-tracer commit-3a5fdea4ffd387a53ac2a42fb503557cdbe20696
22git https://github.com/nektro/zig-yaml commit-b1ebd056b9afaaa719cb55359c610455ffe0449922git https://github.com/nektro/zig-yaml commit-00e899bec815bc2b49c6e5a72a7cfeeda673e133
23git https://github.com/truemedian/hzzp commit-ab212bd208f0eb54d85861679677c5e3dc9bb54323git https://github.com/truemedian/hzzp commit-ab212bd208f0eb54d85861679677c5e3dc9bb543
24git https://github.com/madler/zlib tag-v1.3.224git https://github.com/madler/zlib tag-v1.3.2
25git https://github.com/yaml/libyaml tag-0.2.525git https://github.com/yaml/libyaml tag-0.2.5