authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-04 02:59:19 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-04 02:59:19 -07:00
logc50bb32e0145da3e0329be5875e14007ab8559bc
tree0fdabc3aa33ed52c0804e2ee742fcf1d9cd10533
parenta6a764265792dafc3bc09c84aedcebdb9df28997

add lock file generation


6 files changed, 51 insertions(+), 1 deletions(-)

src/cmd/fetch.zig+14
......@@ -104,6 +104,20 @@ pub fn execute(args: [][]u8) !void {
104104 try w.writeAll("pub const system_libs = &[_][]const u8{\n");
105105 try print_sys_libs_to(w, list.items, &std.ArrayList([]const u8).init(gpa));
106106 try w.writeAll("};\n\n");
107
108 //
109
110 const fl = try std.fs.cwd().createFile("zig.lock", .{});
111 defer fl.close();
112
113 const wl = fl.writer();
114 for (list.items) |m| {
115 if (m.dep) |md| {
116 const mpath = try std.fs.path.join(gpa, &.{ dir, m.clean_path });
117 const version = if (md.version.len > 0) md.version else (try md.type.exact_version(mpath))[0..14];
118 try wl.print("{s} {s} {s} {s}\n", .{ m.id, @tagName(md.type), md.path, version });
119 }
120 }
107121}
108122
109123fn print_ids(w: std.fs.File.Writer, list: []u.Module) !void {
src/common.zig+4
......@@ -40,6 +40,7 @@ pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: CollectOpt
4040 .only_os = &.{},
4141 .except_os = &.{},
4242 .yaml = m.yaml,
43 .dep = null,
4344 };
4445}
4546
......@@ -69,6 +70,7 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8, options: CollectOptions)
6970 .only_os = &.{},
7071 .except_os = &.{},
7172 .yaml = m.yaml,
73 .dep = null,
7274 };
7375}
7476
......@@ -197,6 +199,7 @@ pub fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []cons
197199 .deps = &[_]u.Module{},
198200 .clean_path = d.path,
199201 .yaml = null,
202 .dep = d,
200203 });
201204 },
202205 else => {
......@@ -211,6 +214,7 @@ pub fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []cons
211214 },
212215 else => e,
213216 };
217 dd.dep = d;
214218 const save = dd;
215219 if (d.type != .local) dd.clean_path = u.trim_prefix(moddir, dir)[1..];
216220 if (dd.id.len == 0) dd.id = try u.random_string(48);
src/util/dep_type.zig+10
......@@ -73,6 +73,16 @@ pub const DepType = enum {
7373 },
7474 }
7575 }
76
77 pub fn exact_version(self: DepType, mpath: []const u8) ![]const u8 {
78 return switch (self) {
79 .local => "",
80 .system_lib => "",
81 .git => try std.fmt.allocPrint(gpa, "commit-{s}", .{try u.git_rev_HEAD(gpa, mpath)}),
82 .hg => "",
83 .http => "",
84 };
85 }
7686};
7787
7888pub const GitVersionType = enum {
src/util/funcs.zig+10
......@@ -249,3 +249,13 @@ pub fn do_hash(comptime algo: type, data: []const u8) ![]const u8 {
249249 const hex = try std.fmt.allocPrint(gpa, "{x}", .{std.fmt.fmtSliceHexLower(out[0..])});
250250 return hex;
251251}
252
253/// Returns the result of running `git rev-parse HEAD`
254pub fn git_rev_HEAD(alloc: *std.mem.Allocator, path: []const u8) ![]const u8 {
255 const max = std.math.maxInt(usize);
256 const dir = try std.fs.cwd().openDir(path, .{});
257 const dirg = try dir.openDir(".git", .{});
258 const h = std.mem.trimRight(u8, try dirg.readFileAlloc(alloc, "HEAD", max), "\n");
259 const r = std.mem.trimRight(u8, try dirg.readFileAlloc(alloc, h[5..], max), "\n");
260 return r;
261}
src/util/module.zig+2-1
......@@ -20,9 +20,9 @@ pub const Module = struct {
2020 only_os: []const []const u8,
2121 except_os: []const []const u8,
2222 yaml: ?yaml.Mapping,
23
2423 deps: []Module,
2524 clean_path: []const u8,
25 dep: ?u.Dep,
2626
2727 pub fn from(dep: u.Dep, dir: []const u8, options: common.CollectOptions) !Module {
2828 const moddeps = &std.ArrayList(Module).init(gpa);
......@@ -43,6 +43,7 @@ pub const Module = struct {
4343 .only_os = dep.only_os,
4444 .except_os = dep.except_os,
4545 .yaml = dep.yaml,
46 .dep = dep,
4647 };
4748 }
4849
zig.lock created+11
......@@ -0,0 +1,11 @@
18mdbh0zuneb0i3hs5jby5je0heem1i6yxusl7c8y8qx68hqc git https://github.com/yaml/libyaml tag-0.2.5
2s84v9o48ucb0xq0cmzq0cn433hgw0iaqztugja16h8bzxu3h git https://github.com/nektro/zig-ansi commit-930ab1f
32ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf git https://github.com/ziglibs/known-folders commit-f5e5fb8
40npcrzfdlrvkf44mzjo8bduj9gmqyefo0j3rstt6b0pm2r6r git https://github.com/nektro/zig-licenses commit-499bee6
5ejw82j2ipa0eul25ohgdh6yy5nkrtn2pf0rq18m0079w6wj7 git https://github.com/truemedian/zfetch commit-2cefe80
69k24gimke1anv665ilg4si32ayl3dsaqgmdfdpu1ceoky8tl git https://github.com/truemedian/hzzp commit-2d30bdd
7csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe git https://github.com/alexnask/iguanaTLS commit-0d39a36
8yyhw90zkzgmubwpp87n0pzf936n850an66y1c6qan5y6sogv git https://github.com/MasterQ32/zig-network commit-b9c9176
9u9w9dpp6p804p38o3u87f437pf942wxunyjite27dyhtu7ns git https://github.com/MasterQ32/zig-uri commit-f1896c6
10ocmr9rtohgccd6gm6tp8b1yzylyzkqwvo1q4btrsvj0cse9y git https://github.com/nektro/zig-json commit-6599064
11tnj3qf44tpeq469x94qnu7jzus5n7sen9ewrrn8kldngbac0 http https://aquila.red/1/nektro/range/v0.1.tar.gz sha256-d2f72fdd8cdb8