diff --git a/src/cmd/aquila/install.zig b/src/cmd/aquila/install.zig index e425c12f0f3623bc518d230717ffa16f7d7b9902..51abdaaa2e68286b32215cda5cb02d92bc20b99e 100644 --- a/src/cmd/aquila/install.zig +++ b/src/cmd/aquila/install.zig @@ -60,7 +60,7 @@ pub fn execute(args: [][]u8) !void { // zigmod ci const ci = @import("../ci.zig"); - try ci.do(modpath, moddir); + try ci.do(gpa, modpath, moddir); // zig build const argv: []const string = &.{ diff --git a/src/cmd/ci.zig b/src/cmd/ci.zig index db2f78efcfaa0dd9ebb049264195a15a00811f14..6b9e8979e1daedcfb7bca83545a8950f05b01df3 100644 --- a/src/cmd/ci.zig +++ b/src/cmd/ci.zig @@ -1,6 +1,5 @@ const std = @import("std"); const string = []const u8; -const gpa = std.heap.c_allocator; const zigmod = @import("../lib.zig"); const u = @import("./../util/index.zig"); @@ -12,23 +11,24 @@ const common = @import("./../common.zig"); pub fn execute(args: [][]u8) !void { _ = args; + const gpa = std.heap.c_allocator; const cachepath = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" }); const dir = std.fs.cwd(); - try do(cachepath, dir); + try do(gpa, cachepath, dir); } -pub fn do(cachepath: string, dir: std.fs.Dir) !void { +pub fn do(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.Dir) !void { var options = common.CollectOptions{ .log = true, .update = false, - .lock = try common.parse_lockfile(gpa, dir), - .alloc = gpa, + .lock = try common.parse_lockfile(alloc, dir), + .alloc = alloc, }; const top_module = try common.collect_deps_deep(cachepath, dir, &options); - var list = std.ArrayList(zigmod.Module).init(gpa); + var list = std.ArrayList(zigmod.Module).init(alloc); try common.collect_pkgs(top_module, &list); const fetch = @import("./fetch.zig"); - try fetch.create_depszig(cachepath, dir, top_module, &list); + try fetch.create_depszig(alloc, cachepath, dir, top_module, &list); } diff --git a/src/cmd/fetch.zig b/src/cmd/fetch.zig index 5b06a5215230abda735d0f4d85e44c86f185c306..1ccd74bbac5a0a3fce051c1563056223d6f384f8 100644 --- a/src/cmd/fetch.zig +++ b/src/cmd/fetch.zig @@ -1,13 +1,11 @@ const std = @import("std"); const string = []const u8; -const gpa = std.heap.c_allocator; const zigmod = @import("../lib.zig"); const u = @import("./../util/index.zig"); const common = @import("./../common.zig"); const ansi = @import("ansi"); - const root = @import("root"); const build_options = if (@hasDecl(root, "build_options")) root.build_options else struct {}; const bootstrap = if (@hasDecl(build_options, "bootstrap")) build_options.bootstrap else false; @@ -17,6 +15,7 @@ const bootstrap = if (@hasDecl(build_options, "bootstrap")) build_options.bootst pub fn execute(args: [][]u8) !void { // + const gpa = std.heap.c_allocator; const cachepath = try std.fs.path.join(gpa, &.{ ".zigmod", "deps" }); const dir = std.fs.cwd(); const should_update = !(args.len >= 1 and std.mem.eql(u8, args[0], "--no-update")); @@ -31,16 +30,16 @@ pub fn execute(args: [][]u8) !void { var list = std.ArrayList(zigmod.Module).init(gpa); try common.collect_pkgs(top_module, &list); - try create_depszig(cachepath, dir, top_module, &list); + try create_depszig(gpa, cachepath, dir, top_module, &list); if (bootstrap) return; - try create_lockfile(&list, cachepath, dir); + try create_lockfile(gpa, &list, cachepath, dir); - try diff_lockfile(); + try diff_lockfile(gpa); } -pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Module, list: *std.ArrayList(zigmod.Module)) !void { +pub fn create_depszig(alloc: std.mem.Allocator, cachepath: string, dir: std.fs.Dir, top_module: zigmod.Module, list: *std.ArrayList(zigmod.Module)) !void { const f = try dir.createFile("deps.zig", .{}); defer f.close(); @@ -98,14 +97,14 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Mod try w.writeAll("};\n\n"); try w.writeAll("pub const package_data = struct {\n"); - var duped = std.ArrayList(zigmod.Module).init(gpa); + var duped = std.ArrayList(zigmod.Module).init(alloc); for (list.items) |mod| { if (mod.is_sys_lib) { continue; } try duped.append(mod); } - try print_pkg_data_to(w, &duped, &std.ArrayList(zigmod.Module).init(gpa)); + try print_pkg_data_to(w, &duped, &std.ArrayList(zigmod.Module).init(alloc)); try w.writeAll("};\n\n"); try w.writeAll("pub const packages = "); @@ -113,15 +112,15 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Mod try w.writeAll(";\n\n"); try w.writeAll("pub const pkgs = "); - try print_pkgs(w, top_module); + try print_pkgs(alloc, w, top_module); try w.writeAll(";\n\n"); try w.writeAll("pub const imports = struct {\n"); - try print_imports(w, top_module, cachepath); + try print_imports(alloc, w, top_module, cachepath); try w.writeAll("};\n"); } -fn create_lockfile(list: *std.ArrayList(zigmod.Module), path: string, dir: std.fs.Dir) !void { +fn create_lockfile(alloc: std.mem.Allocator, list: *std.ArrayList(zigmod.Module), path: string, dir: std.fs.Dir) !void { const fl = try dir.createFile("zigmod.lock", .{}); defer fl.close(); @@ -133,7 +132,7 @@ fn create_lockfile(list: *std.ArrayList(zigmod.Module), path: string, dir: std.f continue; } if (md.type == .system_lib) continue; - const mpath = try std.fs.path.join(gpa, &.{ path, m.clean_path }); + const mpath = try std.fs.path.join(alloc, &.{ path, m.clean_path }); const version = try md.exact_version(mpath); try wl.print("{s} {s} {s}\n", .{ @tagName(md.type), md.path, version }); } @@ -145,25 +144,25 @@ const DiffChange = struct { to: string, }; -fn diff_lockfile() !void { +fn diff_lockfile(alloc: std.mem.Allocator) !void { const max = std.math.maxInt(usize); if (try u.does_folder_exist(".git")) { - const result = try u.run_cmd_raw(gpa, null, &.{ "git", "diff", "zigmod.lock" }); + const result = try u.run_cmd_raw(alloc, null, &.{ "git", "diff", "zigmod.lock" }); const r = std.io.fixedBufferStream(result.stdout).reader(); - while (try r.readUntilDelimiterOrEofAlloc(gpa, '\n', max)) |line| { + while (try r.readUntilDelimiterOrEofAlloc(alloc, '\n', max)) |line| { if (std.mem.startsWith(u8, line, "@@")) break; } - var rems = std.ArrayList(string).init(gpa); - var adds = std.ArrayList(string).init(gpa); - while (try r.readUntilDelimiterOrEofAlloc(gpa, '\n', max)) |line| { + var rems = std.ArrayList(string).init(alloc); + var adds = std.ArrayList(string).init(alloc); + while (try r.readUntilDelimiterOrEofAlloc(alloc, '\n', max)) |line| { if (line[0] == ' ') continue; if (line[0] == '-') try rems.append(line[1..]); if (line[0] == '+') if (line[1] == '2') continue else try adds.append(line[1..]); } - var changes = std.StringHashMap(DiffChange).init(gpa); + var changes = std.StringHashMap(DiffChange).init(alloc); var didbreak = false; var i: usize = 0; @@ -349,7 +348,7 @@ fn contains_all(needles: []zigmod.Module, haystack: []const zigmod.Module) bool return true; } -fn print_pkgs(w: std.fs.File.Writer, m: zigmod.Module) !void { +fn print_pkgs(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module) !void { try w.writeAll("struct {\n"); for (m.deps) |d| { if (d.main.len == 0) { @@ -358,13 +357,13 @@ fn print_pkgs(w: std.fs.File.Writer, m: zigmod.Module) !void { if (d.for_build) { continue; } - const ident = try zig_name_from_pkg_name(d.name); + const ident = try zig_name_from_pkg_name(alloc, d.name); try w.print(" pub const {s} = package_data._{s};\n", .{ ident, d.id[0..12] }); } try w.writeAll("}"); } -fn print_imports(w: std.fs.File.Writer, m: zigmod.Module, path: string) !void { +fn print_imports(alloc: std.mem.Allocator, w: std.fs.File.Writer, m: zigmod.Module, path: string) !void { for (m.deps) |d| { if (d.main.len == 0) { continue; @@ -372,15 +371,15 @@ fn print_imports(w: std.fs.File.Writer, m: zigmod.Module, path: string) !void { if (!d.for_build) { continue; } - const ident = try zig_name_from_pkg_name(d.name); + const ident = try zig_name_from_pkg_name(alloc, d.name); try w.print(" pub const {s} = @import(\"{}/{}/{s}\");\n", .{ ident, std.zig.fmtEscapes(path), std.zig.fmtEscapes(d.clean_path), d.main }); } } -fn zig_name_from_pkg_name(name: string) !string { +fn zig_name_from_pkg_name(alloc: std.mem.Allocator, name: string) !string { var legal = name; - legal = try std.mem.replaceOwned(u8, gpa, legal, "-", "_"); - legal = try std.mem.replaceOwned(u8, gpa, legal, "/", "_"); - legal = try std.mem.replaceOwned(u8, gpa, legal, ".", "_"); + legal = try std.mem.replaceOwned(u8, alloc, legal, "-", "_"); + legal = try std.mem.replaceOwned(u8, alloc, legal, "/", "_"); + legal = try std.mem.replaceOwned(u8, alloc, legal, ".", "_"); return legal; }