From 44c0c6c615900e9616e02514cc8b822afada9f0c Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 6 Jul 2021 11:20:42 -0700 Subject: [PATCH] update lockfile format to version 2 --- src/cmd/fetch.zig | 3 ++- src/common.zig | 48 +++++++++++++++++++++++++++++++++++++++-------- zigmod.lock | 23 ++++++++++++----------- 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/cmd/fetch.zig b/src/cmd/fetch.zig index 84da2d61dd1335bbd5cccbb14f8627e7a41e31a5..1541bdf7e5eec33b1d22b51eb329efcf67f57e43 100644 --- a/src/cmd/fetch.zig +++ b/src/cmd/fetch.zig @@ -116,6 +116,7 @@ fn create_lockfile(list: *std.ArrayList(u.Module), dir: []const u8) !void { defer fl.close(); const wl = fl.writer(); + try wl.writeAll("2\n"); for (list.items) |m| { if (m.dep) |md| { if (md.type == .local) { @@ -123,7 +124,7 @@ fn create_lockfile(list: *std.ArrayList(u.Module), dir: []const u8) !void { } const mpath = try std.fs.path.join(gpa, &.{ dir, m.clean_path }); const version = if (md.version.len > 0) md.version else (try md.type.exact_version(mpath)); - try wl.print("{s} {s} {s} {s}\n", .{ m.clean_path, @tagName(md.type), md.path, version }); + try wl.print("{s} {s} {s}\n", .{ @tagName(md.type), md.path, version }); } } } diff --git a/src/common.zig b/src/common.zig index f7b409987101acede4ade77f53b382a6a722cce1..d4837456259895cb311fd5c7778b60ab19ab0561 100644 --- a/src/common.zig +++ b/src/common.zig @@ -296,14 +296,46 @@ pub fn parse_lockfile(path: []const u8) ![]const [4][]const u8 { const max = std.math.maxInt(usize); const f = try std.fs.cwd().openFile(path, .{}); const r = f.reader(); - while (try r.readUntilDelimiterOrEofAlloc(gpa, '\n', max)) |line| { - var iter = std.mem.split(line, " "); - try list.append([4][]const u8{ - iter.next().?, - iter.next().?, - iter.next().?, - iter.next().?, - }); + var i: usize = 0; + var v: usize = 1; + while (try r.readUntilDelimiterOrEofAlloc(gpa, '\n', max)) |line| : (i += 1) { + if (i == 0 and std.mem.eql(u8, line, "2")) { + v = 2; + continue; + } + switch (v) { + 1 => { + var iter = std.mem.split(line, " "); + try list.append([4][]const u8{ + iter.next().?, + iter.next().?, + iter.next().?, + iter.next().?, + }); + }, + 2 => { + var iter = std.mem.split(line, " "); + const asdep = u.Dep{ + .type = std.meta.stringToEnum(u.DepType, iter.next().?).?, + .path = iter.next().?, + .version = iter.next().?, + .id = "", + .name = "", + .main = "", + .yaml = null, + .deps = &.{}, + }; + try list.append([4][]const u8{ + try asdep.clean_path(), + @tagName(asdep.type), + asdep.path, + asdep.version, + }); + }, + else => { + u.assert(false, "invalid zigmod.lock version: {d}", .{v}); + }, + } } return list.toOwnedSlice(); } diff --git a/zigmod.lock b/zigmod.lock index 07224b5920fbb32f607f00b0754fc3c855eaa494..81457857bd5553fe23cea6cf3243c02dbe72efec 100644 --- a/zigmod.lock +++ b/zigmod.lock @@ -1,11 +1,12 @@ -v/git/github.com/yaml/libyaml/tag-0.2.5 git https://github.com/yaml/libyaml tag-0.2.5 -git/github.com/nektro/zig-ansi git https://github.com/nektro/zig-ansi commit-930ab1f -git/github.com/ziglibs/known-folders git https://github.com/ziglibs/known-folders commit-f5e5fb8 -git/github.com/nektro/zig-licenses git https://github.com/nektro/zig-licenses commit-499bee6 -git/github.com/truemedian/zfetch git https://github.com/truemedian/zfetch commit-2cefe80 -git/github.com/truemedian/hzzp git https://github.com/truemedian/hzzp commit-2d30bdd -git/github.com/alexnask/iguanaTLS git https://github.com/alexnask/iguanaTLS commit-0d39a36 -git/github.com/MasterQ32/zig-network git https://github.com/MasterQ32/zig-network commit-b9c9176 -git/github.com/MasterQ32/zig-uri git https://github.com/MasterQ32/zig-uri commit-f1896c6 -git/github.com/nektro/zig-json git https://github.com/nektro/zig-json commit-6599064 -git/github.com/nektro/zig-range git https://github.com/nektro/zig-range commit-890ca30 +2 +git https://github.com/yaml/libyaml tag-0.2.5 +git https://github.com/nektro/zig-ansi commit-930ab1f +git https://github.com/ziglibs/known-folders commit-f5e5fb8 +git https://github.com/nektro/zig-licenses commit-499bee6 +git https://github.com/truemedian/zfetch commit-2cefe80 +git https://github.com/truemedian/hzzp commit-2d30bdd +git https://github.com/alexnask/iguanaTLS commit-0d39a36 +git https://github.com/MasterQ32/zig-network commit-b9c9176 +git https://github.com/MasterQ32/zig-uri commit-f1896c6 +git https://github.com/nektro/zig-json commit-6599064 +git https://github.com/nektro/zig-range commit-890ca30 -- 2.54.0