diff options
| author | Isaac Freund <mail@isaacfreund.com> | 2022-05-16 22:34:43 +0200 |
|---|---|---|
| committer | Isaac Freund <mail@isaacfreund.com> | 2022-05-16 22:34:43 +0200 |
| commit | 7c440b834ecac898d603379e0944024d3617d9d8 (patch) | |
| tree | d61f5b2a8c08e799250cd555bc4565883e768c28 /build.zig | |
| parent | 7122df7ec46d03392f2440b9387612c1cc460c14 (diff) | |
| download | river-7c440b834ecac898d603379e0944024d3617d9d8.tar.gz river-7c440b834ecac898d603379e0944024d3617d9d8.tar.xz | |
build: follow semantic versioning for -dev versions
The new version format is 0.2.0-dev.76+d1cf95b which is compliant to the
semantic versioning 2.0.0 spec and sorts better than the old format.
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -55,15 +55,24 @@ pub fn build(b: *zbs.Builder) !void { const full_version = blk: { if (mem.endsWith(u8, version, "-dev")) { var ret: u8 = undefined; - const git_dir = try fs.path.join(b.allocator, &[_][]const u8{ b.build_root, ".git" }); - const git_commit_hash = b.execAllowFail( - &[_][]const u8{ "git", "--git-dir", git_dir, "--work-tree", b.build_root, "rev-parse", "--short", "HEAD" }, + + const git_describe_long = b.execAllowFail( + &[_][]const u8{ "git", "-C", b.build_root, "describe", "--long" }, &ret, .Inherit, ) catch break :blk version; - break :blk try std.fmt.allocPrintZ(b.allocator, "{s}-{s}", .{ - version, - mem.trim(u8, git_commit_hash, &std.ascii.spaces), + + var it = mem.split(u8, mem.trim(u8, git_describe_long, &std.ascii.spaces), "-"); + _ = it.next().?; // previous tag + const commit_count = it.next().?; + const commit_hash = it.next().?; + assert(it.next() == null); + assert(commit_hash[0] == 'g'); + + // Follow semantic versioning, e.g. 0.2.0-dev.42+d1cf95b + break :blk try std.fmt.allocPrintZ(b.allocator, version ++ ".{s}+{s}", .{ + commit_count, + commit_hash[1..], }); } else { break :blk version; |
