authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-18 18:30:50-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-19 14:24:35-04:00
log10200970bb3700dd36807b4df1b1e327da98bbea
treeb9a724cbffc2d25300c86a895f9834d67bef1388
parentb87353a17f4fe297b83d2f75cbf1c737ebb71c74

build system: fixups to --seed mechanism

* support 0x prefixed hex code for CLI seed arguments * don't change the build summary; the printed CLI on build runner failure is sufficient * use `std.crypto.random` instead of system time for entropy

2 files changed, 10 insertions(+), 8 deletions(-)

lib/build_runner.zig+5-5
......@@ -202,8 +202,10 @@ pub fn main() !void {
202202 std.debug.print("Expected u32 after {s}\n\n", .{arg});
203203 usageAndErr(builder, false, stderr_stream);
204204 };
205 seed = std.fmt.parseUnsigned(u32, next_arg, 10) catch |err| {
206 std.debug.print("unable to parse seed '{s}' as u32: {s}", .{ next_arg, @errorName(err) });
205 seed = std.fmt.parseUnsigned(u32, next_arg, 0) catch |err| {
206 std.debug.print("unable to parse seed '{s}' as 32-bit integer: {s}", .{
207 next_arg, @errorName(err),
208 });
207209 process.exit(1);
208210 };
209211 } else if (mem.eql(u8, arg, "--debug-log")) {
......@@ -526,9 +528,7 @@ fn runStepNames(
526528 stderr.writeAll(" (disable with --summary none)") catch {};
527529 ttyconf.setColor(stderr, .reset) catch {};
528530 }
529 ttyconf.setColor(stderr, .dim) catch {};
530 stderr.writer().print("\nseed is {}\n", .{seed}) catch {};
531 ttyconf.setColor(stderr, .reset) catch {};
531 stderr.writeAll("\n") catch {};
532532 const failures_only = run.summary != Summary.all;
533533
534534 // Print a fancy tree with build results.
src/main.zig+5-3
......@@ -4906,6 +4906,7 @@ pub const usage_build =
49064906 \\ --global-cache-dir [path] Override path to global Zig cache directory
49074907 \\ --zig-lib-dir [arg] Override path to Zig lib directory
49084908 \\ --build-runner [file] Override path to build runner
4909 \\ --seed [integer] For shuffling dependency traversal order (default: random)
49094910 \\ --fetch Exit after fetching dependency tree
49104911 \\ -h, --help Print this help and exit
49114912 \\
......@@ -4930,8 +4931,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
49304931 var reference_trace: ?u32 = null;
49314932 var debug_compile_errors = false;
49324933 var fetch_only = false;
4933 const micros: u32 = @truncate(@as(u64, @bitCast(std.time.microTimestamp())));
4934 var seed: []const u8 = try std.fmt.allocPrint(arena, "{}", .{micros});
49354934
49364935 const argv_index_exe = child_argv.items.len;
49374936 _ = try child_argv.addOne();
......@@ -4947,7 +4946,10 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
49474946 const argv_index_global_cache_dir = child_argv.items.len;
49484947 _ = try child_argv.addOne();
49494948
4950 try child_argv.appendSlice(&[_][]const u8{ "--seed", seed });
4949 try child_argv.appendSlice(&.{
4950 "--seed",
4951 try std.fmt.allocPrint(arena, "0x{x}", .{std.crypto.random.int(u32)}),
4952 });
49514953 const argv_index_seed = child_argv.items.len - 1;
49524954
49534955 {