diff --git a/src/cmd/ci.zig b/src/cmd/ci.zig index c3ec0d50a04bec951a05c5623c534e29c2dcc1dd..6a8d0f7adc613e68f77e4b4031876c0313a4d0d3 100644 --- a/src/cmd/ci.zig +++ b/src/cmd/ci.zig @@ -2,6 +2,7 @@ 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"); @@ -24,7 +25,7 @@ pub fn do(cachepath: string, dir: std.fs.Dir) !void { }; const top_module = try common.collect_deps_deep(cachepath, dir, &options); - var list = std.ArrayList(u.Module).init(gpa); + var list = std.ArrayList(zigmod.Module).init(gpa); try common.collect_pkgs(top_module, &list); const fetch = @import("./fetch.zig"); diff --git a/src/cmd/fetch.zig b/src/cmd/fetch.zig index 3b430846065ffad9860749972359e8bcbdcd3f99..64a73054d68bced9ecc5c2dfb6733bd8a24458b8 100644 --- a/src/cmd/fetch.zig +++ b/src/cmd/fetch.zig @@ -2,6 +2,7 @@ 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"); @@ -26,7 +27,7 @@ pub fn execute(args: [][]u8) !void { }; const top_module = try common.collect_deps_deep(cachepath, dir, &options); - var list = std.ArrayList(u.Module).init(gpa); + var list = std.ArrayList(zigmod.Module).init(gpa); try common.collect_pkgs(top_module, &list); try create_depszig(cachepath, dir, top_module, &list); @@ -38,7 +39,7 @@ pub fn execute(args: [][]u8) !void { try diff_lockfile(); } -pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: u.Module, list: *std.ArrayList(u.Module)) !void { +pub fn create_depszig(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(); @@ -92,14 +93,14 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: u.Module, try w.writeAll("};\n\n"); try w.writeAll("pub const package_data = struct {\n"); - var duped = std.ArrayList(u.Module).init(gpa); + var duped = std.ArrayList(zigmod.Module).init(gpa); for (list.items) |mod| { if (mod.is_sys_lib) { continue; } try duped.append(mod); } - try print_pkg_data_to(w, &duped, &std.ArrayList(u.Module).init(gpa)); + try print_pkg_data_to(w, &duped, &std.ArrayList(zigmod.Module).init(gpa)); try w.writeAll("};\n\n"); try w.writeAll("pub const packages = "); @@ -115,7 +116,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: u.Module, try w.writeAll("};\n"); } -fn create_lockfile(list: *std.ArrayList(u.Module), path: string, dir: std.fs.Dir) !void { +fn create_lockfile(list: *std.ArrayList(zigmod.Module), path: string, dir: std.fs.Dir) !void { const fl = try dir.createFile("zigmod.lock", .{}); defer fl.close(); @@ -225,7 +226,7 @@ fn diff_printchange(comptime testt: string, comptime replacement: string, item: return false; } -fn print_dirs(w: std.fs.File.Writer, list: []const u.Module) !void { +fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module) !void { for (list) |mod| { if (mod.is_sys_lib) continue; if (std.mem.eql(u8, mod.id, "root")) { @@ -236,7 +237,7 @@ fn print_dirs(w: std.fs.File.Writer, list: []const u.Module) !void { } } -fn print_deps(w: std.fs.File.Writer, m: u.Module) !void { +fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void { try w.writeAll("&[_]Package{\n"); for (m.deps) |d| { if (d.main.len == 0) { @@ -247,7 +248,7 @@ fn print_deps(w: std.fs.File.Writer, m: u.Module) !void { try w.writeAll("}"); } -fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(u.Module), done: *std.ArrayList(u.Module)) !void { +fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Module), done: *std.ArrayList(zigmod.Module)) !void { var len: usize = notdone.items.len; while (notdone.items.len > 0) { for (notdone.items) |mod, i| { @@ -328,16 +329,16 @@ fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(u.Module), d } /// returns if all of the zig modules in needles are in haystack -fn contains_all(needles: []u.Module, haystack: []const u.Module) bool { +fn contains_all(needles: []zigmod.Module, haystack: []const zigmod.Module) bool { for (needles) |item| { - if (item.main.len > 0 and !u.list_contains_gen(u.Module, haystack, item)) { + if (item.main.len > 0 and !u.list_contains_gen(zigmod.Module, haystack, item)) { return false; } } return true; } -fn print_pkgs(w: std.fs.File.Writer, m: u.Module) !void { +fn print_pkgs(w: std.fs.File.Writer, m: zigmod.Module) !void { try w.writeAll("struct {\n"); for (m.deps) |d| { if (d.main.len == 0) { @@ -349,7 +350,7 @@ fn print_pkgs(w: std.fs.File.Writer, m: u.Module) !void { try w.writeAll("}"); } -fn print_imports(w: std.fs.File.Writer, m: u.Module, path: string) !void { +fn print_imports(w: std.fs.File.Writer, m: zigmod.Module, path: string) !void { for (m.deps) |d| { if (d.main.len == 0) { continue; diff --git a/src/cmd/license.zig b/src/cmd/license.zig index 19e508bbda12a9e5621f8345803db6bdade0e798..a4aab2fc3289083758b69dc2815fe0b0544039ac 100644 --- a/src/cmd/license.zig +++ b/src/cmd/license.zig @@ -4,11 +4,12 @@ const gpa = std.heap.c_allocator; const style = @import("ansi").style; const licenses = @import("licenses"); +const zigmod = @import("../lib.zig"); const u = @import("./../util/index.zig"); const common = @import("./../common.zig"); -const Module = u.Module; -const List = std.ArrayList(u.Module); +const Module = zigmod.Module; +const List = std.ArrayList(zigmod.Module); const Map = std.StringArrayHashMap(*List); // Inspired by: diff --git a/src/cmd/sum.zig b/src/cmd/sum.zig index f4850f5db53b899039cceacd333b29524443d249..78492e8390b5db761d054bfb761979f6f4f40a8f 100644 --- a/src/cmd/sum.zig +++ b/src/cmd/sum.zig @@ -1,6 +1,7 @@ const std = @import("std"); const gpa = std.heap.c_allocator; +const zigmod = @import("../lib.zig"); const u = @import("./../util/index.zig"); const common = @import("./../common.zig"); @@ -25,7 +26,7 @@ pub fn execute(args: [][]u8) !void { const w = f.writer(); // - var module_list = std.ArrayList(u.Module).init(gpa); + var module_list = std.ArrayList(zigmod.Module).init(gpa); try common.collect_pkgs(top_module, &module_list); for (module_list.items) |m| { diff --git a/src/common.zig b/src/common.zig index 8adc396b01ef4484c0a32a9754333f77bf625cd5..e3b166ffae0c451b9e3b4658eabf736b3f7d5c15 100644 --- a/src/common.zig +++ b/src/common.zig @@ -29,10 +29,10 @@ pub const CollectOptions = struct { } }; -pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectOptions) !u.Module { +pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectOptions) !zigmod.Module { const m = try zigmod.ModFile.from_dir(gpa, mdir); try options.init(); - var moduledeps = std.ArrayList(u.Module).init(gpa); + var moduledeps = std.ArrayList(zigmod.Module).init(gpa); defer moduledeps.deinit(); if (m.root_files.len > 0) { try std.fs.cwd().makePath(".zigmod/deps/files"); @@ -44,7 +44,7 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO try moduledeps.append(founddep); } } - return u.Module{ + return zigmod.Module{ .is_sys_lib = false, .id = "root", .name = "root", @@ -56,9 +56,9 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO }; } -pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOptions) anyerror!u.Module { +pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOptions) anyerror!zigmod.Module { const m = try zigmod.ModFile.from_dir(gpa, mdir); - var moduledeps = std.ArrayList(u.Module).init(gpa); + var moduledeps = std.ArrayList(zigmod.Module).init(gpa); defer moduledeps.deinit(); if (m.files.len > 0) { try std.fs.cwd().makePath(".zigmod/deps/files"); @@ -69,7 +69,7 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOption try moduledeps.append(founddep); } } - return u.Module{ + return zigmod.Module{ .is_sys_lib = false, .id = m.id, .name = m.name, @@ -84,8 +84,8 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOption }; } -pub fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void { - if (u.list_contains_gen(u.Module, list.items, mod)) { +pub fn collect_pkgs(mod: zigmod.Module, list: *std.ArrayList(zigmod.Module)) anyerror!void { + if (u.list_contains_gen(zigmod.Module, list.items, mod)) { return; } try list.append(mod); @@ -198,7 +198,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! } } -pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectOptions) anyerror!?u.Module { +pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectOptions) anyerror!?zigmod.Module { if (options.lock) |lock| { for (lock) |item| { if (std.mem.eql(u8, item[0], try d.clean_path())) { @@ -217,14 +217,14 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO switch (d.type) { .system_lib => { - return u.Module{ + return zigmod.Module{ .is_sys_lib = true, .id = try u.do_hash(std.crypto.hash.sha3.Sha3_384, d.path), .name = d.path, .only_os = d.only_os, .except_os = d.except_os, .main = "", - .deps = &[_]u.Module{}, + .deps = &[_]zigmod.Module{}, .clean_path = d.path, .yaml = null, .dep = d.*, @@ -234,7 +234,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO var dd = try collect_deps(cachepath, moddir, options) catch |e| switch (e) { error.FileNotFound => { if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { - var mod_from = try u.Module.from(d.*, cachepath, options); + var mod_from = try zigmod.Module.from(d.*, cachepath, options); if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..]; if (mod_from.is_for_this()) return mod_from; return null; @@ -248,7 +248,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO if (trymain) |_| { d.*.name = tryname; d.*.main = trymain.?; - var mod_from = try u.Module.from(d.*, cachepath, options); + var mod_from = try zigmod.Module.from(d.*, cachepath, options); if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..]; if (mod_from.is_for_this()) return mod_from; return null; @@ -276,7 +276,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO } } -pub fn add_files_package(pkg_name: string, mdir: std.fs.Dir, dirs: []const string) !u.Module { +pub fn add_files_package(pkg_name: string, mdir: std.fs.Dir, dirs: []const string) !zigmod.Module { const destination = ".zigmod/deps/files"; const fname = try std.mem.join(gpa, "", &.{ pkg_name, ".zig" }); diff --git a/src/lib.zig b/src/lib.zig index dcacf761f3697744821cb70c25f3bbf9420367d5..f4b43cdcaebd38b2e104ab777d4cff89b533d731 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -26,3 +26,4 @@ pub fn deinit() void { pub const DepType = @import("./util/dep_type.zig").DepType; pub const Dep = @import("./util/dep.zig").Dep; pub const ModFile = @import("./util/modfile.zig").ModFile; +pub const Module = @import("./util/module.zig").Module; diff --git a/src/util/index.zig b/src/util/index.zig index 5b2294e6af433a6f7a882a27618fe1272d3eacd4..0efc73cdd4d1d899293a229dca6e05ed4ed5034b 100644 --- a/src/util/index.zig +++ b/src/util/index.zig @@ -1,2 +1 @@ usingnamespace @import("./funcs.zig"); -usingnamespace @import("./module.zig");