authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-11 11:59:32 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-11 11:59:32 -07:00
log4af6aa9409cc8e61c11d270008e9238d137b067b
treea78795ab7a0f572788835ec3752246ec1f4096f4
parentcf8686516941180d02cab74eb1fc4412c8a377d5

cmd/verison- catch git_rev_HEAD and fallback, fixes #35


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

src/cmd/version.zig+6-7
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const string = []const u8;
2const gpa = std.heap.c_allocator;3const gpa = std.heap.c_allocator;
3const builtin = @import("builtin");4const builtin = @import("builtin");
45
...@@ -14,19 +15,17 @@ pub fn execute(args: [][]u8) !void {...@@ -14,19 +15,17 @@ pub fn execute(args: [][]u8) !void {
14 const build_options = if (@hasDecl(root, "build_options")) root.build_options else struct {};15 const build_options = if (@hasDecl(root, "build_options")) root.build_options else struct {};
15 const version = if (@hasDecl(build_options, "version")) build_options.version else "unknown";16 const version = if (@hasDecl(build_options, "version")) build_options.version else "unknown";
1617
18 var gitversion = u.git_rev_HEAD(gpa, std.fs.cwd()) catch "";
19 gitversion = if (gitversion.len > 0) gitversion[0..7] else gitversion;
20
17 const stdout = std.io.getStdOut();21 const stdout = std.io.getStdOut();
18 const w = stdout.writer();22 const w = stdout.writer();
1923
20 try w.writeAll("zigmod");24 try w.writeAll("zigmod");
2125
22 try w.print(" {s}", .{version});26 try w.print(" {s}", .{version});
23 if (std.mem.eql(u8, version, "dev")) {27 if (std.mem.eql(u8, version, "dev") and gitversion.len > 0) {
24 try w.print(28 try w.print("-{s}", .{gitversion});
25 "-{s}",
26 .{
27 (try u.git_rev_HEAD(gpa, std.fs.cwd()))[0..7],
28 },
29 );
30 }29 }
3130
32 try w.print(" {s}", .{@tagName(builtin.os.tag)});31 try w.print(" {s}", .{@tagName(builtin.os.tag)});