Skip to content

Commit 302aaee

Browse files
committed
reorganize and remember to close files
1 parent ea17428 commit 302aaee

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

build.zig

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -387,31 +387,28 @@ pub fn build(b: *std.Build) !void {
387387
examples_step.dependOn(&example_run.step);
388388
}
389389

390-
// @Todo: is there a better way to do this? this feels hacky
391-
//
392-
// Fix the test fixture file permissions. This is necessary because Zig does
393-
// not respect the execute permission on files it extracts from dependencies.
394-
// Since we need those files to have the execute permission set for tests to
395-
// run successfully, we need to patch them before we bake them into the
396-
// test executable.
390+
const test_step = b.step("test", "Run core unit tests (requires python)");
397391
{
398-
const file_paths = &[_]std.Build.LazyPath{
392+
// Fix the test fixture file permissions. This is necessary because Zig does
393+
// not respect the execute permission on arbitrary files it extracts from dependencies.
394+
// Since we need those files to have the execute permission set for tests to
395+
// run successfully, we need to patch them before we bake them into the
396+
// test executable. While modifying the global cache is hacky, it wont break
397+
// hashes for the same reason above.
398+
for ([_]std.Build.LazyPath{
399399
libgit_root.path(b, "tests/resources/filemodes/exec_on"),
400400
libgit_root.path(b, "tests/resources/filemodes/exec_off2on_staged"),
401401
libgit_root.path(b, "tests/resources/filemodes/exec_off2on_workdir"),
402402
libgit_root.path(b, "tests/resources/filemodes/exec_on_untracked"),
403-
};
404-
for (file_paths) |lazy| {
403+
}) |lazy| {
405404
const path = lazy.getPath2(b, null);
406405
const file = try std.fs.cwd().openFile(path, .{
407406
.mode = .read_write,
408407
});
408+
defer file.close();
409409
try file.setPermissions(.{ .inner = .{ .mode = 0o755 } });
410410
}
411-
}
412411

413-
const test_step = b.step("test", "Run core unit tests (requires python)");
414-
{
415412
const gen_cmd = b.addSystemCommand(&.{"python"});
416413
gen_cmd.addFileArg(libgit_src.path("tests/clar/generate.py"));
417414
const clar_suite = gen_cmd.addPrefixedOutputDirectoryArg("-o", "clar_suite");

0 commit comments

Comments
 (0)