Remove 'g' prefix from commit hash in Zig semver

This commit is contained in:
Jay Petacat 2020-12-30 20:57:50 -06:00
parent 4af763d401
commit 02438aabe3
2 changed files with 9 additions and 3 deletions

View File

@ -46,7 +46,7 @@ if("${ZIG_VERSION}" STREQUAL "")
if(NOT GIT_TAG VERSION_EQUAL ZIG_VERSION)
message(SEND_ERROR "Zig version (${ZIG_VERSION}) does not match Git tag (${GIT_TAG}).")
endif()
elseif(GIT_DESCRIBE MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)-([0-9]+)-(.+)$")
elseif(GIT_DESCRIBE MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)-([0-9]+)-g(.+)$")
# Untagged pre-release. The Zig version is updated to include the number of commits
# since the last tagged version and the commit hash. The version is formatted in
# accordance with the https://semver.org specification.

View File

@ -256,11 +256,17 @@ pub fn build(b: *Builder) !void {
std.process.exit(1);
}
// Check that the commit hash is prefixed with a 'g' (a Git convention).
if (commit_id.len < 1 or commit_id[0] != 'g') {
std.debug.print("Unexpected `git describe` output: {}\n", .{git_describe});
break :v version_string;
}
// The version is reformatted in accordance with the https://semver.org specification.
break :v b.fmt("{}-dev.{}+{}", .{ version_string, commit_height, commit_id });
break :v b.fmt("{}-dev.{}+{}", .{ version_string, commit_height, commit_id[1..] });
},
else => {
std.debug.print("Failed to parse `git describe` output: {}\n", .{git_describe});
std.debug.print("Unexpected `git describe` output: {}\n", .{git_describe});
break :v version_string;
},
}