Merge pull request 'adjust temp files' (#350) from i348 into main

Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/350
This commit is contained in:
Chris Boesch 2026-01-07 20:05:10 +01:00
commit 9b18647fd2
3 changed files with 16 additions and 17 deletions

View File

@ -38,7 +38,8 @@ is incredibly friendly and helpful!
Install a [development build](https://ziglang.org/download/) of Install a [development build](https://ziglang.org/download/) of
the Zig compiler. (See the "master" section of the downloads the Zig compiler. (See the "master" section of the downloads
page.) page.) Sometimes the latest build is not available there;
in that case, you can download it directly from the [build directory](https://ziglang.org/download/index.json).
Verify the installation and build number of `zig` like so: Verify the installation and build number of `zig` like so:
@ -86,6 +87,7 @@ that if you update one, you may need to also update the other.
### Version Changes ### Version Changes
* 2026-01-07 zig 0.16.0-dev.2040 - adjust temp files, see [#30683](https://codeberg.org/ziglang/zig/pulls/30683)
* 2026-01-06 zig 0.16.0-dev.1976 - move process API to `std.Io` and changes to main/environ/argv, see [#30644](https://codeberg.org/ziglang/zig/pulls/30644) * 2026-01-06 zig 0.16.0-dev.1976 - move process API to `std.Io` and changes to main/environ/argv, see [#30644](https://codeberg.org/ziglang/zig/pulls/30644)
* *2025-12-28* zig 0.16.0-dev.1859 - file system I/O integrated with the std.Io interface, see [#30232](https://codeberg.org/ziglang/zig/pulls/30232) * *2025-12-28* zig 0.16.0-dev.1859 - file system I/O integrated with the std.Io interface, see [#30232](https://codeberg.org/ziglang/zig/pulls/30232)
* *2025-11-01* zig 0.16.0-dev.1204 - more changes due to new I/O API, see [#25592](https://github.com/ziglang/zig/pull/25592) * *2025-11-01* zig 0.16.0-dev.1204 - more changes due to new I/O API, see [#25592](https://github.com/ziglang/zig/pull/25592)

View File

@ -15,7 +15,7 @@ const print = std.debug.print;
// 1) Getting Started // 1) Getting Started
// 2) Version Changes // 2) Version Changes
comptime { comptime {
const required_zig = "0.16.0-dev.1976"; const required_zig = "0.16.0-dev.2040";
const current_zig = builtin.zig_version; const current_zig = builtin.zig_version;
const min_zig = std.SemanticVersion.parse(required_zig) catch unreachable; const min_zig = std.SemanticVersion.parse(required_zig) catch unreachable;
if (current_zig.order(min_zig) == .lt) { if (current_zig.order(min_zig) == .lt) {

View File

@ -21,9 +21,10 @@ pub fn addCliTests(b: *std.Build, exercises: []const Exercise) *Step {
// Test that `zig build -Dhealed -Dn=n` selects the nth exercise. // Test that `zig build -Dhealed -Dn=n` selects the nth exercise.
const case_step = createCase(b, "case-1"); const case_step = createCase(b, "case-1");
const tmp_path = makeTempPath(b) catch |err| { const tmp_path = createTempPath(b) catch |err| {
return fail(step, "unable to make tmp path: {s}\n", .{@errorName(err)}); return fail(step, "unable to make tmp path: {s}\n", .{@errorName(err)});
}; };
defer deleteTmpPath(b, tmp_path);
const heal_step = HealStep.create(b, exercises, tmp_path); const heal_step = HealStep.create(b, exercises, tmp_path);
@ -47,20 +48,16 @@ pub fn addCliTests(b: *std.Build, exercises: []const Exercise) *Step {
case_step.dependOn(&verify.step); case_step.dependOn(&verify.step);
} }
const cleanup = b.addRemoveDirTree(.{ .src_path = .{ .owner = b, .sub_path = tmp_path } });
cleanup.step.dependOn(case_step);
step.dependOn(&cleanup.step);
} }
{ {
// Test that `zig build -Dhealed` processes all the exercises in order. // Test that `zig build -Dhealed` processes all the exercises in order.
const case_step = createCase(b, "case-2"); const case_step = createCase(b, "case-2");
const tmp_path = makeTempPath(b) catch |err| { const tmp_path = createTempPath(b) catch |err| {
return fail(step, "unable to make tmp path: {s}\n", .{@errorName(err)}); return fail(step, "unable to make tmp path: {s}\n", .{@errorName(err)});
}; };
defer deleteTmpPath(b, tmp_path);
const heal_step = HealStep.create(b, exercises, tmp_path); const heal_step = HealStep.create(b, exercises, tmp_path);
heal_step.step.dependOn(case_step); heal_step.step.dependOn(case_step);
@ -79,11 +76,6 @@ pub fn addCliTests(b: *std.Build, exercises: []const Exercise) *Step {
const stderr = cmd.captureStdErr(.{}); const stderr = cmd.captureStdErr(.{});
const verify = CheckStep.create(b, exercises, stderr); const verify = CheckStep.create(b, exercises, stderr);
verify.step.dependOn(&cmd.step); verify.step.dependOn(&cmd.step);
const cleanup = b.addRemoveDirTree(.{ .src_path = .{ .owner = b, .sub_path = tmp_path } });
cleanup.step.dependOn(&verify.step);
step.dependOn(&cleanup.step);
} }
{ {
@ -400,9 +392,7 @@ 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 fn createTempPath(b: *Build) ![]const u8 {
/// difference that returns an error when the temp path cannot be created.
pub fn makeTempPath(b: *Build) ![]const u8 {
const io = b.graph.io; const io = b.graph.io;
const rand_int = std.crypto.random.int(u64); const rand_int = std.crypto.random.int(u64);
const tmp_dir_sub_path = "tmp" ++ std.Io.Dir.path.sep_str ++ std.fmt.hex(rand_int); const tmp_dir_sub_path = "tmp" ++ std.Io.Dir.path.sep_str ++ std.fmt.hex(rand_int);
@ -410,3 +400,10 @@ pub fn makeTempPath(b: *Build) ![]const u8 {
try b.cache_root.handle.createDirPath(io, tmp_dir_sub_path); try b.cache_root.handle.createDirPath(io, tmp_dir_sub_path);
return result_path; return result_path;
} }
fn deleteTmpPath(b: *Build, path: []const u8) void {
const io = b.graph.io;
std.Io.Dir.cwd().deleteTree(io, path) catch |err| {
std.log.warn("failed to delete {s}: {t}", .{ path, err });
};
}