| author | |
| committer | |
| log | c50bb32e0145da3e0329be5875e14007ab8559bc |
| tree | 0fdabc3aa33ed52c0804e2ee742fcf1d9cd10533 |
| parent | a6a764265792dafc3bc09c84aedcebdb9df28997 |
6 files changed, 51 insertions(+), 1 deletions(-)
src/cmd/fetch.zig+14| ... | ... | @@ -104,6 +104,20 @@ pub fn execute(args: [][]u8) !void { |
| 104 | 104 | try w.writeAll("pub const system_libs = &[_][]const u8{\n"); |
| 105 | 105 | try print_sys_libs_to(w, list.items, &std.ArrayList([]const u8).init(gpa)); |
| 106 | 106 | 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 | } | |
| 107 | 121 | } |
| 108 | 122 | |
| 109 | 123 | fn 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 |
| 40 | 40 | .only_os = &.{}, |
| 41 | 41 | .except_os = &.{}, |
| 42 | 42 | .yaml = m.yaml, |
| 43 | .dep = null, | |
| 43 | 44 | }; |
| 44 | 45 | } |
| 45 | 46 | |
| ... | ... | @@ -69,6 +70,7 @@ pub fn collect_deps(dir: []const u8, mpath: []const u8, options: CollectOptions) |
| 69 | 70 | .only_os = &.{}, |
| 70 | 71 | .except_os = &.{}, |
| 71 | 72 | .yaml = m.yaml, |
| 73 | .dep = null, | |
| 72 | 74 | }; |
| 73 | 75 | } |
| 74 | 76 | |
| ... | ... | @@ -197,6 +199,7 @@ pub fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []cons |
| 197 | 199 | .deps = &[_]u.Module{}, |
| 198 | 200 | .clean_path = d.path, |
| 199 | 201 | .yaml = null, |
| 202 | .dep = d, | |
| 200 | 203 | }); |
| 201 | 204 | }, |
| 202 | 205 | else => { |
| ... | ... | @@ -211,6 +214,7 @@ pub fn get_module_from_dep(list: *std.ArrayList(u.Module), d: u.Dep, dir: []cons |
| 211 | 214 | }, |
| 212 | 215 | else => e, |
| 213 | 216 | }; |
| 217 | dd.dep = d; | |
| 214 | 218 | const save = dd; |
| 215 | 219 | if (d.type != .local) dd.clean_path = u.trim_prefix(moddir, dir)[1..]; |
| 216 | 220 | 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 { |
| 73 | 73 | }, |
| 74 | 74 | } |
| 75 | 75 | } |
| 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 | } | |
| 76 | 86 | }; |
| 77 | 87 | |
| 78 | 88 | pub const GitVersionType = enum { |
src/util/funcs.zig+10| ... | ... | @@ -249,3 +249,13 @@ pub fn do_hash(comptime algo: type, data: []const u8) ![]const u8 { |
| 249 | 249 | const hex = try std.fmt.allocPrint(gpa, "{x}", .{std.fmt.fmtSliceHexLower(out[0..])}); |
| 250 | 250 | return hex; |
| 251 | 251 | } |
| 252 | ||
| 253 | /// Returns the result of running `git rev-parse HEAD` | |
| 254 | pub 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 { |
| 20 | 20 | only_os: []const []const u8, |
| 21 | 21 | except_os: []const []const u8, |
| 22 | 22 | yaml: ?yaml.Mapping, |
| 23 | ||
| 24 | 23 | deps: []Module, |
| 25 | 24 | clean_path: []const u8, |
| 25 | dep: ?u.Dep, | |
| 26 | 26 | |
| 27 | 27 | pub fn from(dep: u.Dep, dir: []const u8, options: common.CollectOptions) !Module { |
| 28 | 28 | const moddeps = &std.ArrayList(Module).init(gpa); |
| ... | ... | @@ -43,6 +43,7 @@ pub const Module = struct { |
| 43 | 43 | .only_os = dep.only_os, |
| 44 | 44 | .except_os = dep.except_os, |
| 45 | 45 | .yaml = dep.yaml, |
| 46 | .dep = dep, | |
| 46 | 47 | }; |
| 47 | 48 | } |
| 48 | 49 |
zig.lock created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | 8mdbh0zuneb0i3hs5jby5je0heem1i6yxusl7c8y8qx68hqc git https://github.com/yaml/libyaml tag-0.2.5 | |
| 2 | s84v9o48ucb0xq0cmzq0cn433hgw0iaqztugja16h8bzxu3h git https://github.com/nektro/zig-ansi commit-930ab1f | |
| 3 | 2ta738wrqbaqzl3iwzoo8nj35k9ynwz5p5iyz80ryrpp4ttf git https://github.com/ziglibs/known-folders commit-f5e5fb8 | |
| 4 | 0npcrzfdlrvkf44mzjo8bduj9gmqyefo0j3rstt6b0pm2r6r git https://github.com/nektro/zig-licenses commit-499bee6 | |
| 5 | ejw82j2ipa0eul25ohgdh6yy5nkrtn2pf0rq18m0079w6wj7 git https://github.com/truemedian/zfetch commit-2cefe80 | |
| 6 | 9k24gimke1anv665ilg4si32ayl3dsaqgmdfdpu1ceoky8tl git https://github.com/truemedian/hzzp commit-2d30bdd | |
| 7 | csbnipaad8n77buaszsnjvlmn6j173fl7pkprsctelswjywe git https://github.com/alexnask/iguanaTLS commit-0d39a36 | |
| 8 | yyhw90zkzgmubwpp87n0pzf936n850an66y1c6qan5y6sogv git https://github.com/MasterQ32/zig-network commit-b9c9176 | |
| 9 | u9w9dpp6p804p38o3u87f437pf942wxunyjite27dyhtu7ns git https://github.com/MasterQ32/zig-uri commit-f1896c6 | |
| 10 | ocmr9rtohgccd6gm6tp8b1yzylyzkqwvo1q4btrsvj0cse9y git https://github.com/nektro/zig-json commit-6599064 | |
| 11 | tnj3qf44tpeq469x94qnu7jzus5n7sen9ewrrn8kldngbac0 http https://aquila.red/1/nektro/range/v0.1.tar.gz sha256-d2f72fdd8cdb8 |