| author | |
| committer | |
| log | d55b67f873b850892dc08f2f5346f95cc3d3fedd |
| tree | 454d078dfa7ccd1d6f36b72d790c987f88d4844e |
| parent | 70ce68b8e7b7f00821d74b4f559ef80bfacdaed4 |
7 files changed, 35 insertions(+), 31 deletions(-)
src/cmd/ci.zig+2-1| ... | ... | @@ -2,6 +2,7 @@ const std = @import("std"); |
| 2 | 2 | const string = []const u8; |
| 3 | 3 | const gpa = std.heap.c_allocator; |
| 4 | 4 | |
| 5 | const zigmod = @import("../lib.zig"); | |
| 5 | 6 | const u = @import("./../util/index.zig"); |
| 6 | 7 | const common = @import("./../common.zig"); |
| 7 | 8 | |
| ... | ... | @@ -24,7 +25,7 @@ pub fn do(cachepath: string, dir: std.fs.Dir) !void { |
| 24 | 25 | }; |
| 25 | 26 | const top_module = try common.collect_deps_deep(cachepath, dir, &options); |
| 26 | 27 | |
| 27 | var list = std.ArrayList(u.Module).init(gpa); | |
| 28 | var list = std.ArrayList(zigmod.Module).init(gpa); | |
| 28 | 29 | try common.collect_pkgs(top_module, &list); |
| 29 | 30 | |
| 30 | 31 | const fetch = @import("./fetch.zig"); |
src/cmd/fetch.zig+13-12| ... | ... | @@ -2,6 +2,7 @@ const std = @import("std"); |
| 2 | 2 | const string = []const u8; |
| 3 | 3 | const gpa = std.heap.c_allocator; |
| 4 | 4 | |
| 5 | const zigmod = @import("../lib.zig"); | |
| 5 | 6 | const u = @import("./../util/index.zig"); |
| 6 | 7 | const common = @import("./../common.zig"); |
| 7 | 8 | |
| ... | ... | @@ -26,7 +27,7 @@ pub fn execute(args: [][]u8) !void { |
| 26 | 27 | }; |
| 27 | 28 | const top_module = try common.collect_deps_deep(cachepath, dir, &options); |
| 28 | 29 | |
| 29 | var list = std.ArrayList(u.Module).init(gpa); | |
| 30 | var list = std.ArrayList(zigmod.Module).init(gpa); | |
| 30 | 31 | try common.collect_pkgs(top_module, &list); |
| 31 | 32 | |
| 32 | 33 | try create_depszig(cachepath, dir, top_module, &list); |
| ... | ... | @@ -38,7 +39,7 @@ pub fn execute(args: [][]u8) !void { |
| 38 | 39 | try diff_lockfile(); |
| 39 | 40 | } |
| 40 | 41 | |
| 41 | pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: u.Module, list: *std.ArrayList(u.Module)) !void { | |
| 42 | pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: zigmod.Module, list: *std.ArrayList(zigmod.Module)) !void { | |
| 42 | 43 | const f = try dir.createFile("deps.zig", .{}); |
| 43 | 44 | defer f.close(); |
| 44 | 45 | |
| ... | ... | @@ -92,14 +93,14 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: u.Module, |
| 92 | 93 | try w.writeAll("};\n\n"); |
| 93 | 94 | |
| 94 | 95 | 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); | |
| 96 | 97 | for (list.items) |mod| { |
| 97 | 98 | if (mod.is_sys_lib) { |
| 98 | 99 | continue; |
| 99 | 100 | } |
| 100 | 101 | try duped.append(mod); |
| 101 | 102 | } |
| 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)); | |
| 103 | 104 | try w.writeAll("};\n\n"); |
| 104 | 105 | |
| 105 | 106 | try w.writeAll("pub const packages = "); |
| ... | ... | @@ -115,7 +116,7 @@ pub fn create_depszig(cachepath: string, dir: std.fs.Dir, top_module: u.Module, |
| 115 | 116 | try w.writeAll("};\n"); |
| 116 | 117 | } |
| 117 | 118 | |
| 118 | fn create_lockfile(list: *std.ArrayList(u.Module), path: string, dir: std.fs.Dir) !void { | |
| 119 | fn create_lockfile(list: *std.ArrayList(zigmod.Module), path: string, dir: std.fs.Dir) !void { | |
| 119 | 120 | const fl = try dir.createFile("zigmod.lock", .{}); |
| 120 | 121 | defer fl.close(); |
| 121 | 122 | |
| ... | ... | @@ -225,7 +226,7 @@ fn diff_printchange(comptime testt: string, comptime replacement: string, item: |
| 225 | 226 | return false; |
| 226 | 227 | } |
| 227 | 228 | |
| 228 | fn print_dirs(w: std.fs.File.Writer, list: []const u.Module) !void { | |
| 229 | fn print_dirs(w: std.fs.File.Writer, list: []const zigmod.Module) !void { | |
| 229 | 230 | for (list) |mod| { |
| 230 | 231 | if (mod.is_sys_lib) continue; |
| 231 | 232 | 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 { |
| 236 | 237 | } |
| 237 | 238 | } |
| 238 | 239 | |
| 239 | fn print_deps(w: std.fs.File.Writer, m: u.Module) !void { | |
| 240 | fn print_deps(w: std.fs.File.Writer, m: zigmod.Module) !void { | |
| 240 | 241 | try w.writeAll("&[_]Package{\n"); |
| 241 | 242 | for (m.deps) |d| { |
| 242 | 243 | if (d.main.len == 0) { |
| ... | ... | @@ -247,7 +248,7 @@ fn print_deps(w: std.fs.File.Writer, m: u.Module) !void { |
| 247 | 248 | try w.writeAll("}"); |
| 248 | 249 | } |
| 249 | 250 | |
| 250 | fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(u.Module), done: *std.ArrayList(u.Module)) !void { | |
| 251 | fn print_pkg_data_to(w: std.fs.File.Writer, notdone: *std.ArrayList(zigmod.Module), done: *std.ArrayList(zigmod.Module)) !void { | |
| 251 | 252 | var len: usize = notdone.items.len; |
| 252 | 253 | while (notdone.items.len > 0) { |
| 253 | 254 | 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 |
| 328 | 329 | } |
| 329 | 330 | |
| 330 | 331 | /// returns if all of the zig modules in needles are in haystack |
| 331 | fn contains_all(needles: []u.Module, haystack: []const u.Module) bool { | |
| 332 | fn contains_all(needles: []zigmod.Module, haystack: []const zigmod.Module) bool { | |
| 332 | 333 | 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)) { | |
| 334 | 335 | return false; |
| 335 | 336 | } |
| 336 | 337 | } |
| 337 | 338 | return true; |
| 338 | 339 | } |
| 339 | 340 | |
| 340 | fn print_pkgs(w: std.fs.File.Writer, m: u.Module) !void { | |
| 341 | fn print_pkgs(w: std.fs.File.Writer, m: zigmod.Module) !void { | |
| 341 | 342 | try w.writeAll("struct {\n"); |
| 342 | 343 | for (m.deps) |d| { |
| 343 | 344 | if (d.main.len == 0) { |
| ... | ... | @@ -349,7 +350,7 @@ fn print_pkgs(w: std.fs.File.Writer, m: u.Module) !void { |
| 349 | 350 | try w.writeAll("}"); |
| 350 | 351 | } |
| 351 | 352 | |
| 352 | fn print_imports(w: std.fs.File.Writer, m: u.Module, path: string) !void { | |
| 353 | fn print_imports(w: std.fs.File.Writer, m: zigmod.Module, path: string) !void { | |
| 353 | 354 | for (m.deps) |d| { |
| 354 | 355 | if (d.main.len == 0) { |
| 355 | 356 | continue; |
src/cmd/license.zig+3-2| ... | ... | @@ -4,11 +4,12 @@ const gpa = std.heap.c_allocator; |
| 4 | 4 | const style = @import("ansi").style; |
| 5 | 5 | const licenses = @import("licenses"); |
| 6 | 6 | |
| 7 | const zigmod = @import("../lib.zig"); | |
| 7 | 8 | const u = @import("./../util/index.zig"); |
| 8 | 9 | const common = @import("./../common.zig"); |
| 9 | 10 | |
| 10 | const Module = u.Module; | |
| 11 | const List = std.ArrayList(u.Module); | |
| 11 | const Module = zigmod.Module; | |
| 12 | const List = std.ArrayList(zigmod.Module); | |
| 12 | 13 | const Map = std.StringArrayHashMap(*List); |
| 13 | 14 | |
| 14 | 15 | // Inspired by: |
src/cmd/sum.zig+2-1| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const gpa = std.heap.c_allocator; |
| 3 | 3 | |
| 4 | const zigmod = @import("../lib.zig"); | |
| 4 | 5 | const u = @import("./../util/index.zig"); |
| 5 | 6 | const common = @import("./../common.zig"); |
| 6 | 7 | |
| ... | ... | @@ -25,7 +26,7 @@ pub fn execute(args: [][]u8) !void { |
| 25 | 26 | const w = f.writer(); |
| 26 | 27 | |
| 27 | 28 | // |
| 28 | var module_list = std.ArrayList(u.Module).init(gpa); | |
| 29 | var module_list = std.ArrayList(zigmod.Module).init(gpa); | |
| 29 | 30 | try common.collect_pkgs(top_module, &module_list); |
| 30 | 31 | |
| 31 | 32 | for (module_list.items) |m| { |
src/common.zig+14-14| ... | ... | @@ -29,10 +29,10 @@ pub const CollectOptions = struct { |
| 29 | 29 | } |
| 30 | 30 | }; |
| 31 | 31 | |
| 32 | pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectOptions) !u.Module { | |
| 32 | pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectOptions) !zigmod.Module { | |
| 33 | 33 | const m = try zigmod.ModFile.from_dir(gpa, mdir); |
| 34 | 34 | try options.init(); |
| 35 | var moduledeps = std.ArrayList(u.Module).init(gpa); | |
| 35 | var moduledeps = std.ArrayList(zigmod.Module).init(gpa); | |
| 36 | 36 | defer moduledeps.deinit(); |
| 37 | 37 | if (m.root_files.len > 0) { |
| 38 | 38 | 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 |
| 44 | 44 | try moduledeps.append(founddep); |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | return u.Module{ | |
| 47 | return zigmod.Module{ | |
| 48 | 48 | .is_sys_lib = false, |
| 49 | 49 | .id = "root", |
| 50 | 50 | .name = "root", |
| ... | ... | @@ -56,9 +56,9 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO |
| 56 | 56 | }; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOptions) anyerror!u.Module { | |
| 59 | pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOptions) anyerror!zigmod.Module { | |
| 60 | 60 | 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); | |
| 62 | 62 | defer moduledeps.deinit(); |
| 63 | 63 | if (m.files.len > 0) { |
| 64 | 64 | try std.fs.cwd().makePath(".zigmod/deps/files"); |
| ... | ... | @@ -69,7 +69,7 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOption |
| 69 | 69 | try moduledeps.append(founddep); |
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | return u.Module{ | |
| 72 | return zigmod.Module{ | |
| 73 | 73 | .is_sys_lib = false, |
| 74 | 74 | .id = m.id, |
| 75 | 75 | .name = m.name, |
| ... | ... | @@ -84,8 +84,8 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOption |
| 84 | 84 | }; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | pub fn collect_pkgs(mod: u.Module, list: *std.ArrayList(u.Module)) anyerror!void { | |
| 88 | if (u.list_contains_gen(u.Module, list.items, mod)) { | |
| 87 | pub fn collect_pkgs(mod: zigmod.Module, list: *std.ArrayList(zigmod.Module)) anyerror!void { | |
| 88 | if (u.list_contains_gen(zigmod.Module, list.items, mod)) { | |
| 89 | 89 | return; |
| 90 | 90 | } |
| 91 | 91 | try list.append(mod); |
| ... | ... | @@ -198,7 +198,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! |
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectOptions) anyerror!?u.Module { | |
| 201 | pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectOptions) anyerror!?zigmod.Module { | |
| 202 | 202 | if (options.lock) |lock| { |
| 203 | 203 | for (lock) |item| { |
| 204 | 204 | 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 |
| 217 | 217 | |
| 218 | 218 | switch (d.type) { |
| 219 | 219 | .system_lib => { |
| 220 | return u.Module{ | |
| 220 | return zigmod.Module{ | |
| 221 | 221 | .is_sys_lib = true, |
| 222 | 222 | .id = try u.do_hash(std.crypto.hash.sha3.Sha3_384, d.path), |
| 223 | 223 | .name = d.path, |
| 224 | 224 | .only_os = d.only_os, |
| 225 | 225 | .except_os = d.except_os, |
| 226 | 226 | .main = "", |
| 227 | .deps = &[_]u.Module{}, | |
| 227 | .deps = &[_]zigmod.Module{}, | |
| 228 | 228 | .clean_path = d.path, |
| 229 | 229 | .yaml = null, |
| 230 | 230 | .dep = d.*, |
| ... | ... | @@ -234,7 +234,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 234 | 234 | var dd = try collect_deps(cachepath, moddir, options) catch |e| switch (e) { |
| 235 | 235 | error.FileNotFound => { |
| 236 | 236 | 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); | |
| 238 | 238 | if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..]; |
| 239 | 239 | if (mod_from.is_for_this()) return mod_from; |
| 240 | 240 | return null; |
| ... | ... | @@ -248,7 +248,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 248 | 248 | if (trymain) |_| { |
| 249 | 249 | d.*.name = tryname; |
| 250 | 250 | 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); | |
| 252 | 252 | if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..]; |
| 253 | 253 | if (mod_from.is_for_this()) return mod_from; |
| 254 | 254 | return null; |
| ... | ... | @@ -276,7 +276,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 276 | 276 | } |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | pub fn add_files_package(pkg_name: string, mdir: std.fs.Dir, dirs: []const string) !u.Module { | |
| 279 | pub fn add_files_package(pkg_name: string, mdir: std.fs.Dir, dirs: []const string) !zigmod.Module { | |
| 280 | 280 | const destination = ".zigmod/deps/files"; |
| 281 | 281 | const fname = try std.mem.join(gpa, "", &.{ pkg_name, ".zig" }); |
| 282 | 282 |
src/lib.zig+1| ... | ... | @@ -26,3 +26,4 @@ pub fn deinit() void { |
| 26 | 26 | pub const DepType = @import("./util/dep_type.zig").DepType; |
| 27 | 27 | pub const Dep = @import("./util/dep.zig").Dep; |
| 28 | 28 | pub const ModFile = @import("./util/modfile.zig").ModFile; |
| 29 | pub const Module = @import("./util/module.zig").Module; |
src/util/index.zig-1| ... | ... | @@ -1,2 +1 @@ |
| 1 | 1 | usingnamespace @import("./funcs.zig"); |
| 2 | usingnamespace @import("./module.zig"); |