authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 02:43:49 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 02:43:49 -07:00
logd55b67f873b850892dc08f2f5346f95cc3d3fedd
tree454d078dfa7ccd1d6f36b72d790c987f88d4844e
parent70ce68b8e7b7f00821d74b4f559ef80bfacdaed4

move Module to lib entry point


7 files changed, 35 insertions(+), 31 deletions(-)

src/cmd/ci.zig+2-1
......@@ -2,6 +2,7 @@ const std = @import("std");
22const string = []const u8;
33const gpa = std.heap.c_allocator;
44
5const zigmod = @import("../lib.zig");
56const u = @import("./../util/index.zig");
67const common = @import("./../common.zig");
78
......@@ -24,7 +25,7 @@ pub fn do(cachepath: string, dir: std.fs.Dir) !void {
2425 };
2526 const top_module = try common.collect_deps_deep(cachepath, dir, &options);
2627
27 var list = std.ArrayList(u.Module).init(gpa);
28 var list = std.ArrayList(zigmod.Module).init(gpa);
2829 try common.collect_pkgs(top_module, &list);
2930
3031 const fetch = @import("./fetch.zig");
src/cmd/fetch.zig+13-12
......@@ -2,6 +2,7 @@ const std = @import("std");
22const string = []const u8;
33const gpa = std.heap.c_allocator;
44
5const zigmod = @import("../lib.zig");
56const u = @import("./../util/index.zig");
67const common = @import("./../common.zig");
78
......@@ -26,7 +27,7 @@ pub fn execute(args: [][]u8) !void {
2627 };
2728 const top_module = try common.collect_deps_deep(cachepath, dir, &options);
2829
29 var list = std.ArrayList(u.Module).init(gpa);
30 var list = std.ArrayList(zigmod.Module).init(gpa);
3031 try common.collect_pkgs(top_module, &list);
3132
3233 try create_depszig(cachepath, dir, top_module, &list);
......@@ -38,7 +39,7 @@ pub fn execute(args: [][]u8) !void {
3839 try diff_lockfile();
3940}
4041
41pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: u.Module, list: *std.ArrayList(u.Module)) !void {
42pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Module, list: *std.ArrayList(zigmod.Module)) !void {
4243 const f = try dir.createFile("deps.zig", .{});
4344 defer f.close();
4445
......@@ -92,14 +93,14 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: u.Module,
9293 try w.writeAll("};\n\n");
9394
9495 try w.writeAll("pub const package_data = struct {\n");
95 var duped = std.ArrayList(u.Module).init(gpa);
96 var duped = std.ArrayList(zigmod.Module).init(gpa);
9697 for (list.items) |mod| {
9798 if (mod.is_sys_lib) {
9899 continue;
99100 }
100101 try duped.append(mod);
101102 }
102 try print_pkg_data_to(w, &duped, &std.ArrayList(u.Module).init(gpa));
103 try print_pkg_data_to(w, &duped, &std.ArrayList(zigmod.Module).init(gpa));
103104 try w.writeAll("};\n\n");
104105
105106 try w.writeAll("pub const packages = ");
......@@ -115,7 +116,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: u.Module,
115116 try w.writeAll("};\n");
116117}
117118
118fn create_lockfile(list: *std.ArrayList(u.Module), path: string, dir: std.fs.Dir) !void {
119fn create_lockfile(list: *std.ArrayList(zigmod.Module), path: string, dir: std.fs.Dir) !void {
119120 const fl = try dir.createFile("zigmod.lock", .{});
120121 defer fl.close();
121122
......@@ -225,7 +226,7 @@ fn diff_printchange(comptime testt: string, comptime replacement: string, item:
225226 return false;
226227}
227228
228fn print_dirs(w: std.fs.File.Writer, list: []const u.Module) !void {
229fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module) !void {
229230 for (list) |mod| {
230231 if (mod.is_sys_lib) continue;
231232 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 {
236237 }
237238}
238239
239fn print_deps(w: std.fs.File.Writer, m: u.Module) !void {
240fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void {
240241 try w.writeAll("&[_]Package{\n");
241242 for (m.deps) |d| {
242243 if (d.main.len == 0) {
......@@ -247,7 +248,7 @@ fn print_deps(w: std.fs.File.Writer, m: u.Module) !void {
247248 try w.writeAll("}");
248249}
249250
250fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(u.Module), done: *std.ArrayList(u.Module)) !void {
251fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Module), done: *std.ArrayList(zigmod.Module)) !void {
251252 var len: usize = notdone.items.len;
252253 while (notdone.items.len > 0) {
253254 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
328329}
329330
330331/// returns if all of the zig modules in needles are in haystack
331fn contains_all(needles: []u.Module, haystack: []const u.Module) bool {
332fn contains_all(needles: []zigmod.Module, haystack: []const zigmod.Module) bool {
332333 for (needles) |item| {
333 if (item.main.len > 0 and !u.list_contains_gen(u.Module, haystack, item)) {
334 if (item.main.len > 0 and !u.list_contains_gen(zigmod.Module, haystack, item)) {
334335 return false;
335336 }
336337 }
337338 return true;
338339}
339340
340fn print_pkgs(w: std.fs.File.Writer, m: u.Module) !void {
341fn print_pkgs(w: std.fs.File.Writer, m: zigmod.Module) !void {
341342 try w.writeAll("struct {\n");
342343 for (m.deps) |d| {
343344 if (d.main.len == 0) {
......@@ -349,7 +350,7 @@ fn print_pkgs(w: std.fs.File.Writer, m: u.Module) !void {
349350 try w.writeAll("}");
350351}
351352
352fn print_imports(w: std.fs.File.Writer, m: u.Module, path: string) !void {
353fn print_imports(w: std.fs.File.Writer, m: zigmod.Module, path: string) !void {
353354 for (m.deps) |d| {
354355 if (d.main.len == 0) {
355356 continue;
src/cmd/license.zig+3-2
......@@ -4,11 +4,12 @@ const gpa = std.heap.c_allocator;
44const style = @import("ansi").style;
55const licenses = @import("licenses");
66
7const zigmod = @import("../lib.zig");
78const u = @import("./../util/index.zig");
89const common = @import("./../common.zig");
910
10const Module = u.Module;
11const List = std.ArrayList(u.Module);
11const Module = zigmod.Module;
12const List = std.ArrayList(zigmod.Module);
1213const Map = std.StringArrayHashMap(*List);
1314
1415// Inspired by:
src/cmd/sum.zig+2-1
......@@ -1,6 +1,7 @@
11const std = @import("std");
22const gpa = std.heap.c_allocator;
33
4const zigmod = @import("../lib.zig");
45const u = @import("./../util/index.zig");
56const common = @import("./../common.zig");
67
......@@ -25,7 +26,7 @@ pub fn execute(args: [][]u8) !void {
2526 const w = f.writer();
2627
2728 //
28 var module_list = std.ArrayList(u.Module).init(gpa);
29 var module_list = std.ArrayList(zigmod.Module).init(gpa);
2930 try common.collect_pkgs(top_module, &module_list);
3031
3132 for (module_list.items) |m| {
src/common.zig+14-14
......@@ -29,10 +29,10 @@ pub const CollectOptions = struct {
2929 }
3030};
3131
32pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectOptions) !u.Module {
32pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectOptions) !zigmod.Module {
3333 const m = try zigmod.ModFile.from_dir(gpa, mdir);
3434 try options.init();
35 var moduledeps = std.ArrayList(u.Module).init(gpa);
35 var moduledeps = std.ArrayList(zigmod.Module).init(gpa);
3636 defer moduledeps.deinit();
3737 if (m.root_files.len > 0) {
3838 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
4444 try moduledeps.append(founddep);
4545 }
4646 }
47 return u.Module{
47 return zigmod.Module{
4848 .is_sys_lib = false,
4949 .id = "root",
5050 .name = "root",
......@@ -56,9 +56,9 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO
5656 };
5757}
5858
59pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOptions) anyerror!u.Module {
59pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOptions) anyerror!zigmod.Module {
6060 const m = try zigmod.ModFile.from_dir(gpa, mdir);
61 var moduledeps = std.ArrayList(u.Module).init(gpa);
61 var moduledeps = std.ArrayList(zigmod.Module).init(gpa);
6262 defer moduledeps.deinit();
6363 if (m.files.len > 0) {
6464 try std.fs.cwd().makePath(".zigmod/deps/files");
......@@ -69,7 +69,7 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOption
6969 try moduledeps.append(founddep);
7070 }
7171 }
72 return u.Module{
72 return zigmod.Module{
7373 .is_sys_lib = false,
7474 .id = m.id,
7575 .name = m.name,
......@@ -84,8 +84,8 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOption
8484 };
8585}
8686
87pub fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void {
88 if (u.list_contains_gen(u.Module, list.items, mod)) {
87pub fn collect_pkgs(mod: zigmod.Module, list: *std.ArrayList(zigmod.Module)) anyerror!void {
88 if (u.list_contains_gen(zigmod.Module, list.items, mod)) {
8989 return;
9090 }
9191 try list.append(mod);
......@@ -198,7 +198,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
198198 }
199199}
200200
201pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectOptions) anyerror!?u.Module {
201pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectOptions) anyerror!?zigmod.Module {
202202 if (options.lock) |lock| {
203203 for (lock) |item| {
204204 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
217217
218218 switch (d.type) {
219219 .system_lib => {
220 return u.Module{
220 return zigmod.Module{
221221 .is_sys_lib = true,
222222 .id = try u.do_hash(std.crypto.hash.sha3.Sha3_384, d.path),
223223 .name = d.path,
224224 .only_os = d.only_os,
225225 .except_os = d.except_os,
226226 .main = "",
227 .deps = &[_]u.Module{},
227 .deps = &[_]zigmod.Module{},
228228 .clean_path = d.path,
229229 .yaml = null,
230230 .dep = d.*,
......@@ -234,7 +234,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
234234 var dd = try collect_deps(cachepath, moddir, options) catch |e| switch (e) {
235235 error.FileNotFound => {
236236 if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) {
237 var mod_from = try u.Module.from(d.*, cachepath, options);
237 var mod_from = try zigmod.Module.from(d.*, cachepath, options);
238238 if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..];
239239 if (mod_from.is_for_this()) return mod_from;
240240 return null;
......@@ -248,7 +248,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
248248 if (trymain) |_| {
249249 d.*.name = tryname;
250250 d.*.main = trymain.?;
251 var mod_from = try u.Module.from(d.*, cachepath, options);
251 var mod_from = try zigmod.Module.from(d.*, cachepath, options);
252252 if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..];
253253 if (mod_from.is_for_this()) return mod_from;
254254 return null;
......@@ -276,7 +276,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO
276276 }
277277}
278278
279pub fn add_files_package(pkg_name: string, mdir: std.fs.Dir, dirs: []const string) !u.Module {
279pub fn add_files_package(pkg_name: string, mdir: std.fs.Dir, dirs: []const string) !zigmod.Module {
280280 const destination = ".zigmod/deps/files";
281281 const fname = try std.mem.join(gpa, "", &.{ pkg_name, ".zig" });
282282
src/lib.zig+1
......@@ -26,3 +26,4 @@ pub fn deinit() void {
2626pub const DepType = @import("./util/dep_type.zig").DepType;
2727pub const Dep = @import("./util/dep.zig").Dep;
2828pub const ModFile = @import("./util/modfile.zig").ModFile;
29pub const Module = @import("./util/module.zig").Module;
src/util/index.zig-1
......@@ -1,2 +1 @@
11usingnamespace @import("./funcs.zig");
2usingnamespace @import("./module.zig");