Apply temp patches
This commit is contained in:
parent
5b51d6f393
commit
68bb75644b
3 changed files with 23 additions and 16 deletions
|
|
@ -1,5 +1,7 @@
|
|||
# Ziglings
|
||||
|
||||
-> Fix originally by [nerdman](https://codeberg.org/nerdman) from [this issue](https://codeberg.org/ziglings/exercises/issues/127).
|
||||
|
||||
Welcome to Ziglings! This project contains a series of tiny
|
||||
broken programs (and one nasty surprise). By fixing them, you'll
|
||||
learn how to read and write [Zig](https://ziglang.org/) code.
|
||||
|
|
|
|||
12
build.zig
12
build.zig
|
|
@ -274,7 +274,7 @@ const ZiglingStep = struct {
|
|||
return self;
|
||||
}
|
||||
|
||||
fn make(step: *Step, prog_node: std.Progress.Node) !void {
|
||||
fn make(step: *Step, options: Step.MakeOptions) !void {
|
||||
// NOTE: Using exit code 2 will prevent the Zig compiler to print the message:
|
||||
// "error: the following build command failed with exit code 1:..."
|
||||
const self: *ZiglingStep = @alignCast(@fieldParentPtr("step", step));
|
||||
|
|
@ -285,7 +285,7 @@ const ZiglingStep = struct {
|
|||
return;
|
||||
}
|
||||
|
||||
const exe_path = self.compile(prog_node) catch {
|
||||
const exe_path = self.compile(options) catch {
|
||||
self.printErrors();
|
||||
|
||||
if (self.exercise.hint) |hint|
|
||||
|
|
@ -295,7 +295,7 @@ const ZiglingStep = struct {
|
|||
std.process.exit(2);
|
||||
};
|
||||
|
||||
self.run(exe_path.?, prog_node) catch {
|
||||
self.run(exe_path.?, options.progress_node) catch {
|
||||
self.printErrors();
|
||||
|
||||
if (self.exercise.hint) |hint|
|
||||
|
|
@ -405,7 +405,7 @@ const ZiglingStep = struct {
|
|||
print("{s}PASSED{s}\n\n", .{ green_text, reset_text });
|
||||
}
|
||||
|
||||
fn compile(self: *ZiglingStep, prog_node: std.Progress.Node) !?[]const u8 {
|
||||
fn compile(self: *ZiglingStep, options: Step.MakeOptions) !?[]const u8 {
|
||||
print("Compiling: {s}\n", .{self.exercise.main_file});
|
||||
|
||||
const b = self.step.owner;
|
||||
|
|
@ -436,7 +436,7 @@ const ZiglingStep = struct {
|
|||
|
||||
zig_args.append("--listen=-") catch @panic("OOM");
|
||||
|
||||
return try self.step.evalZigProcess(zig_args.items, prog_node);
|
||||
return try self.step.evalZigProcess(zig_args.items, options.progress_node, false);
|
||||
}
|
||||
|
||||
fn help(self: *ZiglingStep) void {
|
||||
|
|
@ -525,7 +525,7 @@ const PrintStep = struct {
|
|||
return self;
|
||||
}
|
||||
|
||||
fn make(step: *Step, _: std.Progress.Node) !void {
|
||||
fn make(step: *Step, _: Step.MakeOptions) !void {
|
||||
const self: *PrintStep = @alignCast(@fieldParentPtr("step", step));
|
||||
print("{s}", .{self.message});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ pub fn addCliTests(b: *std.Build, exercises: []const Exercise) *Step {
|
|||
b.graph.zig_exe,
|
||||
"build",
|
||||
"-Dhealed",
|
||||
b.fmt("-Dhealed-path={s}", .{tmp_path}),
|
||||
b.fmt("-Dhealed-path={s}", .{tmp_path.src_path.sub_path}),
|
||||
b.fmt("-Dn={}", .{n}),
|
||||
});
|
||||
cmd.setName(b.fmt("zig build -Dhealed -Dn={}", .{n}));
|
||||
|
|
@ -72,7 +72,7 @@ pub fn addCliTests(b: *std.Build, exercises: []const Exercise) *Step {
|
|||
b.graph.zig_exe,
|
||||
"build",
|
||||
"-Dhealed",
|
||||
b.fmt("-Dhealed-path={s}", .{tmp_path}),
|
||||
b.fmt("-Dhealed-path={s}", .{tmp_path.src_path.sub_path}),
|
||||
});
|
||||
cmd.setName("zig build -Dhealed");
|
||||
cmd.expectExitCode(0);
|
||||
|
|
@ -150,7 +150,7 @@ const CheckNamedStep = struct {
|
|||
return self;
|
||||
}
|
||||
|
||||
fn make(step: *Step, _: std.Progress.Node) !void {
|
||||
fn make(step: *Step, _: Step.MakeOptions) !void {
|
||||
const b = step.owner;
|
||||
const self: *CheckNamedStep = @alignCast(@fieldParentPtr("step", step));
|
||||
const ex = self.exercise;
|
||||
|
|
@ -202,7 +202,7 @@ const CheckStep = struct {
|
|||
return self;
|
||||
}
|
||||
|
||||
fn make(step: *Step, _: std.Progress.Node) !void {
|
||||
fn make(step: *Step, _: Step.MakeOptions) !void {
|
||||
const b = step.owner;
|
||||
const self: *CheckStep = @alignCast(@fieldParentPtr("step", step));
|
||||
const exercises = self.exercises;
|
||||
|
|
@ -325,7 +325,7 @@ const FailStep = struct {
|
|||
return self;
|
||||
}
|
||||
|
||||
fn make(step: *Step, _: std.Progress.Node) !void {
|
||||
fn make(step: *Step, _: Step.MakeOptions) !void {
|
||||
const b = step.owner;
|
||||
const self: *FailStep = @alignCast(@fieldParentPtr("step", step));
|
||||
|
||||
|
|
@ -352,7 +352,7 @@ const HealStep = struct {
|
|||
exercises: []const Exercise,
|
||||
work_path: []const u8,
|
||||
|
||||
pub fn create(owner: *Build, exercises: []const Exercise, work_path: []const u8) *HealStep {
|
||||
pub fn create(owner: *Build, exercises: []const Exercise, work_path: LazyPath) *HealStep {
|
||||
const self = owner.allocator.create(HealStep) catch @panic("OOM");
|
||||
self.* = .{
|
||||
.step = Step.init(.{
|
||||
|
|
@ -362,13 +362,13 @@ const HealStep = struct {
|
|||
.makeFn = make,
|
||||
}),
|
||||
.exercises = exercises,
|
||||
.work_path = work_path,
|
||||
.work_path = work_path.src_path.sub_path,
|
||||
};
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
fn make(step: *Step, _: std.Progress.Node) !void {
|
||||
fn make(step: *Step, _: Step.MakeOptions) !void {
|
||||
const b = step.owner;
|
||||
const self: *HealStep = @alignCast(@fieldParentPtr("step", step));
|
||||
|
||||
|
|
@ -403,12 +403,17 @@ fn heal(allocator: Allocator, exercises: []const Exercise, work_path: []const u8
|
|||
|
||||
/// 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 {
|
||||
pub fn makeTempPath(b: *Build) !LazyPath {
|
||||
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;
|
||||
return LazyPath{
|
||||
.src_path = .{
|
||||
.owner = b,
|
||||
.sub_path = path,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue