authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-06 11:20:42 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-06 11:20:42 -07:00
log44c0c6c615900e9616e02514cc8b822afada9f0c
tree9bfd706cd35f48aac5a95d5d52dff4ab1db774d1
parent9f80f414a25e5abce9993b6f88efb2d0ca1da751

update lockfile format to version 2


3 files changed, 54 insertions(+), 20 deletions(-)

src/cmd/fetch.zig+2-1
...@@ -116,6 +116,7 @@ fn create_lockfile(list: *std.ArrayList(u.Module), dir: []const u8) !void {...@@ -116,6 +116,7 @@ fn create_lockfile(list: *std.ArrayList(u.Module), dir: []const u8) !void {
116 defer fl.close();116 defer fl.close();
117117
118 const wl = fl.writer();118 const wl = fl.writer();
119 try wl.writeAll("2\n");
119 for (list.items) |m| {120 for (list.items) |m| {
120 if (m.dep) |md| {121 if (m.dep) |md| {
121 if (md.type == .local) {122 if (md.type == .local) {
...@@ -123,7 +124,7 @@ fn create_lockfile(list: *std.ArrayList(u.Module), dir: []const u8) !void {...@@ -123,7 +124,7 @@ fn create_lockfile(list: *std.ArrayList(u.Module), dir: []const u8) !void {
123 }124 }
124 const mpath = try std.fs.path.join(gpa, &.{ dir, m.clean_path });125 const mpath = try std.fs.path.join(gpa, &.{ dir, m.clean_path });
125 const version = if (md.version.len > 0) md.version else (try md.type.exact_version(mpath));126 const version = if (md.version.len > 0) md.version else (try md.type.exact_version(mpath));
126 try wl.print("{s} {s} {s} {s}\n", .{ m.clean_path, @tagName(md.type), md.path, version });127 try wl.print("{s} {s} {s}\n", .{ @tagName(md.type), md.path, version });
127 }128 }
128 }129 }
129}130}
src/common.zig+40-8
...@@ -296,14 +296,46 @@ pub fn parse_lockfile(path: []const u8) ![]const [4][]const u8 {...@@ -296,14 +296,46 @@ pub fn parse_lockfile(path: []const u8) ![]const [4][]const u8 {
296 const max = std.math.maxInt(usize);296 const max = std.math.maxInt(usize);
297 const f = try std.fs.cwd().openFile(path, .{});297 const f = try std.fs.cwd().openFile(path, .{});
298 const r = f.reader();298 const r = f.reader();
299 while (try r.readUntilDelimiterOrEofAlloc(gpa, '\n', max)) |line| {299 var i: usize = 0;
300 var iter = std.mem.split(line, " ");300 var v: usize = 1;
301 try list.append([4][]const u8{301 while (try r.readUntilDelimiterOrEofAlloc(gpa, '\n', max)) |line| : (i += 1) {
302 iter.next().?,302 if (i == 0 and std.mem.eql(u8, line, "2")) {
303 iter.next().?,303 v = 2;
304 iter.next().?,304 continue;
305 iter.next().?,305 }
306 });306 switch (v) {
307 1 => {
308 var iter = std.mem.split(line, " ");
309 try list.append([4][]const u8{
310 iter.next().?,
311 iter.next().?,
312 iter.next().?,
313 iter.next().?,
314 });
315 },
316 2 => {
317 var iter = std.mem.split(line, " ");
318 const asdep = u.Dep{
319 .type = std.meta.stringToEnum(u.DepType, iter.next().?).?,
320 .path = iter.next().?,
321 .version = iter.next().?,
322 .id = "",
323 .name = "",
324 .main = "",
325 .yaml = null,
326 .deps = &.{},
327 };
328 try list.append([4][]const u8{
329 try asdep.clean_path(),
330 @tagName(asdep.type),
331 asdep.path,
332 asdep.version,
333 });
334 },
335 else => {
336 u.assert(false, "invalid zigmod.lock version: {d}", .{v});
337 },
338 }
307 }339 }
308 return list.toOwnedSlice();340 return list.toOwnedSlice();
309}341}
zigmod.lock+12-11
...@@ -1,11 +1,12 @@...@@ -1,11 +1,12 @@
1v/git/github.com/yaml/libyaml/tag-0.2.5 git https://github.com/yaml/libyaml tag-0.2.512
2git/github.com/nektro/zig-ansi git https://github.com/nektro/zig-ansi commit-930ab1f2git https://github.com/yaml/libyaml tag-0.2.5
3git/github.com/ziglibs/known-folders git https://github.com/ziglibs/known-folders commit-f5e5fb83git https://github.com/nektro/zig-ansi commit-930ab1f
4git/github.com/nektro/zig-licenses git https://github.com/nektro/zig-licenses commit-499bee64git https://github.com/ziglibs/known-folders commit-f5e5fb8
5git/github.com/truemedian/zfetch git https://github.com/truemedian/zfetch commit-2cefe805git https://github.com/nektro/zig-licenses commit-499bee6
6git/github.com/truemedian/hzzp git https://github.com/truemedian/hzzp commit-2d30bdd6git https://github.com/truemedian/zfetch commit-2cefe80
7git/github.com/alexnask/iguanaTLS git https://github.com/alexnask/iguanaTLS commit-0d39a367git https://github.com/truemedian/hzzp commit-2d30bdd
8git/github.com/MasterQ32/zig-network git https://github.com/MasterQ32/zig-network commit-b9c91768git https://github.com/alexnask/iguanaTLS commit-0d39a36
9git/github.com/MasterQ32/zig-uri git https://github.com/MasterQ32/zig-uri commit-f1896c69git https://github.com/MasterQ32/zig-network commit-b9c9176
10git/github.com/nektro/zig-json git https://github.com/nektro/zig-json commit-659906410git https://github.com/MasterQ32/zig-uri commit-f1896c6
11git/github.com/nektro/zig-range git https://github.com/nektro/zig-range commit-890ca3011git https://github.com/nektro/zig-json commit-6599064
12git https://github.com/nektro/zig-range commit-890ca30