diff --git a/src/cmd/fetch.zig b/src/cmd/fetch.zig index 8f7121b1f788589e2fb75ed97336e9ceaf9148dc..3c4d71df0dffe792b2b05486cea5e2924de46d95 100644 --- a/src/cmd/fetch.zig +++ b/src/cmd/fetch.zig @@ -104,6 +104,20 @@ pub fn execute(args: [][]u8) !void { try w.writeAll("pub const system_libs = &[_][]const u8{\n"); try print_sys_libs_to(w, list.items, &std.ArrayList([]const u8).init(gpa)); try w.writeAll("};\n\n"); + + // + + const fl = try std.fs.cwd().createFile("zig.lock", .{}); + defer fl.close(); + + const wl = fl.writer(); + for (list.items) |m| { + if (m.dep) |md| { + 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))[0..14]; + try wl.print("{s} {s} {s} {s}\n", .{ m.id, @tagName(md.type), md.path, version }); + } + } } fn print_ids(w: std.fs.File.Writer, list: []u.Module) !void { diff --git a/src/common.zig b/src/common.zig index 1fb285b516043ef2adafdc9ed5dba3f1276a6751..182ca2f86d5478f6179d90fc2a4ce9f784127a16 100644 --- a/src/common.zig +++ b/src/common.zig @@ -40,6 +40,7 @@ pub fn collect_deps_deep(dir: []const u8, mpath: []const u8, options: CollectOpt .only_os = &.{}, .except_os = &.{}, .yaml = m.yaml, + .dep = null, }; } @@ -69,6 +70,7 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8, options: CollectOptions) .only_os = &.{}, .except_os = &.{}, .yaml = m.yaml, + .dep = null, }; } @@ -197,6 +199,7 @@ pub fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []cons .deps = &[_]u.Module{}, .clean_path = d.path, .yaml = null, + .dep = d, }); }, else => { @@ -211,6 +214,7 @@ pub fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []cons }, else => e, }; + dd.dep = d; const save = dd; if (d.type != .local) dd.clean_path = u.trim_prefix(moddir, dir)[1..]; if (dd.id.len == 0) dd.id = try u.random_string(48); diff --git a/src/util/dep_type.zig b/src/util/dep_type.zig index 0eedef3a1a8fdc9e046e400143bca60b4d150563..09afcba64210e79820f50cf8c1e549d7fb4a47df 100644 --- a/src/util/dep_type.zig +++ b/src/util/dep_type.zig @@ -73,6 +73,16 @@ pub const DepType = enum { }, } } + + pub fn exact_version(self: DepType, mpath: []const u8) ![]const u8 { + return switch (self) { + .local => "", + .system_lib => "", + .git => try std.fmt.allocPrint(gpa, "commit-{s}", .{try u.git_rev_HEAD(gpa, mpath)}), + .hg => "", + .http => "", + }; + } }; pub const GitVersionType = enum { diff --git a/src/util/funcs.zig b/src/util/funcs.zig index 80cbba3ea58418e0017c1836578f23a0b60d3e20..6db7907f5a1e422560d2de960c4169e7f98c23fe 100644 --- a/src/util/funcs.zig +++ b/src/util/funcs.zig @@ -249,3 +249,13 @@ pub fn do_hash(comptime algo: type, data: []const u8) ![]const u8 { const hex = try std.fmt.allocPrint(gpa, "{x}", .{std.fmt.fmtSliceHexLower(out[0..])}); return hex; } + +/// Returns the result of running `git rev-parse HEAD` +pub fn git_rev_HEAD(alloc: *std.mem.Allocator, path: []const u8) ![]const u8 { + const max = std.math.maxInt(usize); + const dir = try std.fs.cwd().openDir(path, .{}); + const dirg = try dir.openDir(".git", .{}); + const h = std.mem.trimRight(u8, try dirg.readFileAlloc(alloc, "HEAD", max), "\n"); + const r = std.mem.trimRight(u8, try dirg.readFileAlloc(alloc, h[5..], max), "\n"); + return r; +} diff --git a/src/util/module.zig b/src/util/module.zig index 3fbe32d16ce99380af8889cc3ad972196005cd20..530cbd0a984469b555927a1c70c3f0262612156e 100644 --- a/src/util/module.zig +++ b/src/util/module.zig @@ -20,9 +20,9 @@ pub const Module = struct { only_os: []const []const u8, except_os: []const []const u8, yaml: ?yaml.Mapping, - deps: []Module, clean_path: []const u8, + dep: ?u.Dep, pub fn from(dep: u.Dep, dir: []const u8, options: common.CollectOptions) !Module { const moddeps = &std.ArrayList(Module).init(gpa); @@ -43,6 +43,7 @@ pub const Module = struct { .only_os = dep.only_os, .except_os = dep.except_os, .yaml = dep.yaml, + .dep = dep, }; } diff --git a/zig.lock b/zig.lock new file mode 100644 index 0000000000000000000000000000000000000000..5368b55b55f02ae9b20e8824dd34b825b7893b2a --- /dev/null +++ b/zig.lock @@ -0,0 +1,11 @@ +8mdbh0zuneb0i3hs5jby5je0heem1i6yxusl7c8y8qx68hqc git https://github.com/yaml/libyaml tag-0.2.5 +s84v9o48ucb0xq0cmzq0cn433hgw0iaqztugja16h8bzxu3h git https://github.com/nektro/zig-ansi commit-930ab1f +2ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf git https://github.com/ziglibs/known-folders commit-f5e5fb8 +0npcrzfdlrvkf44mzjo8bduj9gmqyefo0j3rstt6b0pm2r6r git https://github.com/nektro/zig-licenses commit-499bee6 +ejw82j2ipa0eul25ohgdh6yy5nkrtn2pf0rq18m0079w6wj7 git https://github.com/truemedian/zfetch commit-2cefe80 +9k24gimke1anv665ilg4si32ayl3dsaqgmdfdpu1ceoky8tl git https://github.com/truemedian/hzzp commit-2d30bdd +csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe git https://github.com/alexnask/iguanaTLS commit-0d39a36 +yyhw90zkzgmubwpp87n0pzf936n850an66y1c6qan5y6sogv git https://github.com/MasterQ32/zig-network commit-b9c9176 +u9w9dpp6p804p38o3u87f437pf942wxunyjite27dyhtu7ns git https://github.com/MasterQ32/zig-uri commit-f1896c6 +ocmr9rtohgccd6gm6tp8b1yzylyzkqwvo1q4btrsvj0cse9y git https://github.com/nektro/zig-json commit-6599064 +tnj3qf44tpeq469x94qnu7jzus5n7sen9ewrrn8kldngbac0 http https://aquila.red/1/nektro/range/v0.1.tar.gz sha256-d2f72fdd8cdb8