Skip to content

Commit d6f20b7

Browse files
committed
git lfs stuff
1 parent e094066 commit d6f20b7

File tree

4 files changed

+92
-1
lines changed

4 files changed

+92
-1
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
*.dylib filter=lfs diff=lfs merge=lfs -text
77
*.bin filter=lfs diff=lfs merge=lfs -text
88
*.exe filter=lfs diff=lfs merge=lfs -text
9+
.lfs-content-token filter=lfs diff=lfs merge=lfs -text

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
steps:
2121
- name: Checkout repository
2222
uses: actions/checkout@v3
23+
with:
24+
lfs: true
2325
- name: Install Zig
2426
uses: mlugg/setup-zig@v2
2527
- name: Check format

.lfs-content-token

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:936686ef9b9485f027086ce1ed7b4f7461d0ceb7eeccb573e48582055ca1c00f
3+
size 87

build.zig

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
const std = @import("std");
22

3-
pub fn build(b: *std.Build) void {
3+
pub fn build(b: *std.Build) !void {
4+
checkGitLfsContent() catch {
5+
try ensureGit(b.allocator);
6+
try ensureGitLfs(b.allocator, "install");
7+
try ensureGitLfs(b.allocator, "pull");
8+
try checkGitLfsContent();
9+
};
10+
411
const zopenvr = b.addModule("root", .{
512
.root_source_file = b.path("src/openvr.zig"),
613
});
@@ -120,3 +127,81 @@ pub fn installOpenVR(
120127
else => {},
121128
}
122129
}
130+
131+
fn ensureGit(allocator: std.mem.Allocator) !void {
132+
const printErrorMsg = (struct {
133+
fn impl() void {
134+
std.log.err("\n" ++
135+
\\---------------------------------------------------------------------------
136+
\\
137+
\\'git version' failed. Is Git not installed?
138+
\\
139+
\\---------------------------------------------------------------------------
140+
\\
141+
, .{});
142+
}
143+
}).impl;
144+
const argv = &[_][]const u8{ "git", "version" };
145+
const result = std.process.Child.run(.{
146+
.allocator = allocator,
147+
.argv = argv,
148+
}) catch { // e.g. FileNotFound
149+
printErrorMsg();
150+
return error.GitNotFound;
151+
};
152+
defer {
153+
allocator.free(result.stderr);
154+
allocator.free(result.stdout);
155+
}
156+
if (result.term.Exited != 0) {
157+
printErrorMsg();
158+
return error.GitNotFound;
159+
}
160+
}
161+
162+
fn ensureGitLfs(allocator: std.mem.Allocator, cmd: []const u8) !void {
163+
const printNoGitLfs = (struct {
164+
fn impl() void {
165+
std.log.err("\n" ++
166+
\\---------------------------------------------------------------------------
167+
\\
168+
\\Please install Git LFS (Large File Support) extension and run 'zig build' again.
169+
\\
170+
\\For more info about Git LFS see: https://git-lfs.github.com/
171+
\\
172+
\\---------------------------------------------------------------------------
173+
\\
174+
, .{});
175+
}
176+
}).impl;
177+
const argv = &[_][]const u8{ "git", "lfs", cmd };
178+
const result = std.process.Child.run(.{
179+
.allocator = allocator,
180+
.argv = argv,
181+
}) catch { // e.g. FileNotFound
182+
printNoGitLfs();
183+
return error.GitLfsNotFound;
184+
};
185+
defer {
186+
allocator.free(result.stderr);
187+
allocator.free(result.stdout);
188+
}
189+
if (result.term.Exited != 0) {
190+
printNoGitLfs();
191+
return error.GitLfsNotFound;
192+
}
193+
}
194+
195+
fn checkGitLfsContent() !void {
196+
const expected_contents =
197+
\\DO NOT EDIT OR DELETE
198+
\\This file is used to check if Git LFS content has been downloaded
199+
;
200+
var buf: [expected_contents.len]u8 = undefined;
201+
_ = std.fs.cwd().readFile(".lfs-content-token", &buf) catch {
202+
return error.GitLfsContentTokenNotFound;
203+
};
204+
if (!std.mem.eql(u8, expected_contents, &buf)) {
205+
return error.GitLfsContentCheckFailed;
206+
}
207+
}

0 commit comments

Comments
 (0)