authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2020-12-25 17:18:44-05:00
committergravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2020-12-25 17:18:44-05:00
logec102951cb9ef7f9859ff719fc77afd264d66a5b
tree3f8b29fa1ed95375803fc51f398553dc7a0be129
parent1322a7314139206b3b67240b826d02821cc87a7f

remove git diff dirty changes feature from build.zig


1 files changed, 2 insertions(+), 18 deletions(-)

build.zig+2-18
...@@ -234,22 +234,6 @@ pub fn build(b: *Builder) !void {...@@ -234,22 +234,6 @@ pub fn build(b: *Builder) !void {
234 break :v version_string;234 break :v version_string;
235 };235 };
236 const git_sha_trimmed = mem.trim(u8, git_sha_untrimmed, " \n\r");236 const git_sha_trimmed = mem.trim(u8, git_sha_untrimmed, " \n\r");
237 // Detect dirty changes.
238 const diff_untrimmed = b.execAllowFail(&[_][]const u8{
239 "git", "-C", b.build_root, "diff", "HEAD",
240 }, &code, .Ignore) catch |err| switch (err) {
241 // when there is a big diff, usually after resolving merge conflicts, but before a commit
242 error.StreamTooLong => "dirty_diff_too_big",
243 else => {
244 std.debug.print("Error executing git diff: {}\n", .{err});
245 std.process.exit(1);
246 },
247 };
248 const trimmed_diff = mem.trim(u8, diff_untrimmed, " \n\r");
249 const dirty_suffix = if (trimmed_diff.len == 0) "" else s: {
250 const dirty_hash = std.hash.Wyhash.hash(0, trimmed_diff);
251 break :s b.fmt("dirty{x}", .{@truncate(u32, dirty_hash)});
252 };
253237
254 // This will look like e.g. "0.7.0^0" for a tag commit.238 // This will look like e.g. "0.7.0^0" for a tag commit.
255 if (mem.endsWith(u8, git_sha_trimmed, "^0")) {239 if (mem.endsWith(u8, git_sha_trimmed, "^0")) {
...@@ -258,9 +242,9 @@ pub fn build(b: *Builder) !void {...@@ -258,9 +242,9 @@ pub fn build(b: *Builder) !void {
258 std.debug.print("Expected git tag '{}', found '{}'\n", .{ version_string, git_ver_string });242 std.debug.print("Expected git tag '{}', found '{}'\n", .{ version_string, git_ver_string });
259 std.process.exit(1);243 std.process.exit(1);
260 }244 }
261 break :v b.fmt("{}{}", .{ version_string, dirty_suffix });245 break :v b.fmt("{}", .{version_string});
262 } else {246 } else {
263 break :v b.fmt("{}+{}{}", .{ version_string, git_sha_trimmed, dirty_suffix });247 break :v b.fmt("{}+{}", .{ version_string, git_sha_trimmed });
264 }248 }
265 };249 };
266 exe.addBuildOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version));250 exe.addBuildOption([:0]const u8, "version", try b.allocator.dupeZ(u8, version));