Skip to content

Commit 963ffe9

Browse files
authored
Merge pull request #20059 from ziglang/progress
rework std.Progress
2 parents 759c221 + 3a3d218 commit 963ffe9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1758
-819
lines changed

lib/compiler/aro/aro/Diagnostics.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ const MsgWriter = struct {
528528
config: std.io.tty.Config,
529529

530530
fn init(config: std.io.tty.Config) MsgWriter {
531-
std.debug.getStderrMutex().lock();
531+
std.debug.lockStdErr();
532532
return .{
533533
.w = std.io.bufferedWriter(std.io.getStdErr().writer()),
534534
.config = config,
@@ -537,7 +537,7 @@ const MsgWriter = struct {
537537

538538
pub fn deinit(m: *MsgWriter) void {
539539
m.w.flush() catch {};
540-
std.debug.getStderrMutex().unlock();
540+
std.debug.unlockStdErr();
541541
}
542542

543543
pub fn print(m: *MsgWriter, comptime fmt: []const u8, args: anytype) void {

lib/compiler/build_runner.zig

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,14 @@ pub fn main() !void {
289289
.windows_api => {},
290290
}
291291

292-
var progress: std.Progress = .{ .dont_print_on_dumb = true };
293-
const main_progress_node = progress.start("", 0);
292+
const main_progress_node = std.Progress.start(.{
293+
.disable_printing = (color == .off),
294+
});
294295

295296
builder.debug_log_scopes = debug_log_scopes.items;
296297
builder.resolveInstallPrefix(install_prefix, dir_list);
297298
{
298-
var prog_node = main_progress_node.start("user build.zig logic", 0);
299+
var prog_node = main_progress_node.start("Configure", 0);
299300
defer prog_node.end();
300301
try builder.runBuild(root);
301302
}
@@ -385,7 +386,7 @@ fn runStepNames(
385386
arena: std.mem.Allocator,
386387
b: *std.Build,
387388
step_names: []const []const u8,
388-
parent_prog_node: *std.Progress.Node,
389+
parent_prog_node: std.Progress.Node,
389390
thread_pool_options: std.Thread.Pool.Options,
390391
run: *Run,
391392
seed: u32,
@@ -452,7 +453,7 @@ fn runStepNames(
452453
{
453454
defer parent_prog_node.end();
454455

455-
var step_prog = parent_prog_node.start("steps", step_stack.count());
456+
const step_prog = parent_prog_node.start("steps", step_stack.count());
456457
defer step_prog.end();
457458

458459
var wait_group: std.Thread.WaitGroup = .{};
@@ -467,7 +468,7 @@ fn runStepNames(
467468
if (step.state == .skipped_oom) continue;
468469

469470
thread_pool.spawnWg(&wait_group, workerMakeOneStep, .{
470-
&wait_group, &thread_pool, b, step, &step_prog, run,
471+
&wait_group, &thread_pool, b, step, step_prog, run,
471472
});
472473
}
473474
}
@@ -891,7 +892,7 @@ fn workerMakeOneStep(
891892
thread_pool: *std.Thread.Pool,
892893
b: *std.Build,
893894
s: *Step,
894-
prog_node: *std.Progress.Node,
895+
prog_node: std.Progress.Node,
895896
run: *Run,
896897
) void {
897898
// First, check the conditions for running this step. If they are not met,
@@ -941,11 +942,10 @@ fn workerMakeOneStep(
941942
}
942943
}
943944

944-
var sub_prog_node = prog_node.start(s.name, 0);
945-
sub_prog_node.activate();
945+
const sub_prog_node = prog_node.start(s.name, 0);
946946
defer sub_prog_node.end();
947947

948-
const make_result = s.make(&sub_prog_node);
948+
const make_result = s.make(sub_prog_node);
949949

950950
// No matter the result, we want to display error/warning messages.
951951
const show_compile_errors = !run.prominent_compile_errors and
@@ -954,8 +954,8 @@ fn workerMakeOneStep(
954954
const show_stderr = s.result_stderr.len > 0;
955955

956956
if (show_error_msgs or show_compile_errors or show_stderr) {
957-
sub_prog_node.context.lock_stderr();
958-
defer sub_prog_node.context.unlock_stderr();
957+
std.debug.lockStdErr();
958+
defer std.debug.unlockStdErr();
959959

960960
printErrorMessages(b, s, run) catch {};
961961
}
@@ -1225,7 +1225,7 @@ fn cleanExit() void {
12251225
process.exit(0);
12261226
}
12271227

1228-
const Color = enum { auto, off, on };
1228+
const Color = std.zig.Color;
12291229
const Summary = enum { all, new, failures, none };
12301230

12311231
fn get_tty_conf(color: Color, stderr: File) std.io.tty.Config {

lib/compiler/resinator/cli.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ pub const Diagnostics = struct {
108108
}
109109

110110
pub fn renderToStdErr(self: *Diagnostics, args: []const []const u8, config: std.io.tty.Config) void {
111-
std.debug.getStderrMutex().lock();
112-
defer std.debug.getStderrMutex().unlock();
111+
std.debug.lockStdErr();
112+
defer std.debug.unlockStdErr();
113113
const stderr = std.io.getStdErr().writer();
114114
self.renderToWriter(args, stderr, config) catch return;
115115
}

lib/compiler/resinator/errors.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ pub const Diagnostics = struct {
6060
}
6161

6262
pub fn renderToStdErr(self: *Diagnostics, cwd: std.fs.Dir, source: []const u8, tty_config: std.io.tty.Config, source_mappings: ?SourceMappings) void {
63-
std.debug.getStderrMutex().lock();
64-
defer std.debug.getStderrMutex().unlock();
63+
std.debug.lockStdErr();
64+
defer std.debug.unlockStdErr();
6565
const stderr = std.io.getStdErr().writer();
6666
for (self.errors.items) |err_details| {
6767
renderErrorMessage(self.allocator, stderr, tty_config, cwd, err_details, source, self.strings.items, source_mappings) catch return;

lib/compiler/resinator/main.zig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,6 @@ pub fn main() !void {
5050
},
5151
};
5252

53-
if (zig_integration) {
54-
// Send progress with a special string to indicate that the building of the
55-
// resinator binary is finished and we've moved on to actually compiling the .rc file
56-
try error_handler.server.serveStringMessage(.progress, "<resinator>");
57-
}
58-
5953
var options = options: {
6054
var cli_diagnostics = cli.Diagnostics.init(allocator);
6155
defer cli_diagnostics.deinit();

lib/compiler/test_runner.zig

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,11 @@ fn mainTerminal() void {
129129
var ok_count: usize = 0;
130130
var skip_count: usize = 0;
131131
var fail_count: usize = 0;
132-
var progress = std.Progress{
133-
.dont_print_on_dumb = true,
134-
};
135-
const root_node = progress.start("Test", test_fn_list.len);
136-
const have_tty = progress.terminal != null and
137-
(progress.supports_ansi_escape_codes or progress.is_windows_terminal);
132+
const root_node = std.Progress.start(.{
133+
.root_name = "Test",
134+
.estimated_total_items = test_fn_list.len,
135+
});
136+
const have_tty = std.io.getStdErr().isTty();
138137

139138
var async_frame_buffer: []align(builtin.target.stackAlignment()) u8 = undefined;
140139
// TODO this is on the next line (using `undefined` above) because otherwise zig incorrectly
@@ -151,11 +150,9 @@ fn mainTerminal() void {
151150
}
152151
std.testing.log_level = .warn;
153152

154-
var test_node = root_node.start(test_fn.name, 0);
155-
test_node.activate();
156-
progress.refresh();
153+
const test_node = root_node.start(test_fn.name, 0);
157154
if (!have_tty) {
158-
std.debug.print("{d}/{d} {s}... ", .{ i + 1, test_fn_list.len, test_fn.name });
155+
std.debug.print("{d}/{d} {s}...", .{ i + 1, test_fn_list.len, test_fn.name });
159156
}
160157
if (test_fn.func()) |_| {
161158
ok_count += 1;
@@ -164,12 +161,22 @@ fn mainTerminal() void {
164161
} else |err| switch (err) {
165162
error.SkipZigTest => {
166163
skip_count += 1;
167-
progress.log("SKIP\n", .{});
164+
if (have_tty) {
165+
std.debug.print("{d}/{d} {s}...SKIP\n", .{ i + 1, test_fn_list.len, test_fn.name });
166+
} else {
167+
std.debug.print("SKIP\n", .{});
168+
}
168169
test_node.end();
169170
},
170171
else => {
171172
fail_count += 1;
172-
progress.log("FAIL ({s})\n", .{@errorName(err)});
173+
if (have_tty) {
174+
std.debug.print("{d}/{d} {s}...FAIL ({s})\n", .{
175+
i + 1, test_fn_list.len, test_fn.name, @errorName(err),
176+
});
177+
} else {
178+
std.debug.print("FAIL ({s})\n", .{@errorName(err)});
179+
}
173180
if (@errorReturnTrace()) |trace| {
174181
std.debug.dumpStackTrace(trace.*);
175182
}

lib/std/Build.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ pub fn getUninstallStep(b: *Build) *Step {
10591059
return &b.uninstall_tls.step;
10601060
}
10611061

1062-
fn makeUninstall(uninstall_step: *Step, prog_node: *std.Progress.Node) anyerror!void {
1062+
fn makeUninstall(uninstall_step: *Step, prog_node: std.Progress.Node) anyerror!void {
10631063
_ = prog_node;
10641064
const uninstall_tls: *TopLevelStep = @fieldParentPtr("step", uninstall_step);
10651065
const b: *Build = @fieldParentPtr("uninstall_tls", uninstall_tls);
@@ -2281,10 +2281,10 @@ pub const LazyPath = union(enum) {
22812281
.cwd_relative => |p| return src_builder.pathFromCwd(p),
22822282
.generated => |gen| {
22832283
var file_path: []const u8 = gen.file.step.owner.pathFromRoot(gen.file.path orelse {
2284-
std.debug.getStderrMutex().lock();
2284+
std.debug.lockStdErr();
22852285
const stderr = std.io.getStdErr();
22862286
dumpBadGetPathHelp(gen.file.step, stderr, src_builder, asking_step) catch {};
2287-
std.debug.getStderrMutex().unlock();
2287+
std.debug.unlockStdErr();
22882288
@panic("misconfigured build script");
22892289
});
22902290

@@ -2351,8 +2351,8 @@ fn dumpBadDirnameHelp(
23512351
comptime msg: []const u8,
23522352
args: anytype,
23532353
) anyerror!void {
2354-
debug.getStderrMutex().lock();
2355-
defer debug.getStderrMutex().unlock();
2354+
debug.lockStdErr();
2355+
defer debug.unlockStdErr();
23562356

23572357
const stderr = io.getStdErr();
23582358
const w = stderr.writer();

lib/std/Build/Step.zig

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub const TestResults = struct {
5858
}
5959
};
6060

61-
pub const MakeFn = *const fn (step: *Step, prog_node: *std.Progress.Node) anyerror!void;
61+
pub const MakeFn = *const fn (step: *Step, prog_node: std.Progress.Node) anyerror!void;
6262

6363
pub const State = enum {
6464
precheck_unstarted,
@@ -176,7 +176,7 @@ pub fn init(options: StepOptions) Step {
176176
/// If the Step's `make` function reports `error.MakeFailed`, it indicates they
177177
/// have already reported the error. Otherwise, we add a simple error report
178178
/// here.
179-
pub fn make(s: *Step, prog_node: *std.Progress.Node) error{ MakeFailed, MakeSkipped }!void {
179+
pub fn make(s: *Step, prog_node: std.Progress.Node) error{ MakeFailed, MakeSkipped }!void {
180180
const arena = s.owner.allocator;
181181

182182
s.makeFn(s, prog_node) catch |err| switch (err) {
@@ -217,7 +217,7 @@ pub fn getStackTrace(s: *Step) ?std.builtin.StackTrace {
217217
};
218218
}
219219

220-
fn makeNoOp(step: *Step, prog_node: *std.Progress.Node) anyerror!void {
220+
fn makeNoOp(step: *Step, prog_node: std.Progress.Node) anyerror!void {
221221
_ = prog_node;
222222

223223
var all_cached = true;
@@ -303,7 +303,7 @@ pub fn addError(step: *Step, comptime fmt: []const u8, args: anytype) error{OutO
303303
pub fn evalZigProcess(
304304
s: *Step,
305305
argv: []const []const u8,
306-
prog_node: *std.Progress.Node,
306+
prog_node: std.Progress.Node,
307307
) !?[]const u8 {
308308
assert(argv.len != 0);
309309
const b = s.owner;
@@ -319,6 +319,7 @@ pub fn evalZigProcess(
319319
child.stdout_behavior = .Pipe;
320320
child.stderr_behavior = .Pipe;
321321
child.request_resource_usage_statistics = true;
322+
child.progress_node = prog_node;
322323

323324
child.spawn() catch |err| return s.fail("unable to spawn {s}: {s}", .{
324325
argv[0], @errorName(err),
@@ -337,11 +338,6 @@ pub fn evalZigProcess(
337338
const Header = std.zig.Server.Message.Header;
338339
var result: ?[]const u8 = null;
339340

340-
var node_name: std.ArrayListUnmanaged(u8) = .{};
341-
defer node_name.deinit(gpa);
342-
var sub_prog_node = prog_node.start("", 0);
343-
defer sub_prog_node.end();
344-
345341
const stdout = poller.fifo(.stdout);
346342

347343
poll: while (true) {
@@ -379,11 +375,6 @@ pub fn evalZigProcess(
379375
.extra = extra_array,
380376
};
381377
},
382-
.progress => {
383-
node_name.clearRetainingCapacity();
384-
try node_name.appendSlice(gpa, body);
385-
sub_prog_node.setName(node_name.items);
386-
},
387378
.emit_bin_path => {
388379
const EbpHdr = std.zig.Server.Message.EmitBinPath;
389380
const ebp_hdr = @as(*align(1) const EbpHdr, @ptrCast(body));

lib/std/Build/Step/CheckFile.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub fn setName(check_file: *CheckFile, name: []const u8) void {
4646
check_file.step.name = name;
4747
}
4848

49-
fn make(step: *Step, prog_node: *std.Progress.Node) !void {
49+
fn make(step: *Step, prog_node: std.Progress.Node) !void {
5050
_ = prog_node;
5151
const b = step.owner;
5252
const check_file: *CheckFile = @fieldParentPtr("step", step);

lib/std/Build/Step/CheckObject.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ pub fn checkComputeCompare(
550550
check_object.checks.append(check) catch @panic("OOM");
551551
}
552552

553-
fn make(step: *Step, prog_node: *std.Progress.Node) !void {
553+
fn make(step: *Step, prog_node: std.Progress.Node) !void {
554554
_ = prog_node;
555555
const b = step.owner;
556556
const gpa = b.allocator;

0 commit comments

Comments
 (0)