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
This commit is contained in:
Andrew Kelley 2023-10-18 18:30:50 -07:00
parent b87353a17f
commit 10200970bb
2 changed files with 10 additions and 8 deletions

View File

@ -202,8 +202,10 @@ pub fn main() !void {
std.debug.print("Expected u32 after {s}\n\n", .{arg}); std.debug.print("Expected u32 after {s}\n\n", .{arg});
usageAndErr(builder, false, stderr_stream); usageAndErr(builder, false, stderr_stream);
}; };
seed = std.fmt.parseUnsigned(u32, next_arg, 10) catch |err| { seed = std.fmt.parseUnsigned(u32, next_arg, 0) catch |err| {
std.debug.print("unable to parse seed '{s}' as u32: {s}", .{ next_arg, @errorName(err) }); std.debug.print("unable to parse seed '{s}' as 32-bit integer: {s}", .{
next_arg, @errorName(err),
});
process.exit(1); process.exit(1);
}; };
} else if (mem.eql(u8, arg, "--debug-log")) { } else if (mem.eql(u8, arg, "--debug-log")) {
@ -526,9 +528,7 @@ fn runStepNames(
stderr.writeAll(" (disable with --summary none)") catch {}; stderr.writeAll(" (disable with --summary none)") catch {};
ttyconf.setColor(stderr, .reset) catch {}; ttyconf.setColor(stderr, .reset) catch {};
} }
ttyconf.setColor(stderr, .dim) catch {}; stderr.writeAll("\n") catch {};
stderr.writer().print("\nseed is {}\n", .{seed}) catch {};
ttyconf.setColor(stderr, .reset) catch {};
const failures_only = run.summary != Summary.all; const failures_only = run.summary != Summary.all;
// Print a fancy tree with build results. // Print a fancy tree with build results.

View File

@ -4906,6 +4906,7 @@ pub const usage_build =
\\ --global-cache-dir [path] Override path to global Zig cache directory \\ --global-cache-dir [path] Override path to global Zig cache directory
\\ --zig-lib-dir [arg] Override path to Zig lib directory \\ --zig-lib-dir [arg] Override path to Zig lib directory
\\ --build-runner [file] Override path to build runner \\ --build-runner [file] Override path to build runner
\\ --seed [integer] For shuffling dependency traversal order (default: random)
\\ --fetch Exit after fetching dependency tree \\ --fetch Exit after fetching dependency tree
\\ -h, --help Print this help and exit \\ -h, --help Print this help and exit
\\ \\
@ -4930,8 +4931,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
var reference_trace: ?u32 = null; var reference_trace: ?u32 = null;
var debug_compile_errors = false; var debug_compile_errors = false;
var fetch_only = false; var fetch_only = false;
const micros: u32 = @truncate(@as(u64, @bitCast(std.time.microTimestamp())));
var seed: []const u8 = try std.fmt.allocPrint(arena, "{}", .{micros});
const argv_index_exe = child_argv.items.len; const argv_index_exe = child_argv.items.len;
_ = try child_argv.addOne(); _ = try child_argv.addOne();
@ -4947,7 +4946,10 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
const argv_index_global_cache_dir = child_argv.items.len; const argv_index_global_cache_dir = child_argv.items.len;
_ = try child_argv.addOne(); _ = try child_argv.addOne();
try child_argv.appendSlice(&[_][]const u8{ "--seed", seed }); try child_argv.appendSlice(&.{
"--seed",
try std.fmt.allocPrint(arena, "0x{x}", .{std.crypto.random.int(u32)}),
});
const argv_index_seed = child_argv.items.len - 1; const argv_index_seed = child_argv.items.len - 1;
{ {