| ... | @@ -379,12 +379,18 @@ pub fn main() !void { | ... | @@ -379,12 +379,18 @@ pub fn main() !void { |
| 379 | | 379 | |
| 380 | validateSystemLibraryOptions(builder); | 380 | validateSystemLibraryOptions(builder); |
| 381 | | 381 | |
| 382 | { | 382 | if (help_menu) { |
| 383 | var fw = std.fs.File.stdout().writer(); | 383 | var w = initStdoutWriter(); |
| 384 | var bw = fw.interface().buffered(&stdio_buffer); | 384 | printUsage(builder, w) catch return stdout_writer_allocation.err.?; |
| 385 | defer bw.flush() catch {}; | 385 | w.flush() catch return stdout_writer_allocation.err.?; |
| 386 | if (help_menu) return usage(builder, &bw); | 386 | return; |
| 387 | if (steps_menu) return steps(builder, &bw); | 387 | } |
| | 388 | |
| | 389 | if (steps_menu) { |
| | 390 | var w = initStdoutWriter(); |
| | 391 | printSteps(builder, w) catch return stdout_writer_allocation.err.?; |
| | 392 | w.flush() catch return stdout_writer_allocation.err.?; |
| | 393 | return; |
| 388 | } | 394 | } |
| 389 | | 395 | |
| 390 | var run: Run = .{ | 396 | var run: Run = .{ |
| ... | @@ -697,21 +703,21 @@ fn runStepNames( | ... | @@ -697,21 +703,21 @@ fn runStepNames( |
| 697 | const ttyconf = run.ttyconf; | 703 | const ttyconf = run.ttyconf; |
| 698 | | 704 | |
| 699 | if (run.summary != .none) { | 705 | if (run.summary != .none) { |
| 700 | const bw = std.debug.lockStderrWriter(&stdio_buffer); | 706 | const w = std.debug.lockStderrWriter(&stdio_buffer_allocation); |
| 701 | defer std.debug.unlockStderrWriter(); | 707 | defer std.debug.unlockStderrWriter(); |
| 702 | | 708 | |
| 703 | const total_count = success_count + failure_count + pending_count + skipped_count; | 709 | const total_count = success_count + failure_count + pending_count + skipped_count; |
| 704 | ttyconf.setColor(bw, .cyan) catch {}; | 710 | ttyconf.setColor(w, .cyan) catch {}; |
| 705 | bw.writeAll("Build Summary:") catch {}; | 711 | w.writeAll("Build Summary:") catch {}; |
| 706 | ttyconf.setColor(bw, .reset) catch {}; | 712 | ttyconf.setColor(w, .reset) catch {}; |
| 707 | bw.print(" {d}/{d} steps succeeded", .{ success_count, total_count }) catch {}; | 713 | w.print(" {d}/{d} steps succeeded", .{ success_count, total_count }) catch {}; |
| 708 | if (skipped_count > 0) bw.print("; {d} skipped", .{skipped_count}) catch {}; | 714 | if (skipped_count > 0) w.print("; {d} skipped", .{skipped_count}) catch {}; |
| 709 | if (failure_count > 0) bw.print("; {d} failed", .{failure_count}) catch {}; | 715 | if (failure_count > 0) w.print("; {d} failed", .{failure_count}) catch {}; |
| 710 | | 716 | |
| 711 | if (test_count > 0) bw.print("; {d}/{d} tests passed", .{ test_pass_count, test_count }) catch {}; | 717 | if (test_count > 0) w.print("; {d}/{d} tests passed", .{ test_pass_count, test_count }) catch {}; |
| 712 | if (test_skip_count > 0) bw.print("; {d} skipped", .{test_skip_count}) catch {}; | 718 | if (test_skip_count > 0) w.print("; {d} skipped", .{test_skip_count}) catch {}; |
| 713 | if (test_fail_count > 0) bw.print("; {d} failed", .{test_fail_count}) catch {}; | 719 | if (test_fail_count > 0) w.print("; {d} failed", .{test_fail_count}) catch {}; |
| 714 | if (test_leak_count > 0) bw.print("; {d} leaked", .{test_leak_count}) catch {}; | 720 | if (test_leak_count > 0) w.print("; {d} leaked", .{test_leak_count}) catch {}; |
| 715 | | 721 | |
| 716 | // Print a fancy tree with build results. | 722 | // Print a fancy tree with build results. |
| 717 | var step_stack_copy = try step_stack.clone(gpa); | 723 | var step_stack_copy = try step_stack.clone(gpa); |
| ... | @@ -720,7 +726,7 @@ fn runStepNames( | ... | @@ -720,7 +726,7 @@ fn runStepNames( |
| 720 | var print_node: PrintNode = .{ .parent = null }; | 726 | var print_node: PrintNode = .{ .parent = null }; |
| 721 | if (step_names.len == 0) { | 727 | if (step_names.len == 0) { |
| 722 | print_node.last = true; | 728 | print_node.last = true; |
| 723 | printTreeStep(b, b.default_step, run, bw, ttyconf, &print_node, &step_stack_copy) catch {}; | 729 | printTreeStep(b, b.default_step, run, w, ttyconf, &print_node, &step_stack_copy) catch {}; |
| 724 | } else { | 730 | } else { |
| 725 | const last_index = if (run.summary == .all) b.top_level_steps.count() else blk: { | 731 | const last_index = if (run.summary == .all) b.top_level_steps.count() else blk: { |
| 726 | var i: usize = step_names.len; | 732 | var i: usize = step_names.len; |
| ... | @@ -739,10 +745,10 @@ fn runStepNames( | ... | @@ -739,10 +745,10 @@ fn runStepNames( |
| 739 | for (step_names, 0..) |step_name, i| { | 745 | for (step_names, 0..) |step_name, i| { |
| 740 | const tls = b.top_level_steps.get(step_name).?; | 746 | const tls = b.top_level_steps.get(step_name).?; |
| 741 | print_node.last = i + 1 == last_index; | 747 | print_node.last = i + 1 == last_index; |
| 742 | printTreeStep(b, &tls.step, run, bw, ttyconf, &print_node, &step_stack_copy) catch {}; | 748 | printTreeStep(b, &tls.step, run, w, ttyconf, &print_node, &step_stack_copy) catch {}; |
| 743 | } | 749 | } |
| 744 | } | 750 | } |
| 745 | bw.writeByte('\n') catch {}; | 751 | w.writeByte('\n') catch {}; |
| 746 | } | 752 | } |
| 747 | | 753 | |
| 748 | if (failure_count == 0) { | 754 | if (failure_count == 0) { |
| ... | @@ -1128,7 +1134,7 @@ fn workerMakeOneStep( | ... | @@ -1128,7 +1134,7 @@ fn workerMakeOneStep( |
| 1128 | const show_stderr = s.result_stderr.len > 0; | 1134 | const show_stderr = s.result_stderr.len > 0; |
| 1129 | | 1135 | |
| 1130 | if (show_error_msgs or show_compile_errors or show_stderr) { | 1136 | if (show_error_msgs or show_compile_errors or show_stderr) { |
| 1131 | const bw = std.debug.lockStderrWriter(&stdio_buffer); | 1137 | const bw = std.debug.lockStderrWriter(&stdio_buffer_allocation); |
| 1132 | defer std.debug.unlockStderrWriter(); | 1138 | defer std.debug.unlockStderrWriter(); |
| 1133 | | 1139 | |
| 1134 | const gpa = b.allocator; | 1140 | const gpa = b.allocator; |
| ... | @@ -1242,29 +1248,27 @@ pub fn printErrorMessages( | ... | @@ -1242,29 +1248,27 @@ pub fn printErrorMessages( |
| 1242 | } | 1248 | } |
| 1243 | } | 1249 | } |
| 1244 | | 1250 | |
| 1245 | fn steps(builder: *std.Build, bw: *Writer) !void { | 1251 | fn printSteps(builder: *std.Build, w: *Writer) !void { |
| 1246 | const allocator = builder.allocator; | 1252 | const allocator = builder.allocator; |
| 1247 | for (builder.top_level_steps.values()) |top_level_step| { | 1253 | for (builder.top_level_steps.values()) |top_level_step| { |
| 1248 | const name = if (&top_level_step.step == builder.default_step) | 1254 | const name = if (&top_level_step.step == builder.default_step) |
| 1249 | try fmt.allocPrint(allocator, "{s} (default)", .{top_level_step.step.name}) | 1255 | try fmt.allocPrint(allocator, "{s} (default)", .{top_level_step.step.name}) |
| 1250 | else | 1256 | else |
| 1251 | top_level_step.step.name; | 1257 | top_level_step.step.name; |
| 1252 | try bw.print(" {s:<28} {s}\n", .{ name, top_level_step.description }); | 1258 | try w.print(" {s:<28} {s}\n", .{ name, top_level_step.description }); |
| 1253 | } | 1259 | } |
| 1254 | } | 1260 | } |
| 1255 | | 1261 | |
| 1256 | var stdio_buffer: [256]u8 = undefined; | 1262 | fn printUsage(b: *std.Build, w: *Writer) !void { |
| 1257 | | 1263 | try w.print( |
| 1258 | fn usage(b: *std.Build, bw: *Writer) !void { | | |
| 1259 | try bw.print( | | |
| 1260 | \\Usage: {s} build [steps] [options] | 1264 | \\Usage: {s} build [steps] [options] |
| 1261 | \\ | 1265 | \\ |
| 1262 | \\Steps: | 1266 | \\Steps: |
| 1263 | \\ | 1267 | \\ |
| 1264 | , .{b.graph.zig_exe}); | 1268 | , .{b.graph.zig_exe}); |
| 1265 | try steps(b, bw); | 1269 | try printSteps(b, w); |
| 1266 | | 1270 | |
| 1267 | try bw.writeAll( | 1271 | try w.writeAll( |
| 1268 | \\ | 1272 | \\ |
| 1269 | \\General Options: | 1273 | \\General Options: |
| 1270 | \\ -p, --prefix [path] Where to install files (default: zig-out) | 1274 | \\ -p, --prefix [path] Where to install files (default: zig-out) |
| ... | @@ -1320,25 +1324,25 @@ fn usage(b: *std.Build, bw: *Writer) !void { | ... | @@ -1320,25 +1324,25 @@ fn usage(b: *std.Build, bw: *Writer) !void { |
| 1320 | | 1324 | |
| 1321 | const arena = b.allocator; | 1325 | const arena = b.allocator; |
| 1322 | if (b.available_options_list.items.len == 0) { | 1326 | if (b.available_options_list.items.len == 0) { |
| 1323 | try bw.print(" (none)\n", .{}); | 1327 | try w.print(" (none)\n", .{}); |
| 1324 | } else { | 1328 | } else { |
| 1325 | for (b.available_options_list.items) |option| { | 1329 | for (b.available_options_list.items) |option| { |
| 1326 | const name = try fmt.allocPrint(arena, " -D{s}=[{s}]", .{ | 1330 | const name = try fmt.allocPrint(arena, " -D{s}=[{s}]", .{ |
| 1327 | option.name, | 1331 | option.name, |
| 1328 | @tagName(option.type_id), | 1332 | @tagName(option.type_id), |
| 1329 | }); | 1333 | }); |
| 1330 | try bw.print("{s:<30} {s}\n", .{ name, option.description }); | 1334 | try w.print("{s:<30} {s}\n", .{ name, option.description }); |
| 1331 | if (option.enum_options) |enum_options| { | 1335 | if (option.enum_options) |enum_options| { |
| 1332 | const padding = " " ** 33; | 1336 | const padding = " " ** 33; |
| 1333 | try bw.writeAll(padding ++ "Supported Values:\n"); | 1337 | try w.writeAll(padding ++ "Supported Values:\n"); |
| 1334 | for (enum_options) |enum_option| { | 1338 | for (enum_options) |enum_option| { |
| 1335 | try bw.print(padding ++ " {s}\n", .{enum_option}); | 1339 | try w.print(padding ++ " {s}\n", .{enum_option}); |
| 1336 | } | 1340 | } |
| 1337 | } | 1341 | } |
| 1338 | } | 1342 | } |
| 1339 | } | 1343 | } |
| 1340 | | 1344 | |
| 1341 | try bw.writeAll( | 1345 | try w.writeAll( |
| 1342 | \\ | 1346 | \\ |
| 1343 | \\System Integration Options: | 1347 | \\System Integration Options: |
| 1344 | \\ --search-prefix [path] Add a path to look for binaries, libraries, headers | 1348 | \\ --search-prefix [path] Add a path to look for binaries, libraries, headers |
| ... | @@ -1353,7 +1357,7 @@ fn usage(b: *std.Build, bw: *Writer) !void { | ... | @@ -1353,7 +1357,7 @@ fn usage(b: *std.Build, bw: *Writer) !void { |
| 1353 | \\ | 1357 | \\ |
| 1354 | ); | 1358 | ); |
| 1355 | if (b.graph.system_library_options.entries.len == 0) { | 1359 | if (b.graph.system_library_options.entries.len == 0) { |
| 1356 | try bw.writeAll(" (none) -\n"); | 1360 | try w.writeAll(" (none) -\n"); |
| 1357 | } else { | 1361 | } else { |
| 1358 | for (b.graph.system_library_options.keys(), b.graph.system_library_options.values()) |k, v| { | 1362 | for (b.graph.system_library_options.keys(), b.graph.system_library_options.values()) |k, v| { |
| 1359 | const status = switch (v) { | 1363 | const status = switch (v) { |
| ... | @@ -1361,11 +1365,11 @@ fn usage(b: *std.Build, bw: *Writer) !void { | ... | @@ -1361,11 +1365,11 @@ fn usage(b: *std.Build, bw: *Writer) !void { |
| 1361 | .declared_disabled => "no", | 1365 | .declared_disabled => "no", |
| 1362 | .user_enabled, .user_disabled => unreachable, // already emitted error | 1366 | .user_enabled, .user_disabled => unreachable, // already emitted error |
| 1363 | }; | 1367 | }; |
| 1364 | try bw.print(" {s:<43} {s}\n", .{ k, status }); | 1368 | try w.print(" {s:<43} {s}\n", .{ k, status }); |
| 1365 | } | 1369 | } |
| 1366 | } | 1370 | } |
| 1367 | | 1371 | |
| 1368 | try bw.writeAll( | 1372 | try w.writeAll( |
| 1369 | \\ | 1373 | \\ |
| 1370 | \\Advanced Options: | 1374 | \\Advanced Options: |
| 1371 | \\ -freference-trace[=num] How many lines of reference trace should be shown per compile error | 1375 | \\ -freference-trace[=num] How many lines of reference trace should be shown per compile error |
| ... | @@ -1545,3 +1549,11 @@ fn createModuleDependenciesForStep(step: *Step) Allocator.Error!void { | ... | @@ -1545,3 +1549,11 @@ fn createModuleDependenciesForStep(step: *Step) Allocator.Error!void { |
| 1545 | }; | 1549 | }; |
| 1546 | } | 1550 | } |
| 1547 | } | 1551 | } |
| | 1552 | |
| | 1553 | var stdio_buffer_allocation: [256]u8 = undefined; |
| | 1554 | var stdout_writer_allocation: std.fs.File.Writer = undefined; |
| | 1555 | |
| | 1556 | fn initStdoutWriter() *Writer { |
| | 1557 | stdout_writer_allocation = std.fs.File.stdout().writerStreaming(&stdio_buffer_allocation); |
| | 1558 | return &stdout_writer_allocation.interface; |
| | 1559 | } |