authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-27 13:51:16-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-27 20:56:49-07:00
log44389253c2c3bd47c2c741aa6c804d18d1642ee7
tree97d48a74cfd0389ef30907a6e248e7f998d0a56a
parent2367a1ff846ef2f146d4f7e449044970d399046b

fix zig translate-c creating root progress node twice


2 files changed, 23 insertions(+), 13 deletions(-)

lib/std/Progress.zig+4-4
......@@ -128,12 +128,12 @@ pub const Node = struct {
128128 }
129129 };
130130
131 const OptionalIndex = enum(u8) {
131 pub const OptionalIndex = enum(u8) {
132132 none = std.math.maxInt(u8),
133133 /// Index into `node_storage`.
134134 _,
135135
136 fn unwrap(i: @This()) ?Index {
136 pub fn unwrap(i: @This()) ?Index {
137137 if (i == .none) return null;
138138 return @enumFromInt(@intFromEnum(i));
139139 }
......@@ -145,7 +145,7 @@ pub const Node = struct {
145145 };
146146
147147 /// Index into `node_storage`.
148 const Index = enum(u8) {
148 pub const Index = enum(u8) {
149149 _,
150150
151151 fn toParent(i: @This()) Parent {
......@@ -154,7 +154,7 @@ pub const Node = struct {
154154 return @enumFromInt(@intFromEnum(i));
155155 }
156156
157 fn toOptional(i: @This()) OptionalIndex {
157 pub fn toOptional(i: @This()) OptionalIndex {
158158 return @enumFromInt(@intFromEnum(i));
159159 }
160160 };
src/main.zig+19-9
......@@ -3404,15 +3404,15 @@ fn buildOutputType(
34043404 },
34053405 }
34063406
3407 if (arg_mode == .translate_c) {
3408 return cmdTranslateC(comp, arena, null);
3409 }
3410
34113407 const root_prog_node = std.Progress.start(.{
34123408 .disable_printing = (color == .off),
34133409 });
34143410 defer root_prog_node.end();
34153411
3412 if (arg_mode == .translate_c) {
3413 return cmdTranslateC(comp, arena, null, root_prog_node);
3414 }
3415
34163416 updateModule(comp, color, root_prog_node) catch |err| switch (err) {
34173417 error.SemanticAnalyzeFail => {
34183418 assert(listen == .none);
......@@ -4048,7 +4048,7 @@ fn serve(
40484048 defer arena_instance.deinit();
40494049 const arena = arena_instance.allocator();
40504050 var output: Compilation.CImportResult = undefined;
4051 try cmdTranslateC(comp, arena, &output);
4051 try cmdTranslateC(comp, arena, &output, main_progress_node);
40524052 defer output.deinit(gpa);
40534053 if (output.errors.errorMessageCount() != 0) {
40544054 try server.serveErrorBundle(output.errors);
......@@ -4398,7 +4398,12 @@ fn updateModule(comp: *Compilation, color: Color, prog_node: std.Progress.Node)
43984398 }
43994399}
44004400
4401fn cmdTranslateC(comp: *Compilation, arena: Allocator, fancy_output: ?*Compilation.CImportResult) !void {
4401fn cmdTranslateC(
4402 comp: *Compilation,
4403 arena: Allocator,
4404 fancy_output: ?*Compilation.CImportResult,
4405 prog_node: std.Progress.Node,
4406) !void {
44024407 if (build_options.only_core_functionality) @panic("@translate-c is not available in a zig2.c build");
44034408 const color: Color = .auto;
44044409 assert(comp.c_source_files.len == 1);
......@@ -4459,6 +4464,7 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, fancy_output: ?*Compilati
44594464 .root_src_path = "aro_translate_c.zig",
44604465 .depend_on_aro = true,
44614466 .capture = &stdout,
4467 .progress_node = prog_node,
44624468 });
44634469 break :f stdout;
44644470 },
......@@ -5236,6 +5242,7 @@ const JitCmdOptions = struct {
52365242 capture: ?*[]u8 = null,
52375243 /// Send error bundles via std.zig.Server over stdout
52385244 server: bool = false,
5245 progress_node: std.Progress.Node = .{ .index = .none },
52395246};
52405247
52415248fn jitCmd(
......@@ -5245,9 +5252,12 @@ fn jitCmd(
52455252 options: JitCmdOptions,
52465253) !void {
52475254 const color: Color = .auto;
5248 const root_prog_node = std.Progress.start(.{
5249 .disable_printing = (color == .off),
5250 });
5255 const root_prog_node = if (options.progress_node.index != .none)
5256 options.progress_node
5257 else
5258 std.Progress.start(.{
5259 .disable_printing = (color == .off),
5260 });
52515261
52525262 const target_query: std.Target.Query = .{};
52535263 const resolved_target: Package.Module.ResolvedTarget = .{