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 {...@@ -202,8 +202,10 @@ pub fn main() !void {
202 std.debug.print("Expected u32 after {s}\n\n", .{arg});202 std.debug.print("Expected u32 after {s}\n\n", .{arg});
203 usageAndErr(builder, false, stderr_stream);203 usageAndErr(builder, false, stderr_stream);
204 };204 };
205 seed = std.fmt.parseUnsigned(u32, next_arg, 10) catch |err| {205 seed = std.fmt.parseUnsigned(u32, next_arg, 0) catch |err| {
206 std.debug.print("unable to parse seed '{s}' as u32: {s}", .{ next_arg, @errorName(err) });206 std.debug.print("unable to parse seed '{s}' as 32-bit integer: {s}", .{
207 next_arg, @errorName(err),
208 });
207 process.exit(1);209 process.exit(1);
208 };210 };
209 } else if (mem.eql(u8, arg, "--debug-log")) {211 } else if (mem.eql(u8, arg, "--debug-log")) {
...@@ -526,9 +528,7 @@ fn runStepNames(...@@ -526,9 +528,7 @@ fn runStepNames(
526 stderr.writeAll(" (disable with --summary none)") catch {};528 stderr.writeAll(" (disable with --summary none)") catch {};
527 ttyconf.setColor(stderr, .reset) catch {};529 ttyconf.setColor(stderr, .reset) catch {};
528 }530 }
529 ttyconf.setColor(stderr, .dim) catch {};531 stderr.writeAll("\n") catch {};
530 stderr.writer().print("\nseed is {}\n", .{seed}) catch {};
531 ttyconf.setColor(stderr, .reset) catch {};
532 const failures_only = run.summary != Summary.all;532 const failures_only = run.summary != Summary.all;
533533
534 // Print a fancy tree with build results.534 // Print a fancy tree with build results.
src/main.zig+5-3
...@@ -4906,6 +4906,7 @@ pub const usage_build =...@@ -4906,6 +4906,7 @@ pub const usage_build =
4906 \\ --global-cache-dir [path] Override path to global Zig cache directory4906 \\ --global-cache-dir [path] Override path to global Zig cache directory
4907 \\ --zig-lib-dir [arg] Override path to Zig lib directory4907 \\ --zig-lib-dir [arg] Override path to Zig lib directory
4908 \\ --build-runner [file] Override path to build runner4908 \\ --build-runner [file] Override path to build runner
4909 \\ --seed [integer] For shuffling dependency traversal order (default: random)
4909 \\ --fetch Exit after fetching dependency tree4910 \\ --fetch Exit after fetching dependency tree
4910 \\ -h, --help Print this help and exit4911 \\ -h, --help Print this help and exit
4911 \\4912 \\
...@@ -4930,8 +4931,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -4930,8 +4931,6 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
4930 var reference_trace: ?u32 = null;4931 var reference_trace: ?u32 = null;
4931 var debug_compile_errors = false;4932 var debug_compile_errors = false;
4932 var fetch_only = false;4933 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
4936 const argv_index_exe = child_argv.items.len;4935 const argv_index_exe = child_argv.items.len;
4937 _ = try child_argv.addOne();4936 _ = try child_argv.addOne();
...@@ -4947,7 +4946,10 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -4947,7 +4946,10 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
4947 const argv_index_global_cache_dir = child_argv.items.len;4946 const argv_index_global_cache_dir = child_argv.items.len;
4948 _ = try child_argv.addOne();4947 _ = 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 });
4951 const argv_index_seed = child_argv.items.len - 1;4953 const argv_index_seed = child_argv.items.len - 1;
49524954
4953 {4955 {