2023-04-09 12:33:59 -04:00
|
|
|
const std = @import("std");
|
|
|
|
const root = @import("../build.zig");
|
|
|
|
|
|
|
|
const debug = std.debug;
|
2023-04-20 12:45:09 -04:00
|
|
|
const fmt = std.fmt;
|
2023-04-09 12:33:59 -04:00
|
|
|
const fs = std.fs;
|
2023-04-22 11:22:34 -04:00
|
|
|
const mem = std.mem;
|
2023-04-09 12:33:59 -04:00
|
|
|
|
2023-04-20 12:45:09 -04:00
|
|
|
const Allocator = std.mem.Allocator;
|
2023-05-04 13:01:48 -04:00
|
|
|
const Child = std.process.Child;
|
2024-01-05 03:15:51 -05:00
|
|
|
const Build = std.Build;
|
2024-01-05 03:17:09 -05:00
|
|
|
const LazyPath = std.Build.LazyPath;
|
2023-04-22 11:22:34 -04:00
|
|
|
const Reader = fs.File.Reader;
|
2023-04-09 12:33:59 -04:00
|
|
|
const RunStep = std.Build.RunStep;
|
2023-04-20 15:13:13 -04:00
|
|
|
const Step = Build.Step;
|
2023-04-09 12:33:59 -04:00
|
|
|
|
|
|
|
const Exercise = root.Exercise;
|
|
|
|
|
|
|
|
pub fn addCliTests(b: *std.Build, exercises: []const Exercise) *Step {
|
|
|
|
const step = b.step("test-cli", "Test the command line interface");
|
|
|
|
|
|
|
|
{
|
2023-05-13 07:58:12 -04:00
|
|
|
// Test that `zig build -Dhealed -Dn=n` selects the nth exercise.
|
2023-04-09 12:33:59 -04:00
|
|
|
const case_step = createCase(b, "case-1");
|
|
|
|
|
2023-05-05 10:13:57 -04:00
|
|
|
const tmp_path = makeTempPath(b) catch |err| {
|
|
|
|
return fail(step, "unable to make tmp path: {s}\n", .{@errorName(err)});
|
|
|
|
};
|
|
|
|
|
|
|
|
const heal_step = HealStep.create(b, exercises, tmp_path);
|
|
|
|
|
2023-04-09 12:33:59 -04:00
|
|
|
for (exercises[0 .. exercises.len - 1]) |ex| {
|
2023-05-04 10:34:17 -04:00
|
|
|
const n = ex.number();
|
2023-04-09 12:33:59 -04:00
|
|
|
|
2023-05-05 10:13:57 -04:00
|
|
|
const cmd = b.addSystemCommand(&.{
|
2024-02-05 16:06:19 -05:00
|
|
|
b.graph.zig_exe,
|
2023-05-05 10:13:57 -04:00
|
|
|
"build",
|
|
|
|
"-Dhealed",
|
|
|
|
b.fmt("-Dhealed-path={s}", .{tmp_path}),
|
|
|
|
b.fmt("-Dn={}", .{n}),
|
|
|
|
});
|
2023-05-13 07:58:12 -04:00
|
|
|
cmd.setName(b.fmt("zig build -Dhealed -Dn={}", .{n}));
|
2023-04-09 12:33:59 -04:00
|
|
|
cmd.expectExitCode(0);
|
2023-05-06 12:02:18 -04:00
|
|
|
cmd.step.dependOn(&heal_step.step);
|
2023-04-09 12:33:59 -04:00
|
|
|
|
2023-05-13 07:58:12 -04:00
|
|
|
const stderr = cmd.captureStdErr();
|
|
|
|
const verify = CheckNamedStep.create(b, ex, stderr);
|
2023-05-06 12:02:18 -04:00
|
|
|
verify.step.dependOn(&cmd.step);
|
2023-05-02 04:51:59 -04:00
|
|
|
|
2023-05-06 12:02:18 -04:00
|
|
|
case_step.dependOn(&verify.step);
|
2023-04-09 12:33:59 -04:00
|
|
|
}
|
|
|
|
|
2023-05-05 10:13:57 -04:00
|
|
|
const cleanup = b.addRemoveDirTree(tmp_path);
|
|
|
|
cleanup.step.dependOn(case_step);
|
|
|
|
|
|
|
|
step.dependOn(&cleanup.step);
|
2023-04-09 12:33:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2023-05-13 07:58:12 -04:00
|
|
|
// Test that `zig build -Dhealed` processes all the exercises in order.
|
2023-04-09 12:33:59 -04:00
|
|
|
const case_step = createCase(b, "case-2");
|
|
|
|
|
2023-05-05 10:13:57 -04:00
|
|
|
const tmp_path = makeTempPath(b) catch |err| {
|
|
|
|
return fail(step, "unable to make tmp path: {s}\n", .{@errorName(err)});
|
|
|
|
};
|
|
|
|
|
|
|
|
const heal_step = HealStep.create(b, exercises, tmp_path);
|
|
|
|
heal_step.step.dependOn(case_step);
|
|
|
|
|
2023-04-22 11:22:34 -04:00
|
|
|
// TODO: when an exercise is modified, the cache is not invalidated.
|
2023-05-05 10:13:57 -04:00
|
|
|
const cmd = b.addSystemCommand(&.{
|
2024-02-05 16:06:19 -05:00
|
|
|
b.graph.zig_exe,
|
2023-05-05 10:13:57 -04:00
|
|
|
"build",
|
|
|
|
"-Dhealed",
|
|
|
|
b.fmt("-Dhealed-path={s}", .{tmp_path}),
|
|
|
|
});
|
2023-04-22 11:22:34 -04:00
|
|
|
cmd.setName("zig build -Dhealed");
|
|
|
|
cmd.expectExitCode(0);
|
2023-05-02 04:51:59 -04:00
|
|
|
cmd.step.dependOn(&heal_step.step);
|
2023-04-22 11:22:34 -04:00
|
|
|
|
|
|
|
const stderr = cmd.captureStdErr();
|
2023-05-13 07:58:12 -04:00
|
|
|
const verify = CheckStep.create(b, exercises, stderr);
|
2023-04-22 11:22:34 -04:00
|
|
|
verify.step.dependOn(&cmd.step);
|
|
|
|
|
2023-05-05 10:13:57 -04:00
|
|
|
const cleanup = b.addRemoveDirTree(tmp_path);
|
|
|
|
cleanup.step.dependOn(&verify.step);
|
2023-04-22 11:22:34 -04:00
|
|
|
|
2023-05-05 10:13:57 -04:00
|
|
|
step.dependOn(&cleanup.step);
|
2023-04-22 11:22:34 -04:00
|
|
|
}
|
|
|
|
|
2023-04-24 07:03:52 -04:00
|
|
|
{
|
2023-05-14 11:17:01 -04:00
|
|
|
// Test that `zig build -Dn=n` prints the hint.
|
2023-05-13 07:58:12 -04:00
|
|
|
const case_step = createCase(b, "case-3");
|
2023-04-24 07:03:52 -04:00
|
|
|
|
2023-05-14 11:17:01 -04:00
|
|
|
for (exercises[0 .. exercises.len - 1]) |ex| {
|
2023-05-15 09:23:10 -04:00
|
|
|
if (ex.skip) continue;
|
2023-05-14 11:17:01 -04:00
|
|
|
|
|
|
|
if (ex.hint) |hint| {
|
|
|
|
const n = ex.number();
|
|
|
|
|
|
|
|
const cmd = b.addSystemCommand(&.{
|
2024-02-05 16:06:19 -05:00
|
|
|
b.graph.zig_exe,
|
2023-05-14 11:17:01 -04:00
|
|
|
"build",
|
|
|
|
b.fmt("-Dn={}", .{n}),
|
|
|
|
});
|
|
|
|
cmd.setName(b.fmt("zig build -Dn={}", .{n}));
|
|
|
|
cmd.expectExitCode(2);
|
|
|
|
cmd.addCheck(.{ .expect_stderr_match = hint });
|
|
|
|
|
|
|
|
case_step.dependOn(&cmd.step);
|
|
|
|
}
|
|
|
|
}
|
2023-04-24 07:03:52 -04:00
|
|
|
|
2023-05-14 11:17:01 -04:00
|
|
|
step.dependOn(case_step);
|
2023-04-24 07:03:52 -04:00
|
|
|
}
|
|
|
|
|
2023-04-09 12:33:59 -04:00
|
|
|
return step;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn createCase(b: *Build, name: []const u8) *Step {
|
|
|
|
const case_step = b.allocator.create(Step) catch @panic("OOM");
|
|
|
|
case_step.* = Step.init(.{
|
|
|
|
.id = .custom,
|
|
|
|
.name = name,
|
|
|
|
.owner = b,
|
|
|
|
});
|
|
|
|
|
|
|
|
return case_step;
|
|
|
|
}
|
|
|
|
|
2023-05-13 07:58:12 -04:00
|
|
|
/// Checks the output of `zig build -Dn=n`.
|
2023-05-06 12:02:18 -04:00
|
|
|
const CheckNamedStep = struct {
|
|
|
|
step: Step,
|
|
|
|
exercise: Exercise,
|
2024-01-05 03:17:09 -05:00
|
|
|
stderr: LazyPath,
|
2023-05-06 12:02:18 -04:00
|
|
|
|
2024-01-05 03:17:09 -05:00
|
|
|
pub fn create(owner: *Build, exercise: Exercise, stderr: LazyPath) *CheckNamedStep {
|
2023-05-06 12:02:18 -04:00
|
|
|
const self = owner.allocator.create(CheckNamedStep) catch @panic("OOM");
|
|
|
|
self.* = .{
|
|
|
|
.step = Step.init(.{
|
|
|
|
.id = .custom,
|
|
|
|
.name = "check-named",
|
|
|
|
.owner = owner,
|
|
|
|
.makeFn = make,
|
|
|
|
}),
|
|
|
|
.exercise = exercise,
|
2023-05-13 07:58:12 -04:00
|
|
|
.stderr = stderr,
|
2023-05-06 12:02:18 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2024-05-29 15:20:28 -04:00
|
|
|
fn make(step: *Step, _: std.Progress.Node) !void {
|
2023-05-06 12:02:18 -04:00
|
|
|
const b = step.owner;
|
2024-03-31 08:55:32 -04:00
|
|
|
const self: *CheckNamedStep = @alignCast(@fieldParentPtr("step", step));
|
2023-05-13 07:58:12 -04:00
|
|
|
const ex = self.exercise;
|
2023-05-06 12:02:18 -04:00
|
|
|
|
2023-05-13 07:58:12 -04:00
|
|
|
const stderr_file = try fs.cwd().openFile(
|
|
|
|
self.stderr.getPath(b),
|
|
|
|
.{ .mode = .read_only },
|
|
|
|
);
|
|
|
|
defer stderr_file.close();
|
2023-05-06 12:02:18 -04:00
|
|
|
|
2023-05-13 07:58:12 -04:00
|
|
|
const stderr = stderr_file.reader();
|
2023-05-13 14:36:49 -04:00
|
|
|
{
|
|
|
|
// Skip the logo.
|
|
|
|
const nlines = mem.count(u8, root.logo, "\n");
|
|
|
|
var buf: [80]u8 = undefined;
|
|
|
|
|
|
|
|
var lineno: usize = 0;
|
|
|
|
while (lineno < nlines) : (lineno += 1) {
|
|
|
|
_ = try readLine(stderr, &buf);
|
|
|
|
}
|
|
|
|
}
|
2023-05-13 07:58:12 -04:00
|
|
|
try check_output(step, ex, stderr);
|
2023-05-06 12:02:18 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-05-13 07:58:12 -04:00
|
|
|
/// Checks the output of `zig build`.
|
2023-04-22 11:22:34 -04:00
|
|
|
const CheckStep = struct {
|
|
|
|
step: Step,
|
|
|
|
exercises: []const Exercise,
|
2024-01-05 03:17:09 -05:00
|
|
|
stderr: LazyPath,
|
2023-04-22 11:22:34 -04:00
|
|
|
|
|
|
|
pub fn create(
|
|
|
|
owner: *Build,
|
|
|
|
exercises: []const Exercise,
|
2024-01-05 03:17:09 -05:00
|
|
|
stderr: LazyPath,
|
2023-04-22 11:22:34 -04:00
|
|
|
) *CheckStep {
|
|
|
|
const self = owner.allocator.create(CheckStep) catch @panic("OOM");
|
|
|
|
self.* = .{
|
|
|
|
.step = Step.init(.{
|
|
|
|
.id = .custom,
|
|
|
|
.name = "check",
|
|
|
|
.owner = owner,
|
|
|
|
.makeFn = make,
|
|
|
|
}),
|
|
|
|
.exercises = exercises,
|
|
|
|
.stderr = stderr,
|
|
|
|
};
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2024-05-29 15:20:28 -04:00
|
|
|
fn make(step: *Step, _: std.Progress.Node) !void {
|
2023-04-22 11:22:34 -04:00
|
|
|
const b = step.owner;
|
2024-03-31 08:55:32 -04:00
|
|
|
const self: *CheckStep = @alignCast(@fieldParentPtr("step", step));
|
2023-04-22 11:22:34 -04:00
|
|
|
const exercises = self.exercises;
|
|
|
|
|
|
|
|
const stderr_file = try fs.cwd().openFile(
|
|
|
|
self.stderr.getPath(b),
|
|
|
|
.{ .mode = .read_only },
|
|
|
|
);
|
|
|
|
defer stderr_file.close();
|
|
|
|
|
|
|
|
const stderr = stderr_file.reader();
|
|
|
|
for (exercises) |ex| {
|
2023-05-13 07:58:12 -04:00
|
|
|
if (ex.number() == 1) {
|
2023-04-22 11:22:34 -04:00
|
|
|
// Skip the logo.
|
2023-05-09 11:15:22 -04:00
|
|
|
const nlines = mem.count(u8, root.logo, "\n");
|
2023-04-22 11:22:34 -04:00
|
|
|
var buf: [80]u8 = undefined;
|
|
|
|
|
|
|
|
var lineno: usize = 0;
|
2023-05-09 11:15:22 -04:00
|
|
|
while (lineno < nlines) : (lineno += 1) {
|
2023-04-22 11:22:34 -04:00
|
|
|
_ = try readLine(stderr, &buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try check_output(step, ex, stderr);
|
|
|
|
}
|
|
|
|
}
|
2023-05-13 07:58:12 -04:00
|
|
|
};
|
2023-04-22 11:22:34 -04:00
|
|
|
|
2023-05-13 07:58:12 -04:00
|
|
|
fn check_output(step: *Step, exercise: Exercise, reader: Reader) !void {
|
|
|
|
const b = step.owner;
|
2023-04-22 11:22:34 -04:00
|
|
|
|
2023-05-13 07:58:12 -04:00
|
|
|
var buf: [1024]u8 = undefined;
|
|
|
|
if (exercise.skip) {
|
2023-04-22 11:22:34 -04:00
|
|
|
{
|
|
|
|
const actual = try readLine(reader, &buf) orelse "EOF";
|
2023-05-13 07:58:12 -04:00
|
|
|
const expect = b.fmt("Skipping {s}", .{exercise.main_file});
|
2023-04-22 11:22:34 -04:00
|
|
|
try check(step, exercise, expect, actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const actual = try readLine(reader, &buf) orelse "EOF";
|
2023-05-13 07:58:12 -04:00
|
|
|
try check(step, exercise, "", actual);
|
2023-04-22 11:22:34 -04:00
|
|
|
}
|
|
|
|
|
2023-05-13 07:58:12 -04:00
|
|
|
return;
|
|
|
|
}
|
2023-04-22 11:22:34 -04:00
|
|
|
|
2023-05-13 07:58:12 -04:00
|
|
|
{
|
|
|
|
const actual = try readLine(reader, &buf) orelse "EOF";
|
|
|
|
const expect = b.fmt("Compiling {s}...", .{exercise.main_file});
|
|
|
|
try check(step, exercise, expect, actual);
|
2023-04-22 11:22:34 -04:00
|
|
|
}
|
|
|
|
|
2023-05-13 07:58:12 -04:00
|
|
|
{
|
|
|
|
const actual = try readLine(reader, &buf) orelse "EOF";
|
|
|
|
const expect = b.fmt("Checking {s}...", .{exercise.main_file});
|
|
|
|
try check(step, exercise, expect, actual);
|
2023-04-22 11:22:34 -04:00
|
|
|
}
|
|
|
|
|
2023-05-13 07:58:12 -04:00
|
|
|
{
|
|
|
|
const actual = try readLine(reader, &buf) orelse "EOF";
|
2023-05-15 09:23:10 -04:00
|
|
|
const expect = switch (exercise.kind) {
|
|
|
|
.exe => "PASSED:",
|
|
|
|
.@"test" => "PASSED",
|
|
|
|
};
|
2023-05-13 07:58:12 -04:00
|
|
|
try check(step, exercise, expect, actual);
|
|
|
|
}
|
2023-04-22 11:22:34 -04:00
|
|
|
|
2023-05-13 07:58:12 -04:00
|
|
|
// Skip the exercise output.
|
2023-05-15 09:23:10 -04:00
|
|
|
const nlines = switch (exercise.kind) {
|
|
|
|
.exe => 1 + mem.count(u8, exercise.output, "\n") + 1,
|
|
|
|
.@"test" => 1,
|
|
|
|
};
|
|
|
|
|
2023-05-13 07:58:12 -04:00
|
|
|
var lineno: usize = 0;
|
|
|
|
while (lineno < nlines) : (lineno += 1) {
|
|
|
|
_ = try readLine(reader, &buf) orelse @panic("EOF");
|
2023-04-22 11:22:34 -04:00
|
|
|
}
|
2023-05-13 07:58:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
fn check(
|
|
|
|
step: *Step,
|
|
|
|
exercise: Exercise,
|
|
|
|
expect: []const u8,
|
|
|
|
actual: []const u8,
|
|
|
|
) !void {
|
|
|
|
if (!mem.eql(u8, expect, actual)) {
|
|
|
|
return step.fail("{s}: expected to see \"{s}\", found \"{s}\"", .{
|
|
|
|
exercise.main_file,
|
|
|
|
expect,
|
|
|
|
actual,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn readLine(reader: fs.File.Reader, buf: []u8) !?[]const u8 {
|
|
|
|
if (try reader.readUntilDelimiterOrEof(buf, '\n')) |line| {
|
|
|
|
return mem.trimRight(u8, line, " \r\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2023-04-22 11:22:34 -04:00
|
|
|
|
2023-05-04 12:48:35 -04:00
|
|
|
/// Fails with a custom error message.
|
2023-04-20 12:45:09 -04:00
|
|
|
const FailStep = struct {
|
2023-04-09 12:33:59 -04:00
|
|
|
step: Step,
|
2023-04-20 12:45:09 -04:00
|
|
|
error_msg: []const u8,
|
2023-04-09 12:33:59 -04:00
|
|
|
|
2023-04-20 12:45:09 -04:00
|
|
|
pub fn create(owner: *Build, error_msg: []const u8) *FailStep {
|
|
|
|
const self = owner.allocator.create(FailStep) catch @panic("OOM");
|
2023-04-09 12:33:59 -04:00
|
|
|
self.* = .{
|
|
|
|
.step = Step.init(.{
|
|
|
|
.id = .custom,
|
2023-04-20 12:45:09 -04:00
|
|
|
.name = "fail",
|
2023-04-09 12:33:59 -04:00
|
|
|
.owner = owner,
|
|
|
|
.makeFn = make,
|
|
|
|
}),
|
2023-04-20 12:45:09 -04:00
|
|
|
.error_msg = error_msg,
|
2023-04-09 12:33:59 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2024-05-29 15:20:28 -04:00
|
|
|
fn make(step: *Step, _: std.Progress.Node) !void {
|
2023-04-09 12:33:59 -04:00
|
|
|
const b = step.owner;
|
2024-03-31 08:55:32 -04:00
|
|
|
const self: *FailStep = @alignCast(@fieldParentPtr("step", step));
|
2023-04-20 12:45:09 -04:00
|
|
|
|
|
|
|
try step.result_error_msgs.append(b.allocator, self.error_msg);
|
|
|
|
return error.MakeFailed;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-05-04 12:48:35 -04:00
|
|
|
/// A variant of `std.Build.Step.fail` that does not return an error so that it
|
|
|
|
/// can be used in the configuration phase. It returns a FailStep, so that the
|
|
|
|
/// error will be cleanly handled by the build runner.
|
2023-04-20 12:45:09 -04:00
|
|
|
fn fail(step: *Step, comptime format: []const u8, args: anytype) *Step {
|
|
|
|
const b = step.owner;
|
|
|
|
|
|
|
|
const fail_step = FailStep.create(b, b.fmt(format, args));
|
|
|
|
step.dependOn(&fail_step.step);
|
|
|
|
|
|
|
|
return step;
|
|
|
|
}
|
|
|
|
|
2023-05-04 12:48:35 -04:00
|
|
|
/// Heals the exercises.
|
2023-05-02 04:51:59 -04:00
|
|
|
const HealStep = struct {
|
|
|
|
step: Step,
|
|
|
|
exercises: []const Exercise,
|
|
|
|
work_path: []const u8,
|
|
|
|
|
|
|
|
pub fn create(owner: *Build, exercises: []const Exercise, work_path: []const u8) *HealStep {
|
|
|
|
const self = owner.allocator.create(HealStep) catch @panic("OOM");
|
|
|
|
self.* = .{
|
|
|
|
.step = Step.init(.{
|
|
|
|
.id = .custom,
|
|
|
|
.name = "heal",
|
|
|
|
.owner = owner,
|
|
|
|
.makeFn = make,
|
|
|
|
}),
|
|
|
|
.exercises = exercises,
|
|
|
|
.work_path = work_path,
|
|
|
|
};
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2024-05-29 15:20:28 -04:00
|
|
|
fn make(step: *Step, _: std.Progress.Node) !void {
|
2023-05-02 04:51:59 -04:00
|
|
|
const b = step.owner;
|
2024-03-31 08:55:32 -04:00
|
|
|
const self: *HealStep = @alignCast(@fieldParentPtr("step", step));
|
2023-05-02 04:51:59 -04:00
|
|
|
|
|
|
|
return heal(b.allocator, self.exercises, self.work_path);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-05-04 12:48:35 -04:00
|
|
|
/// Heals all the exercises.
|
2023-05-02 04:51:59 -04:00
|
|
|
fn heal(allocator: Allocator, exercises: []const Exercise, work_path: []const u8) !void {
|
2023-05-09 05:00:16 -04:00
|
|
|
const sep = std.fs.path.sep_str;
|
2023-04-20 12:45:09 -04:00
|
|
|
const join = fs.path.join;
|
|
|
|
|
|
|
|
const exercises_path = "exercises";
|
2023-05-09 05:00:16 -04:00
|
|
|
const patches_path = "patches" ++ sep ++ "patches";
|
2023-04-20 12:45:09 -04:00
|
|
|
|
|
|
|
for (exercises) |ex| {
|
2023-04-30 12:48:52 -04:00
|
|
|
const name = ex.name();
|
2023-04-09 12:33:59 -04:00
|
|
|
|
2023-04-20 12:45:09 -04:00
|
|
|
const file = try join(allocator, &.{ exercises_path, ex.main_file });
|
|
|
|
const patch = b: {
|
|
|
|
const patch_name = try fmt.allocPrint(allocator, "{s}.patch", .{name});
|
|
|
|
break :b try join(allocator, &.{ patches_path, patch_name });
|
|
|
|
};
|
2023-05-02 04:51:59 -04:00
|
|
|
const output = try join(allocator, &.{ work_path, ex.main_file });
|
2023-04-09 12:33:59 -04:00
|
|
|
|
2023-04-29 10:50:28 -04:00
|
|
|
const argv = &.{ "patch", "-i", patch, "-o", output, "-s", file };
|
2023-04-09 12:33:59 -04:00
|
|
|
|
2023-05-04 13:01:48 -04:00
|
|
|
var child = Child.init(argv, allocator);
|
2023-04-09 12:33:59 -04:00
|
|
|
_ = try child.spawnAndWait();
|
|
|
|
}
|
2023-04-20 12:45:09 -04:00
|
|
|
}
|
2023-04-09 12:33:59 -04:00
|
|
|
|
2023-05-05 10:13:57 -04:00
|
|
|
/// This function is the same as the one in std.Build.makeTempPath, with the
|
|
|
|
/// difference that returns an error when the temp path cannot be created.
|
|
|
|
pub fn makeTempPath(b: *Build) ![]const u8 {
|
|
|
|
const rand_int = std.crypto.random.int(u64);
|
|
|
|
const tmp_dir_sub_path = "tmp" ++ fs.path.sep_str ++ Build.hex64(rand_int);
|
|
|
|
const path = b.cache_root.join(b.allocator, &.{tmp_dir_sub_path}) catch
|
|
|
|
@panic("OOM");
|
|
|
|
try b.cache_root.handle.makePath(tmp_dir_sub_path);
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|