authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 02:38:07 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 02:38:07 -07:00
log6fd42714e7ec2ab81732770c6eebc9ff7a683b5e
treeae73da38c86fbb8025f1ec7c93b25004f3add618
parente16a1f6d945521ff0cd81d6486dbbe86ae7c038f

move DepType to lib entry point


5 files changed, 11 insertions(+), 7 deletions(-)

src/common.zig+4-3
...@@ -5,6 +5,7 @@ const gpa = std.heap.c_allocator;...@@ -5,6 +5,7 @@ const gpa = std.heap.c_allocator;
55
6const ansi = @import("ansi");6const ansi = @import("ansi");
77
8const zigmod = @import("./lib.zig");
8const u = @import("./util/index.zig");9const u = @import("./util/index.zig");
9const yaml = @import("./util/yaml.zig");10const yaml = @import("./util/yaml.zig");
1011
...@@ -123,7 +124,7 @@ pub fn get_modpath(cachepath: string, d: u.Dep, options: *CollectOptions) !strin...@@ -123,7 +124,7 @@ pub fn get_modpath(cachepath: string, d: u.Dep, options: *CollectOptions) !strin
123 },124 },
124 .git => {125 .git => {
125 if (d.version.len > 0) {126 if (d.version.len > 0) {
126 const vers = u.parse_split(u.DepType.GitVersion, "-").do(d.version) catch |e| switch (e) {127 const vers = u.parse_split(zigmod.DepType.GitVersion, "-").do(d.version) catch |e| switch (e) {
127 error.IterEmpty => unreachable,128 error.IterEmpty => unreachable,
128 error.NoMemberFound => {129 error.NoMemberFound => {
129 const vtype = d.version[0..std.mem.indexOf(u8, d.version, "-").?];130 const vtype = d.version[0..std.mem.indexOf(u8, d.version, "-").?];
...@@ -201,7 +202,7 @@ pub fn get_module_from_dep(d: *u.Dep, cachepath: string, options: *CollectOption...@@ -201,7 +202,7 @@ pub fn get_module_from_dep(d: *u.Dep, cachepath: string, options: *CollectOption
201 if (options.lock) |lock| {202 if (options.lock) |lock| {
202 for (lock) |item| {203 for (lock) |item| {
203 if (std.mem.eql(u8, item[0], try d.clean_path())) {204 if (std.mem.eql(u8, item[0], try d.clean_path())) {
204 d.type = std.meta.stringToEnum(u.DepType, item[1]).?;205 d.type = std.meta.stringToEnum(zigmod.DepType, item[1]).?;
205 d.path = item[2];206 d.path = item[2];
206 d.version = item[3];207 d.version = item[3];
207 break;208 break;
...@@ -367,7 +368,7 @@ pub fn parse_lockfile(dir: std.fs.Dir) ![]const [4]string {...@@ -367,7 +368,7 @@ pub fn parse_lockfile(dir: std.fs.Dir) ![]const [4]string {
367 2 => {368 2 => {
368 var iter = std.mem.split(u8, line, " ");369 var iter = std.mem.split(u8, line, " ");
369 const asdep = u.Dep{370 const asdep = u.Dep{
370 .type = std.meta.stringToEnum(u.DepType, iter.next().?).?,371 .type = std.meta.stringToEnum(zigmod.DepType, iter.next().?).?,
371 .path = iter.next().?,372 .path = iter.next().?,
372 .version = iter.next().?,373 .version = iter.next().?,
373 .id = "",374 .id = "",
src/lib.zig+2
...@@ -22,3 +22,5 @@ pub fn init() !void {...@@ -22,3 +22,5 @@ pub fn init() !void {
22pub fn deinit() void {22pub fn deinit() void {
23 zfetch.deinit();23 zfetch.deinit();
24}24}
25
26pub const DepType = @import("./util/dep_type.zig").DepType;
src/util/dep.zig+3-2
...@@ -3,6 +3,7 @@ const string = []const u8;...@@ -3,6 +3,7 @@ const string = []const u8;
3const gpa = std.heap.c_allocator;3const gpa = std.heap.c_allocator;
4const builtin = std.builtin;4const builtin = std.builtin;
55
6const zigmod = @import("../lib.zig");
6const u = @import("index.zig");7const u = @import("index.zig");
7const yaml = @import("./yaml.zig");8const yaml = @import("./yaml.zig");
89
...@@ -12,7 +13,7 @@ const yaml = @import("./yaml.zig");...@@ -12,7 +13,7 @@ const yaml = @import("./yaml.zig");
12pub const Dep = struct {13pub const Dep = struct {
13 const Self = @This();14 const Self = @This();
1415
15 type: u.DepType,16 type: zigmod.DepType,
16 path: string,17 path: string,
1718
18 id: string,19 id: string,
...@@ -65,7 +66,7 @@ pub const Dep = struct {...@@ -65,7 +66,7 @@ pub const Dep = struct {
65 }66 }
66 return switch (self.type) {67 return switch (self.type) {
67 .git => blk: {68 .git => blk: {
68 const vers = try u.parse_split(u.DepType.GitVersion, "-").do(self.version);69 const vers = try u.parse_split(zigmod.DepType.GitVersion, "-").do(self.version);
69 if (vers.id.frozen()) break :blk self.version;70 if (vers.id.frozen()) break :blk self.version;
70 break :blk try self.type.exact_version(dpath);71 break :blk try self.type.exact_version(dpath);
71 },72 },
src/util/index.zig-1
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1usingnamespace @import("./funcs.zig");1usingnamespace @import("./funcs.zig");
2usingnamespace @import("./dep_type.zig");
3usingnamespace @import("./dep.zig");2usingnamespace @import("./dep.zig");
4usingnamespace @import("./modfile.zig");3usingnamespace @import("./modfile.zig");
5usingnamespace @import("./module.zig");4usingnamespace @import("./module.zig");
src/util/modfile.zig+2-1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;2const string = []const u8;
33
4const zigmod = @import("../lib.zig");
4const u = @import("index.zig");5const u = @import("index.zig");
5const yaml = @import("./yaml.zig");6const yaml = @import("./yaml.zig");
67
...@@ -94,7 +95,7 @@ pub const ModFile = struct {...@@ -94,7 +95,7 @@ pub const ModFile = struct {
94 if (version == null) {95 if (version == null) {
95 version = "";96 version = "";
96 }97 }
97 const dep_type = std.meta.stringToEnum(u.DepType, dtype).?;98 const dep_type = std.meta.stringToEnum(zigmod.DepType, dtype).?;
98 if (dep_type == .local) {99 if (dep_type == .local) {
99 if (path.len > 0) {100 if (path.len > 0) {
100 name = path;101 name = path;