mirror of
https://github.com/zigzap/zap.git
synced 2025-10-21 07:34:08 +00:00
build.zig adds pre-commit hook
This commit is contained in:
parent
084d335661
commit
4ccd8d8620
1 changed files with 17 additions and 2 deletions
19
build.zig
19
build.zig
|
@ -68,6 +68,7 @@ pub fn ensureDeps(step: *std.build.Step) !void {
|
||||||
_ = step;
|
_ = step;
|
||||||
const allocator = std.heap.page_allocator;
|
const allocator = std.heap.page_allocator;
|
||||||
ensureGit(allocator);
|
ensureGit(allocator);
|
||||||
|
ensureGitHook(allocator);
|
||||||
try ensureSubmodule(allocator, "src/deps/facilio");
|
try ensureSubmodule(allocator, "src/deps/facilio");
|
||||||
try ensurePatch(allocator, "src/deps/facilio", "../0001-microsecond-logging.patch");
|
try ensurePatch(allocator, "src/deps/facilio", "../0001-microsecond-logging.patch");
|
||||||
ensureMake(allocator);
|
ensureMake(allocator);
|
||||||
|
@ -127,7 +128,7 @@ fn ensureGit(allocator: std.mem.Allocator) void {
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.argv = &.{ "git", "--version" },
|
.argv = &.{ "git", "--version" },
|
||||||
}) catch { // e.g. FileNotFound
|
}) catch { // e.g. FileNotFound
|
||||||
std.log.err("mach: error: 'git --version' failed. Is git not installed?", .{});
|
std.log.err("error: 'git --version' failed. Is git not installed?", .{});
|
||||||
std.process.exit(1);
|
std.process.exit(1);
|
||||||
};
|
};
|
||||||
defer {
|
defer {
|
||||||
|
@ -135,11 +136,25 @@ fn ensureGit(allocator: std.mem.Allocator) void {
|
||||||
allocator.free(result.stdout);
|
allocator.free(result.stdout);
|
||||||
}
|
}
|
||||||
if (result.term.Exited != 0) {
|
if (result.term.Exited != 0) {
|
||||||
std.log.err("mach: error: 'git --version' failed. Is git not installed?", .{});
|
std.log.err("error: 'git --version' failed. Is git not installed?", .{});
|
||||||
std.process.exit(1);
|
std.process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn ensureGitHook(allocator: std.mem.Allocator) void {
|
||||||
|
var child = std.ChildProcess.init(
|
||||||
|
&.{ "cp", "precommit-hook.sh", ".git/hooks/pre-commit" },
|
||||||
|
allocator,
|
||||||
|
);
|
||||||
|
child.cwd = sdkPath("/");
|
||||||
|
child.stderr = std.io.getStdErr();
|
||||||
|
child.stdout = std.io.getStdOut();
|
||||||
|
_ = child.spawnAndWait() catch {
|
||||||
|
std.log.err("Warning: unable to install git precommit-hook ", .{});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
fn ensureSubmodule(allocator: std.mem.Allocator, path: []const u8) !void {
|
fn ensureSubmodule(allocator: std.mem.Allocator, path: []const u8) !void {
|
||||||
if (std.process.getEnvVarOwned(allocator, "NO_ENSURE_SUBMODULES")) |no_ensure_submodules| {
|
if (std.process.getEnvVarOwned(allocator, "NO_ENSURE_SUBMODULES")) |no_ensure_submodules| {
|
||||||
defer allocator.free(no_ensure_submodules);
|
defer allocator.free(no_ensure_submodules);
|
||||||
|
|
Loading…
Add table
Reference in a new issue