summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig28
1 files changed, 22 insertions, 6 deletions
diff --git a/build.zig b/build.zig
index c7cbea3d..73902a1b 100644
--- a/build.zig
+++ b/build.zig
@@ -284,6 +284,8 @@ pub fn build(b: *std.Build) void {
.prebuilt_shaders = prebuilt_shaders,
.embed_sources = embed_sources,
.commit = if (stamp_commit) gitCommit(b) else null,
+ .change = if (stamp_commit) jjChange(b) else null,
+ .built = if (stamp_commit) command(b, &.{ "date", "-u", "+%Y-%m-%d %H:%M UTC" }) else null,
};
const opts = shellOptions(b, shell_cfg, platform);
const gui_opts: ?*std.Build.Step.Options = if (also_gui) shellOptions(b, shell_cfg, .gui) else null;
@@ -1916,14 +1918,22 @@ fn installed(sub: []const u8) std.Build.LazyPath {
}
fn gitCommit(b: *std.Build) ?[]const u8 {
- // HEAD is not a file the configure cache can track.
+ return command(b, &.{ "git", "rev-parse", "--short=12", "HEAD" });
+}
+
+/// The jj change git HEAD is in, by its commit (jj 0.46 has no revset for
+/// git's HEAD), or null without jj.
+fn jjChange(b: *std.Build) ?[]const u8 {
+ const head = command(b, &.{ "git", "rev-parse", "HEAD" }) orelse return null;
+ return command(b, &.{ "jj", "log", "-r", head, "--no-graph", "-T", "change_id.short()" });
+}
+
+/// One line a command prints, or null: HEAD, the change, the clock are not
+/// files the configure cache can track, so the cache is poisoned.
+fn command(b: *std.Build, argv: []const []const u8) ?[]const u8 {
b.graph.poisonCache();
var code: u8 = 0;
- const out = b.runAllowFail(
- &.{ "git", "rev-parse", "--short=12", "HEAD" },
- &code,
- .ignore,
- ) catch return null;
+ const out = b.runAllowFail(argv, &code, .ignore) catch return null;
const trimmed = std.mem.trim(u8, out, " \t\r\n");
return if (trimmed.len == 0) null else trimmed;
}
@@ -1937,6 +1947,10 @@ const ShellConfig = struct {
prebuilt_shaders: bool,
embed_sources: bool,
commit: ?[]const u8,
+ /// The jj change git HEAD is in, and when this configure ran: the
+ /// `Build` word's, stamped with the commit (see `stamp_commit`).
+ change: ?[]const u8,
+ built: ?[]const u8,
};
fn shellOptions(b: *std.Build, cfg: ShellConfig, platform: Platform) *std.Build.Step.Options {
@@ -1953,6 +1967,8 @@ fn shellOptions(b: *std.Build, cfg: ShellConfig, platform: Platform) *std.Build.
// ...and the commit it was built from, when there is one and the build
// is stamped at all (see `stamp_commit`). Read at configure time.
o.addOption(?[]const u8, "commit", cfg.commit);
+ o.addOption(?[]const u8, "change", cfg.change);
+ o.addOption(?[]const u8, "built", cfg.built);
o.addOption([]const u8, "deps", deps_text);
return o;
}