| ... | ... | @@ -379,12 +379,18 @@ pub fn main() !void { |
| 379 | 379 | |
| 380 | 380 | validateSystemLibraryOptions(builder); |
| 381 | 381 | |
| 382 | | { |
| 383 | | var fw = std.fs.File.stdout().writer(); |
| 384 | | var bw = fw.interface().buffered(&stdio_buffer); |
| 385 | | defer bw.flush() catch {}; |
| 386 | | if (help_menu) return usage(builder, &bw); |
| 387 | | if (steps_menu) return steps(builder, &bw); |
| 382 | if (help_menu) { |
| 383 | var w = initStdoutWriter(); |
| 384 | printUsage(builder, w) catch return stdout_writer_allocation.err.?; |
| 385 | w.flush() catch return stdout_writer_allocation.err.?; |
| 386 | return; |
| 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 | 396 | var run: Run = .{ |
| ... | ... | @@ -697,21 +703,21 @@ fn runStepNames( |
| 697 | 703 | const ttyconf = run.ttyconf; |
| 698 | 704 | |
| 699 | 705 | if (run.summary != .none) { |
| 700 | | const bw = std.debug.lockStderrWriter(&stdio_buffer); |
| 706 | const w = std.debug.lockStderrWriter(&stdio_buffer_allocation); |
| 701 | 707 | defer std.debug.unlockStderrWriter(); |
| 702 | 708 | |
| 703 | 709 | const total_count = success_count + failure_count + pending_count + skipped_count; |
| 704 | | ttyconf.setColor(bw, .cyan) catch {}; |
| 705 | | bw.writeAll("Build Summary:") catch {}; |
| 706 | | ttyconf.setColor(bw, .reset) catch {}; |
| 707 | | bw.print(" {d}/{d} steps succeeded", .{ success_count, total_count }) catch {}; |
| 708 | | if (skipped_count > 0) bw.print("; {d} skipped", .{skipped_count}) catch {}; |
| 709 | | if (failure_count > 0) bw.print("; {d} failed", .{failure_count}) catch {}; |
| 710 | | |
| 711 | | if (test_count > 0) bw.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 {}; |
| 713 | | if (test_fail_count > 0) bw.print("; {d} failed", .{test_fail_count}) catch {}; |
| 714 | | if (test_leak_count > 0) bw.print("; {d} leaked", .{test_leak_count}) catch {}; |
| 710 | ttyconf.setColor(w, .cyan) catch {}; |
| 711 | w.writeAll("Build Summary:") catch {}; |
| 712 | ttyconf.setColor(w, .reset) catch {}; |
| 713 | w.print(" {d}/{d} steps succeeded", .{ success_count, total_count }) catch {}; |
| 714 | if (skipped_count > 0) w.print("; {d} skipped", .{skipped_count}) catch {}; |
| 715 | if (failure_count > 0) w.print("; {d} failed", .{failure_count}) catch {}; |
| 716 | |
| 717 | if (test_count > 0) w.print("; {d}/{d} tests passed", .{ test_pass_count, test_count }) catch {}; |
| 718 | if (test_skip_count > 0) w.print("; {d} skipped", .{test_skip_count}) catch {}; |
| 719 | if (test_fail_count > 0) w.print("; {d} failed", .{test_fail_count}) catch {}; |
| 720 | if (test_leak_count > 0) w.print("; {d} leaked", .{test_leak_count}) catch {}; |
| 715 | 721 | |
| 716 | 722 | // Print a fancy tree with build results. |
| 717 | 723 | var step_stack_copy = try step_stack.clone(gpa); |
| ... | ... | @@ -720,7 +726,7 @@ fn runStepNames( |
| 720 | 726 | var print_node: PrintNode = .{ .parent = null }; |
| 721 | 727 | if (step_names.len == 0) { |
| 722 | 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 | 730 | } else { |
| 725 | 731 | const last_index = if (run.summary == .all) b.top_level_steps.count() else blk: { |
| 726 | 732 | var i: usize = step_names.len; |
| ... | ... | @@ -739,10 +745,10 @@ fn runStepNames( |
| 739 | 745 | for (step_names, 0..) |step_name, i| { |
| 740 | 746 | const tls = b.top_level_steps.get(step_name).?; |
| 741 | 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 | 754 | if (failure_count == 0) { |
| ... | ... | @@ -1128,7 +1134,7 @@ fn workerMakeOneStep( |
| 1128 | 1134 | const show_stderr = s.result_stderr.len > 0; |
| 1129 | 1135 | |
| 1130 | 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 | 1138 | defer std.debug.unlockStderrWriter(); |
| 1133 | 1139 | |
| 1134 | 1140 | const gpa = b.allocator; |
| ... | ... | @@ -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 | 1252 | const allocator = builder.allocator; |
| 1247 | 1253 | for (builder.top_level_steps.values()) |top_level_step| { |
| 1248 | 1254 | const name = if (&top_level_step.step == builder.default_step) |
| 1249 | 1255 | try fmt.allocPrint(allocator, "{s} (default)", .{top_level_step.step.name}) |
| 1250 | 1256 | else |
| 1251 | 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; |
| 1257 | | |
| 1258 | | fn usage(b: *std.Build, bw: *Writer) !void { |
| 1259 | | try bw.print( |
| 1262 | fn printUsage(b: *std.Build, w: *Writer) !void { |
| 1263 | try w.print( |
| 1260 | 1264 | \\Usage: {s} build [steps] [options] |
| 1261 | 1265 | \\ |
| 1262 | 1266 | \\Steps: |
| 1263 | 1267 | \\ |
| 1264 | 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 | 1273 | \\General Options: |
| 1270 | 1274 | \\ -p, --prefix [path] Where to install files (default: zig-out) |
| ... | ... | @@ -1320,25 +1324,25 @@ fn usage(b: *std.Build, bw: *Writer) !void { |
| 1320 | 1324 | |
| 1321 | 1325 | const arena = b.allocator; |
| 1322 | 1326 | if (b.available_options_list.items.len == 0) { |
| 1323 | | try bw.print(" (none)\n", .{}); |
| 1327 | try w.print(" (none)\n", .{}); |
| 1324 | 1328 | } else { |
| 1325 | 1329 | for (b.available_options_list.items) |option| { |
| 1326 | 1330 | const name = try fmt.allocPrint(arena, " -D{s}=[{s}]", .{ |
| 1327 | 1331 | option.name, |
| 1328 | 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 | 1335 | if (option.enum_options) |enum_options| { |
| 1332 | 1336 | const padding = " " ** 33; |
| 1333 | | try bw.writeAll(padding ++ "Supported Values:\n"); |
| 1337 | try w.writeAll(padding ++ "Supported Values:\n"); |
| 1334 | 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 | 1347 | \\System Integration Options: |
| 1344 | 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 | 1357 | \\ |
| 1354 | 1358 | ); |
| 1355 | 1359 | if (b.graph.system_library_options.entries.len == 0) { |
| 1356 | | try bw.writeAll(" (none) -\n"); |
| 1360 | try w.writeAll(" (none) -\n"); |
| 1357 | 1361 | } else { |
| 1358 | 1362 | for (b.graph.system_library_options.keys(), b.graph.system_library_options.values()) |k, v| { |
| 1359 | 1363 | const status = switch (v) { |
| ... | ... | @@ -1361,11 +1365,11 @@ fn usage(b: *std.Build, bw: *Writer) !void { |
| 1361 | 1365 | .declared_disabled => "no", |
| 1362 | 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 | 1374 | \\Advanced Options: |
| 1371 | 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 | 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 | } |