mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
Merge pull request #2172 from ghostty-org/push-kpnkvvmzysom
build: build without Git, tag version as dev with 0 SHA
This commit is contained in:
13
build.zig
13
build.zig
@ -177,7 +177,18 @@ pub fn build(b: *std.Build) !void {
|
|||||||
config.version = if (version_string) |v|
|
config.version = if (version_string) |v|
|
||||||
try std.SemanticVersion.parse(v)
|
try std.SemanticVersion.parse(v)
|
||||||
else version: {
|
else version: {
|
||||||
const vsn = try Version.detect(b);
|
const vsn = Version.detect(b) catch |err| switch (err) {
|
||||||
|
// If Git isn't available we just make an unknown dev version.
|
||||||
|
error.GitNotFound => break :version .{
|
||||||
|
.major = app_version.major,
|
||||||
|
.minor = app_version.minor,
|
||||||
|
.patch = app_version.patch,
|
||||||
|
.pre = "dev",
|
||||||
|
.build = "0000000",
|
||||||
|
},
|
||||||
|
|
||||||
|
else => return err,
|
||||||
|
};
|
||||||
if (vsn.tag) |tag| {
|
if (vsn.tag) |tag| {
|
||||||
// Tip releases behave just like any other pre-release so we skip.
|
// Tip releases behave just like any other pre-release so we skip.
|
||||||
if (!std.mem.eql(u8, tag, "tip")) {
|
if (!std.mem.eql(u8, tag, "tip")) {
|
||||||
|
@ -19,14 +19,34 @@ branch: []const u8,
|
|||||||
pub fn detect(b: *std.Build) !Version {
|
pub fn detect(b: *std.Build) !Version {
|
||||||
// Execute a bunch of git commands to determine the automatic version.
|
// Execute a bunch of git commands to determine the automatic version.
|
||||||
var code: u8 = 0;
|
var code: u8 = 0;
|
||||||
const branch = try b.runAllowFail(&[_][]const u8{ "git", "-C", b.build_root.path orelse ".", "rev-parse", "--abbrev-ref", "HEAD" }, &code, .Ignore);
|
const branch: []const u8 = b.runAllowFail(
|
||||||
|
&[_][]const u8{ "git", "-C", b.build_root.path orelse ".", "rev-parse", "--abbrev-ref", "HEAD" },
|
||||||
|
&code,
|
||||||
|
.Ignore,
|
||||||
|
) catch |err| switch (err) {
|
||||||
|
error.FileNotFound => return error.GitNotFound,
|
||||||
|
else => return err,
|
||||||
|
};
|
||||||
|
|
||||||
const short_hash = short_hash: {
|
const short_hash = short_hash: {
|
||||||
const output = try b.runAllowFail(&[_][]const u8{ "git", "-C", b.build_root.path orelse ".", "log", "--pretty=format:%h", "-n", "1" }, &code, .Ignore);
|
const output = b.runAllowFail(
|
||||||
|
&[_][]const u8{ "git", "-C", b.build_root.path orelse ".", "log", "--pretty=format:%h", "-n", "1" },
|
||||||
|
&code,
|
||||||
|
.Ignore,
|
||||||
|
) catch |err| switch (err) {
|
||||||
|
error.FileNotFound => return error.GitNotFound,
|
||||||
|
else => return err,
|
||||||
|
};
|
||||||
|
|
||||||
break :short_hash std.mem.trimRight(u8, output, "\r\n ");
|
break :short_hash std.mem.trimRight(u8, output, "\r\n ");
|
||||||
};
|
};
|
||||||
|
|
||||||
const tag = b.runAllowFail(&[_][]const u8{ "git", "-C", b.build_root.path orelse ".", "describe", "--exact-match", "--tags" }, &code, .Ignore) catch |err| switch (err) {
|
const tag = b.runAllowFail(
|
||||||
|
&[_][]const u8{ "git", "-C", b.build_root.path orelse ".", "describe", "--exact-match", "--tags" },
|
||||||
|
&code,
|
||||||
|
.Ignore,
|
||||||
|
) catch |err| switch (err) {
|
||||||
|
error.FileNotFound => return error.GitNotFound,
|
||||||
error.ExitCodeFailure => "", // expected
|
error.ExitCodeFailure => "", // expected
|
||||||
else => return err,
|
else => return err,
|
||||||
};
|
};
|
||||||
@ -39,6 +59,7 @@ pub fn detect(b: *std.Build) !Version {
|
|||||||
"--quiet",
|
"--quiet",
|
||||||
"--exit-code",
|
"--exit-code",
|
||||||
}, &code, .Ignore) catch |err| switch (err) {
|
}, &code, .Ignore) catch |err| switch (err) {
|
||||||
|
error.FileNotFound => return error.GitNotFound,
|
||||||
error.ExitCodeFailure => {}, // expected
|
error.ExitCodeFailure => {}, // expected
|
||||||
else => return err,
|
else => return err,
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user