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 {...@@ -128,12 +128,12 @@ pub const Node = struct {
128 }128 }
129 };129 };
130130
131 const OptionalIndex = enum(u8) {131 pub const OptionalIndex = enum(u8) {
132 none = std.math.maxInt(u8),132 none = std.math.maxInt(u8),
133 /// Index into `node_storage`.133 /// Index into `node_storage`.
134 _,134 _,
135135
136 fn unwrap(i: @This()) ?Index {136 pub fn unwrap(i: @This()) ?Index {
137 if (i == .none) return null;137 if (i == .none) return null;
138 return @enumFromInt(@intFromEnum(i));138 return @enumFromInt(@intFromEnum(i));
139 }139 }
...@@ -145,7 +145,7 @@ pub const Node = struct {...@@ -145,7 +145,7 @@ pub const Node = struct {
145 };145 };
146146
147 /// Index into `node_storage`.147 /// Index into `node_storage`.
148 const Index = enum(u8) {148 pub const Index = enum(u8) {
149 _,149 _,
150150
151 fn toParent(i: @This()) Parent {151 fn toParent(i: @This()) Parent {
...@@ -154,7 +154,7 @@ pub const Node = struct {...@@ -154,7 +154,7 @@ pub const Node = struct {
154 return @enumFromInt(@intFromEnum(i));154 return @enumFromInt(@intFromEnum(i));
155 }155 }
156156
157 fn toOptional(i: @This()) OptionalIndex {157 pub fn toOptional(i: @This()) OptionalIndex {
158 return @enumFromInt(@intFromEnum(i));158 return @enumFromInt(@intFromEnum(i));
159 }159 }
160 };160 };
src/main.zig+19-9
...@@ -3404,15 +3404,15 @@ fn buildOutputType(...@@ -3404,15 +3404,15 @@ fn buildOutputType(
3404 },3404 },
3405 }3405 }
34063406
3407 if (arg_mode == .translate_c) {
3408 return cmdTranslateC(comp, arena, null);
3409 }
3410
3411 const root_prog_node = std.Progress.start(.{3407 const root_prog_node = std.Progress.start(.{
3412 .disable_printing = (color == .off),3408 .disable_printing = (color == .off),
3413 });3409 });
3414 defer root_prog_node.end();3410 defer root_prog_node.end();
34153411
3412 if (arg_mode == .translate_c) {
3413 return cmdTranslateC(comp, arena, null, root_prog_node);
3414 }
3415
3416 updateModule(comp, color, root_prog_node) catch |err| switch (err) {3416 updateModule(comp, color, root_prog_node) catch |err| switch (err) {
3417 error.SemanticAnalyzeFail => {3417 error.SemanticAnalyzeFail => {
3418 assert(listen == .none);3418 assert(listen == .none);
...@@ -4048,7 +4048,7 @@ fn serve(...@@ -4048,7 +4048,7 @@ fn serve(
4048 defer arena_instance.deinit();4048 defer arena_instance.deinit();
4049 const arena = arena_instance.allocator();4049 const arena = arena_instance.allocator();
4050 var output: Compilation.CImportResult = undefined;4050 var output: Compilation.CImportResult = undefined;
4051 try cmdTranslateC(comp, arena, &output);4051 try cmdTranslateC(comp, arena, &output, main_progress_node);
4052 defer output.deinit(gpa);4052 defer output.deinit(gpa);
4053 if (output.errors.errorMessageCount() != 0) {4053 if (output.errors.errorMessageCount() != 0) {
4054 try server.serveErrorBundle(output.errors);4054 try server.serveErrorBundle(output.errors);
...@@ -4398,7 +4398,12 @@ fn updateModule(comp: *Compilation, color: Color, prog_node: std.Progress.Node)...@@ -4398,7 +4398,12 @@ fn updateModule(comp: *Compilation, color: Color, prog_node: std.Progress.Node)
4398 }4398 }
4399}4399}
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 {
4402 if (build_options.only_core_functionality) @panic("@translate-c is not available in a zig2.c build");4407 if (build_options.only_core_functionality) @panic("@translate-c is not available in a zig2.c build");
4403 const color: Color = .auto;4408 const color: Color = .auto;
4404 assert(comp.c_source_files.len == 1);4409 assert(comp.c_source_files.len == 1);
...@@ -4459,6 +4464,7 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, fancy_output: ?*Compilati...@@ -4459,6 +4464,7 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, fancy_output: ?*Compilati
4459 .root_src_path = "aro_translate_c.zig",4464 .root_src_path = "aro_translate_c.zig",
4460 .depend_on_aro = true,4465 .depend_on_aro = true,
4461 .capture = &stdout,4466 .capture = &stdout,
4467 .progress_node = prog_node,
4462 });4468 });
4463 break :f stdout;4469 break :f stdout;
4464 },4470 },
...@@ -5236,6 +5242,7 @@ const JitCmdOptions = struct {...@@ -5236,6 +5242,7 @@ const JitCmdOptions = struct {
5236 capture: ?*[]u8 = null,5242 capture: ?*[]u8 = null,
5237 /// Send error bundles via std.zig.Server over stdout5243 /// Send error bundles via std.zig.Server over stdout
5238 server: bool = false,5244 server: bool = false,
5245 progress_node: std.Progress.Node = .{ .index = .none },
5239};5246};
52405247
5241fn jitCmd(5248fn jitCmd(
...@@ -5245,9 +5252,12 @@ fn jitCmd(...@@ -5245,9 +5252,12 @@ fn jitCmd(
5245 options: JitCmdOptions,5252 options: JitCmdOptions,
5246) !void {5253) !void {
5247 const color: Color = .auto;5254 const color: Color = .auto;
5248 const root_prog_node = std.Progress.start(.{5255 const root_prog_node = if (options.progress_node.index != .none)
5249 .disable_printing = (color == .off),5256 options.progress_node
5250 });5257 else
5258 std.Progress.start(.{
5259 .disable_printing = (color == .off),
5260 });
52515261
5252 const target_query: std.Target.Query = .{};5262 const target_query: std.Target.Query = .{};
5253 const resolved_target: Package.Module.ResolvedTarget = .{5263 const resolved_target: Package.Module.ResolvedTarget = .{