Skip to content

Commit

Permalink
allow a package depending on zls to skip 'git describe'
Browse files Browse the repository at this point in the history
  • Loading branch information
pfgithub committed Jan 29, 2025
1 parent 6a16b27 commit d746d19
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ pub fn build(b: *Build) !void {
const enable_tracy_callstack = b.option(bool, "enable-tracy-callstack", "Enable callstack graphs.") orelse enable_tracy;
const test_filters = b.option([]const []const u8, "test-filter", "Skip tests that do not match filter") orelse &.{};
const use_llvm = b.option(bool, "use-llvm", "Use Zig's llvm code backend");
const commit_hash = b.option([]const u8, "commit-hash", "Use the specified commit hash rather than running 'git describe'");

const resolved_zls_version = getVersion(b);
const resolved_zls_version = getVersion(b, commit_hash);
const resolved_zls_version_string = b.fmt("{}", .{resolved_zls_version});

const build_options = blk: {
Expand Down Expand Up @@ -283,11 +284,20 @@ pub fn build(b: *Build) !void {
}

/// Returns `MAJOR.MINOR.PATCH-dev` when `git describe` failed.
fn getVersion(b: *Build) std.SemanticVersion {
fn getVersion(b: *Build, override_commit_hash: ?[]const u8) std.SemanticVersion {
if (zls_version.pre == null and zls_version.build == null) return zls_version;
if (override_commit_hash) |hash| {
return .{
.major = zls_version.major,
.minor = zls_version.minor,
.patch = zls_version.patch,
.pre = "dev",
.build = hash[0..@min(hash.len, 7)],
};
}

const argv: []const []const u8 = &.{
"git", "-C", b.pathFromRoot("."), "describe", "--match", "*.*.*", "--tags",
"git", "-C", b.path(".").getPath2(b, null), "describe", "--match", "*.*.*", "--tags",
};
var code: u8 = undefined;
const git_describe_untrimmed = b.runAllowFail(argv, &code, .Ignore) catch |err| {
Expand Down

0 comments on commit d746d19

Please sign in to comment.