| ... | ... | @@ -268,7 +268,29 @@ pub fn build(b: *std.Build) !void { |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // Ensure git version changes get picked up. |
| 271 | | b.dependOnFileContents(b.path(".git/HEAD")); |
| 271 | git: { |
| 272 | const io = b.graph.io; |
| 273 | const git_file = b.root.openFile(io, ".git", .{ .allow_directory = false }) catch |err| switch (err) { |
| 274 | error.IsDir => { |
| 275 | b.dependOnFileContents(b.path(".git/logs/HEAD")); |
| 276 | break :git; |
| 277 | }, |
| 278 | else => |e| return e, |
| 279 | }; |
| 280 | defer git_file.close(io); |
| 281 | var line_buffer: ["gitdir: ".len + std.Io.Dir.max_path_bytes + 1]u8 = undefined; |
| 282 | var git_file_reader = git_file.reader(io, &line_buffer); |
| 283 | if (std.mem.cutPrefix(u8, std.mem.trimEnd(u8, try git_file_reader.interface.allocRemaining( |
| 284 | arena, |
| 285 | .limited("gitdir: ".len + std.Io.Dir.max_path_bytes + "\r\n".len), |
| 286 | ), "\r\n"), "gitdir: ")) |git_dir| { |
| 287 | const head_file = b.pathJoin(&.{ git_dir, "logs", "HEAD" }); |
| 288 | b.dependOnFileContents(if (std.Io.Dir.path.isAbsolute(head_file)) |
| 289 | b.graph.cwdRelativePath(head_file) |
| 290 | else |
| 291 | b.path(head_file)); |
| 292 | } |
| 293 | } |
| 272 | 294 | |
| 273 | 295 | const version_string = b.fmt("{d}.{d}.{d}", .{ zig_version.major, zig_version.minor, zig_version.patch }); |
| 274 | 296 | |