| ... | @@ -1,4 +1,5 @@ | ... | @@ -1,4 +1,5 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| | 2 | const string = []const u8; |
| 2 | const gpa = std.heap.c_allocator; | 3 | const gpa = std.heap.c_allocator; |
| 3 | const builtin = @import("builtin"); | 4 | const builtin = @import("builtin"); |
| 4 | | 5 | |
| ... | @@ -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"; |
| 16 | | 17 | |
| | 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(); |
| 19 | | 23 | |
| 20 | try w.writeAll("zigmod"); | 24 | try w.writeAll("zigmod"); |
| 21 | | 25 | |
| 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 | } |
| 31 | | 30 | |
| 32 | try w.print(" {s}", .{@tagName(builtin.os.tag)}); | 31 | try w.print(" {s}", .{@tagName(builtin.os.tag)}); |