| author | |
| committer | |
| log | e0e95bedc45c574fef385e7f6a7a2253d1614108 |
| tree | fc8c3e19c735fefa643dc49cd5f69e3b670b3694 |
| parent | 0dacc15ec5f7780721bc6668dc81578706ad0d8c |
5 files changed, 26 insertions(+), 20 deletions(-)
src/common.zig+7-2| ... | @@ -45,6 +45,7 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO | ... | @@ -45,6 +45,7 @@ pub fn collect_deps_deep(cachepath: string, mdir: std.fs.Dir, options: *CollectO |
| 45 | } | 45 | } |
| 46 | } | 46 | } |
| 47 | return zigmod.Module{ | 47 | return zigmod.Module{ |
| 48 | .alloc = gpa, | ||
| 48 | .is_sys_lib = false, | 49 | .is_sys_lib = false, |
| 49 | .id = "root", | 50 | .id = "root", |
| 50 | .name = "root", | 51 | .name = "root", |
| ... | @@ -70,6 +71,7 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOption | ... | @@ -70,6 +71,7 @@ pub fn collect_deps(cachepath: string, mdir: std.fs.Dir, options: *CollectOption |
| 70 | } | 71 | } |
| 71 | } | 72 | } |
| 72 | return zigmod.Module{ | 73 | return zigmod.Module{ |
| 74 | .alloc = gpa, | ||
| 73 | .is_sys_lib = false, | 75 | .is_sys_lib = false, |
| 74 | .id = m.id, | 76 | .id = m.id, |
| 75 | .name = m.name, | 77 | .name = m.name, |
| ... | @@ -218,6 +220,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO | ... | @@ -218,6 +220,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 218 | switch (d.type) { | 220 | switch (d.type) { |
| 219 | .system_lib => { | 221 | .system_lib => { |
| 220 | return zigmod.Module{ | 222 | return zigmod.Module{ |
| 223 | .alloc = gpa, | ||
| 221 | .is_sys_lib = true, | 224 | .is_sys_lib = true, |
| 222 | .id = try u.do_hash(std.crypto.hash.sha3.Sha3_384, d.path), | 225 | .id = try u.do_hash(std.crypto.hash.sha3.Sha3_384, d.path), |
| 223 | .name = d.path, | 226 | .name = d.path, |
| ... | @@ -234,7 +237,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO | ... | @@ -234,7 +237,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 234 | var dd = try collect_deps(cachepath, moddir, options) catch |e| switch (e) { | 237 | var dd = try collect_deps(cachepath, moddir, options) catch |e| switch (e) { |
| 235 | error.FileNotFound => { | 238 | error.FileNotFound => { |
| 236 | if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { | 239 | if (d.main.len > 0 or d.c_include_dirs.len > 0 or d.c_source_files.len > 0) { |
| 237 | var mod_from = try zigmod.Module.from(d.*, cachepath, options); | 240 | var mod_from = try zigmod.Module.from(gpa, d.*, cachepath, options); |
| 238 | if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..]; | 241 | if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..]; |
| 239 | if (mod_from.is_for_this()) return mod_from; | 242 | if (mod_from.is_for_this()) return mod_from; |
| 240 | return null; | 243 | return null; |
| ... | @@ -248,7 +251,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO | ... | @@ -248,7 +251,7 @@ pub fn get_module_from_dep(d: *zigmod.Dep, cachepath: string, options: *CollectO |
| 248 | if (trymain) |_| { | 251 | if (trymain) |_| { |
| 249 | d.*.name = tryname; | 252 | d.*.name = tryname; |
| 250 | d.*.main = trymain.?; | 253 | d.*.main = trymain.?; |
| 251 | var mod_from = try zigmod.Module.from(d.*, cachepath, options); | 254 | var mod_from = try zigmod.Module.from(gpa, d.*, cachepath, options); |
| 252 | if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..]; | 255 | if (d.type != .local) mod_from.clean_path = u.trim_prefix(modpath, cachepath)[1..]; |
| 253 | if (mod_from.is_for_this()) return mod_from; | 256 | if (mod_from.is_for_this()) return mod_from; |
| 254 | return null; | 257 | return null; |
| ... | @@ -327,6 +330,7 @@ pub fn add_files_package(pkg_name: string, mdir: std.fs.Dir, dirs: []const strin | ... | @@ -327,6 +330,7 @@ pub fn add_files_package(pkg_name: string, mdir: std.fs.Dir, dirs: []const strin |
| 327 | ); | 330 | ); |
| 328 | 331 | ||
| 329 | var d: zigmod.Dep = .{ | 332 | var d: zigmod.Dep = .{ |
| 333 | .alloc = gpa, | ||
| 330 | .type = .local, | 334 | .type = .local, |
| 331 | .path = "files", | 335 | .path = "files", |
| 332 | .id = "", | 336 | .id = "", |
| ... | @@ -368,6 +372,7 @@ pub fn parse_lockfile(dir: std.fs.Dir) ![]const [4]string { | ... | @@ -368,6 +372,7 @@ pub fn parse_lockfile(dir: std.fs.Dir) ![]const [4]string { |
| 368 | 2 => { | 372 | 2 => { |
| 369 | var iter = std.mem.split(u8, line, " "); | 373 | var iter = std.mem.split(u8, line, " "); |
| 370 | const asdep = zigmod.Dep{ | 374 | const asdep = zigmod.Dep{ |
| 375 | .alloc = gpa, | ||
| 371 | .type = std.meta.stringToEnum(zigmod.DepType, iter.next().?).?, | 376 | .type = std.meta.stringToEnum(zigmod.DepType, iter.next().?).?, |
| 372 | .path = iter.next().?, | 377 | .path = iter.next().?, |
| 373 | .version = iter.next().?, | 378 | .version = iter.next().?, |
src/util/dep.zig+6-7| ... | @@ -1,6 +1,5 @@ | ... | @@ -1,6 +1,5 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const string = []const u8; | 2 | const string = []const u8; |
| 3 | const gpa = std.heap.c_allocator; | ||
| 4 | const builtin = std.builtin; | 3 | const builtin = std.builtin; |
| 5 | 4 | ||
| 6 | const zigmod = @import("../lib.zig"); | 5 | const zigmod = @import("../lib.zig"); |
| ... | @@ -13,9 +12,9 @@ const yaml = @import("./yaml.zig"); | ... | @@ -13,9 +12,9 @@ const yaml = @import("./yaml.zig"); |
| 13 | pub const Dep = struct { | 12 | pub const Dep = struct { |
| 14 | const Self = @This(); | 13 | const Self = @This(); |
| 15 | 14 | ||
| 15 | alloc: *std.mem.Allocator, | ||
| 16 | type: zigmod.DepType, | 16 | type: zigmod.DepType, |
| 17 | path: string, | 17 | path: string, |
| 18 | |||
| 19 | id: string, | 18 | id: string, |
| 20 | name: string, | 19 | name: string, |
| 21 | main: string, | 20 | main: string, |
| ... | @@ -37,16 +36,16 @@ pub const Dep = struct { | ... | @@ -37,16 +36,16 @@ pub const Dep = struct { |
| 37 | p = u.trim_prefix(p, "https://"); | 36 | p = u.trim_prefix(p, "https://"); |
| 38 | p = u.trim_prefix(p, "git://"); | 37 | p = u.trim_prefix(p, "git://"); |
| 39 | p = u.trim_suffix(p, ".git"); | 38 | p = u.trim_suffix(p, ".git"); |
| 40 | p = try std.mem.join(gpa, "/", &.{ @tagName(self.type), p }); | 39 | p = try std.mem.join(self.alloc, "/", &.{ @tagName(self.type), p }); |
| 41 | return p; | 40 | return p; |
| 42 | } | 41 | } |
| 43 | 42 | ||
| 44 | pub fn clean_path_v(self: Dep) !string { | 43 | pub fn clean_path_v(self: Dep) !string { |
| 45 | if (self.type == .http and self.version.len > 0) { | 44 | if (self.type == .http and self.version.len > 0) { |
| 46 | const i = std.mem.indexOf(u8, self.version, "-").?; | 45 | const i = std.mem.indexOf(u8, self.version, "-").?; |
| 47 | return std.mem.join(gpa, "/", &.{ "v", try self.clean_path(), self.version[i + 1 .. 15] }); | 46 | return std.mem.join(self.alloc, "/", &.{ "v", try self.clean_path(), self.version[i + 1 .. 15] }); |
| 48 | } | 47 | } |
| 49 | return std.mem.join(gpa, "/", &.{ "v", try self.clean_path(), self.version }); | 48 | return std.mem.join(self.alloc, "/", &.{ "v", try self.clean_path(), self.version }); |
| 50 | } | 49 | } |
| 51 | 50 | ||
| 52 | pub fn is_for_this(self: Dep) bool { | 51 | pub fn is_for_this(self: Dep) bool { |
| ... | @@ -62,13 +61,13 @@ pub const Dep = struct { | ... | @@ -62,13 +61,13 @@ pub const Dep = struct { |
| 62 | 61 | ||
| 63 | pub fn exact_version(self: Dep, dpath: string) !string { | 62 | pub fn exact_version(self: Dep, dpath: string) !string { |
| 64 | if (self.version.len == 0) { | 63 | if (self.version.len == 0) { |
| 65 | return try self.type.exact_version(dpath); | 64 | return try self.type.exact_version(self.alloc, dpath); |
| 66 | } | 65 | } |
| 67 | return switch (self.type) { | 66 | return switch (self.type) { |
| 68 | .git => blk: { | 67 | .git => blk: { |
| 69 | const vers = try u.parse_split(zigmod.DepType.GitVersion, "-").do(self.version); | 68 | const vers = try u.parse_split(zigmod.DepType.GitVersion, "-").do(self.version); |
| 70 | if (vers.id.frozen()) break :blk self.version; | 69 | if (vers.id.frozen()) break :blk self.version; |
| 71 | break :blk try self.type.exact_version(dpath); | 70 | break :blk try self.type.exact_version(self.alloc, dpath); |
| 72 | }, | 71 | }, |
| 73 | else => self.version, | 72 | else => self.version, |
| 74 | }; | 73 | }; |
src/util/dep_type.zig+2-3| ... | @@ -1,6 +1,5 @@ | ... | @@ -1,6 +1,5 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const string = []const u8; | 2 | const string = []const u8; |
| 3 | const gpa = std.heap.c_allocator; | ||
| 4 | 3 | ||
| 5 | const u = @import("./index.zig"); | 4 | const u = @import("./index.zig"); |
| 6 | 5 | ||
| ... | @@ -78,13 +77,13 @@ pub const DepType = enum { | ... | @@ -78,13 +77,13 @@ pub const DepType = enum { |
| 78 | } | 77 | } |
| 79 | 78 | ||
| 80 | // zig fmt: on | 79 | // zig fmt: on |
| 81 | pub fn exact_version(self: DepType, mpath: string) !string { | 80 | pub fn exact_version(self: DepType, alloc: *std.mem.Allocator, mpath: string) !string { |
| 82 | var mdir = try std.fs.cwd().openDir(mpath, .{}); | 81 | var mdir = try std.fs.cwd().openDir(mpath, .{}); |
| 83 | defer mdir.close(); | 82 | defer mdir.close(); |
| 84 | return switch (self) { | 83 | return switch (self) { |
| 85 | .local => "", | 84 | .local => "", |
| 86 | .system_lib => "", | 85 | .system_lib => "", |
| 87 | .git => try std.fmt.allocPrint(gpa, "commit-{s}", .{(try u.git_rev_HEAD(gpa, mdir))}), | 86 | .git => try std.fmt.allocPrint(alloc, "commit-{s}", .{(try u.git_rev_HEAD(alloc, mdir))}), |
| 88 | .hg => "", | 87 | .hg => "", |
| 89 | .http => "", | 88 | .http => "", |
| 90 | }; | 89 | }; |
src/util/modfile.zig+1| ... | @@ -108,6 +108,7 @@ pub const ModFile = struct { | ... | @@ -108,6 +108,7 @@ pub const ModFile = struct { |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | try dep_list.append(zigmod.Dep{ | 110 | try dep_list.append(zigmod.Dep{ |
| 111 | .alloc = alloc, | ||
| 111 | .type = dep_type, | 112 | .type = dep_type, |
| 112 | .path = path, | 113 | .path = path, |
| 113 | .id = item.mapping.get_string("id"), | 114 | .id = item.mapping.get_string("id"), |
src/util/module.zig+10-8| ... | @@ -1,6 +1,5 @@ | ... | @@ -1,6 +1,5 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const string = []const u8; | 2 | const string = []const u8; |
| 3 | const gpa = std.heap.c_allocator; | ||
| 4 | const builtin = @import("builtin"); | 3 | const builtin = @import("builtin"); |
| 5 | 4 | ||
| 6 | const zigmod = @import("../lib.zig"); | 5 | const zigmod = @import("../lib.zig"); |
| ... | @@ -12,6 +11,7 @@ const common = @import("./../common.zig"); | ... | @@ -12,6 +11,7 @@ const common = @import("./../common.zig"); |
| 12 | // | 11 | // |
| 13 | 12 | ||
| 14 | pub const Module = struct { | 13 | pub const Module = struct { |
| 14 | alloc: *std.mem.Allocator, | ||
| 15 | is_sys_lib: bool, | 15 | is_sys_lib: bool, |
| 16 | id: string, | 16 | id: string, |
| 17 | name: string, | 17 | name: string, |
| ... | @@ -26,15 +26,17 @@ pub const Module = struct { | ... | @@ -26,15 +26,17 @@ pub const Module = struct { |
| 26 | clean_path: string, | 26 | clean_path: string, |
| 27 | dep: ?zigmod.Dep, | 27 | dep: ?zigmod.Dep, |
| 28 | 28 | ||
| 29 | pub fn from(dep: zigmod.Dep, dir: string, options: *common.CollectOptions) !Module { | 29 | pub fn from(alloc: *std.mem.Allocator, dep: zigmod.Dep, dir: string, options: *common.CollectOptions) !Module { |
| 30 | var moddeps = std.ArrayList(Module).init(gpa); | 30 | var moddeps = std.ArrayList(Module).init(alloc); |
| 31 | defer moddeps.deinit(); | 31 | defer moddeps.deinit(); |
| 32 | |||
| 32 | for (dep.deps) |*d| { | 33 | for (dep.deps) |*d| { |
| 33 | if (try common.get_module_from_dep(d, dir, options)) |founddep| { | 34 | if (try common.get_module_from_dep(d, dir, options)) |founddep| { |
| 34 | try moddeps.append(founddep); | 35 | try moddeps.append(founddep); |
| 35 | } | 36 | } |
| 36 | } | 37 | } |
| 37 | return Module{ | 38 | return Module{ |
| 39 | .alloc = alloc, | ||
| 38 | .is_sys_lib = false, | 40 | .is_sys_lib = false, |
| 39 | .id = if (dep.id.len > 0) dep.id else try u.random_string(48), | 41 | .id = if (dep.id.len > 0) dep.id else try u.random_string(48), |
| 40 | .name = dep.name, | 42 | .name = dep.name, |
| ... | @@ -56,9 +58,9 @@ pub const Module = struct { | ... | @@ -56,9 +58,9 @@ pub const Module = struct { |
| 56 | } | 58 | } |
| 57 | 59 | ||
| 58 | pub fn get_hash(self: Module, cdpath: string) !string { | 60 | pub fn get_hash(self: Module, cdpath: string) !string { |
| 59 | const file_list_1 = try u.file_list(try std.mem.concat(gpa, u8, &.{ cdpath, "/", self.clean_path })); | 61 | const file_list_1 = try u.file_list(try std.mem.concat(self.alloc, u8, &.{ cdpath, "/", self.clean_path })); |
| 60 | 62 | ||
| 61 | var file_list_2 = std.ArrayList(string).init(gpa); | 63 | var file_list_2 = std.ArrayList(string).init(self.alloc); |
| 62 | defer file_list_2.deinit(); | 64 | defer file_list_2.deinit(); |
| 63 | for (file_list_1) |item| { | 65 | for (file_list_1) |item| { |
| 64 | const _a = u.trim_prefix(item, cdpath); | 66 | const _a = u.trim_prefix(item, cdpath); |
| ... | @@ -76,15 +78,15 @@ pub const Module = struct { | ... | @@ -76,15 +78,15 @@ pub const Module = struct { |
| 76 | 78 | ||
| 77 | const h = &std.crypto.hash.Blake3.init(.{}); | 79 | const h = &std.crypto.hash.Blake3.init(.{}); |
| 78 | for (file_list_2.items) |item| { | 80 | for (file_list_2.items) |item| { |
| 79 | const abs_path = try std.fs.path.join(gpa, &.{ cdpath, self.clean_path, item }); | 81 | const abs_path = try std.fs.path.join(self.alloc, &.{ cdpath, self.clean_path, item }); |
| 80 | const file = try std.fs.cwd().openFile(abs_path, .{}); | 82 | const file = try std.fs.cwd().openFile(abs_path, .{}); |
| 81 | defer file.close(); | 83 | defer file.close(); |
| 82 | const input = try file.reader().readAllAlloc(gpa, u.mb * 100); | 84 | const input = try file.reader().readAllAlloc(self.alloc, u.mb * 100); |
| 83 | h.update(input); | 85 | h.update(input); |
| 84 | } | 86 | } |
| 85 | var out: [32]u8 = undefined; | 87 | var out: [32]u8 = undefined; |
| 86 | h.final(&out); | 88 | h.final(&out); |
| 87 | const hex = try std.fmt.allocPrint(gpa, "blake3-{x}", .{std.fmt.fmtSliceHexLower(out[0..])}); | 89 | const hex = try std.fmt.allocPrint(self.alloc, "blake3-{x}", .{std.fmt.fmtSliceHexLower(out[0..])}); |
| 88 | return hex; | 90 | return hex; |
| 89 | } | 91 | } |
| 90 | 92 |