diff options
| author | Chris Boesch <[email protected]> | 2024-06-25 08:30:14 +0000 |
|---|---|---|
| committer | Chris Boesch <[email protected]> | 2024-06-25 08:30:14 +0000 |
| commit | 94fe012c771998c36aef63f0595f45315b8226d5 (patch) | |
| tree | 15de1ddad0715c375d7cc3000d65809ed87caa4d /build.zig | |
| parent | f496d79ab9db052d6aa0cadcd68d44112a5f0724 (diff) | |
| parent | 2259a18ece9b277c7006ec37632d41799d75fd9f (diff) | |
| download | ziglings-94fe012c771998c36aef63f0595f45315b8226d5.tar.xz ziglings-94fe012c771998c36aef63f0595f45315b8226d5.zip | |
Merge pull request 'attempt at implementing #113 "Add a way to do one random exercise"' (#117) from hippietrail/exercises:random-exercise into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/117
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -103,6 +103,8 @@ const Mode = enum { normal, /// Named build mode: `zig build -Dn=n` named, + /// Random build mode: `zig build -Drandom` + random, }; pub const logo = @@ -158,6 +160,7 @@ pub fn build(b: *Build) !void { false; const override_healed_path = b.option([]const u8, "healed-path", "Override healed path"); const exno: ?usize = b.option(usize, "n", "Select exercise"); + const rand: ?bool = b.option(bool, "random", "Select random exercise"); const sep = std.fs.path.sep_str; const healed_path = if (override_healed_path) |path| @@ -191,6 +194,33 @@ pub fn build(b: *Build) !void { return; } + if (rand) |_| { + // Random build mode: verifies one random exercise. + // like for 'exno' but chooses a random exersise number. + print("work in progress: check a random exercise\n", .{}); + + var prng = std.rand.DefaultPrng.init(blk: { + var seed: u64 = undefined; + try std.posix.getrandom(std.mem.asBytes(&seed)); + break :blk seed; + }); + const rnd = prng.random(); + const ex = exercises[rnd.intRangeLessThan(usize, 0, exercises.len)]; + + print("random exercise: {s}\n", .{ex.main_file}); + + const zigling_step = b.step( + "random", + b.fmt("Check the solution of {s}", .{ex.main_file}), + ); + b.default_step = zigling_step; + zigling_step.dependOn(&header_step.step); + const verify_step = ZiglingStep.create(b, ex, work_path, .random); + verify_step.step.dependOn(&header_step.step); + zigling_step.dependOn(&verify_step.step); + return; + } + // Normal build mode: verifies all exercises according to the recommended // order. const ziglings_step = b.step("ziglings", "Check all ziglings"); @@ -417,6 +447,7 @@ const ZiglingStep = struct { const cmd = switch (self.mode) { .normal => "zig build", .named => b.fmt("zig build -Dn={s}", .{key}), + .random => "zig build -Drandom", }; print("\n{s}Edit exercises/{s} and run '{s}' again.{s}\n", .{ |
