authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-09 14:18:25-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-15 10:48:14-07:00
log7106a91b097c5ac0feb13f328bec5e6788f8c8ef
treed8214f4e6d7df4efe095fe11679612786b9fdc95
parent23295f64ca8b93f32e75cef42cc1293ec334e890

CLI: fix ast-check printing ZIR errors twice


1 files changed, 15 insertions(+), 52 deletions(-)

src/main.zig+15-52
......@@ -4082,12 +4082,7 @@ fn updateModule(gpa: Allocator, comp: *Compilation, hook: AfterUpdateHook) !void
40824082 defer errors.deinit(comp.gpa);
40834083
40844084 if (errors.errorMessageCount() > 0) {
4085 const ttyconf: std.debug.TTY.Config = switch (comp.color) {
4086 .auto => std.debug.detectTTYConfig(std.io.getStdErr()),
4087 .on => .escape_codes,
4088 .off => .no_color,
4089 };
4090 errors.renderToStdErr(ttyconf);
4085 errors.renderToStdErr(get_tty_conf(comp.color));
40914086 const log_text = comp.getCompileLogOutput();
40924087 if (log_text.len != 0) {
40934088 std.debug.print("\nCompile Log Output:\n{s}", .{log_text});
......@@ -4714,14 +4709,9 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
47144709 &all_modules,
47154710 );
47164711 if (wip_errors.root_list.items.len > 0) {
4717 const ttyconf: std.debug.TTY.Config = switch (color) {
4718 .auto => std.debug.detectTTYConfig(std.io.getStdErr()),
4719 .on => .escape_codes,
4720 .off => .no_color,
4721 };
47224712 var errors = try wip_errors.toOwnedBundle();
47234713 defer errors.deinit(gpa);
4724 errors.renderToStdErr(ttyconf);
4714 errors.renderToStdErr(get_tty_conf(color));
47254715 process.exit(1);
47264716 }
47274717 try fetch_result;
......@@ -4767,7 +4757,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
47674757 defer comp.destroy();
47684758
47694759 updateModule(gpa, comp, .none) catch |err| switch (err) {
4770 error.SemanticAnalyzeFail => process.exit(1),
4760 error.SemanticAnalyzeFail => process.exit(2),
47714761 else => |e| return e,
47724762 };
47734763 try comp.makeBinFileExecutable();
......@@ -4982,14 +4972,9 @@ pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
49824972 try wip_errors.init(gpa);
49834973 defer wip_errors.deinit();
49844974 try Compilation.addZirErrorMessages(&wip_errors, &file);
4985 const ttyconf: std.debug.TTY.Config = switch (color) {
4986 .auto => std.debug.detectTTYConfig(std.io.getStdErr()),
4987 .on => .escape_codes,
4988 .off => .no_color,
4989 };
49904975 var error_bundle = try wip_errors.toOwnedBundle();
49914976 defer error_bundle.deinit(gpa);
4992 error_bundle.renderToStdErr(ttyconf);
4977 error_bundle.renderToStdErr(get_tty_conf(color));
49934978 process.exit(2);
49944979 }
49954980 } else if (tree.errors.len != 0) {
......@@ -5193,14 +5178,9 @@ fn fmtPathFile(
51935178 try wip_errors.init(gpa);
51945179 defer wip_errors.deinit();
51955180 try Compilation.addZirErrorMessages(&wip_errors, &file);
5196 const ttyconf: std.debug.TTY.Config = switch (fmt.color) {
5197 .auto => std.debug.detectTTYConfig(std.io.getStdErr()),
5198 .on => .escape_codes,
5199 .off => .no_color,
5200 };
52015181 var error_bundle = try wip_errors.toOwnedBundle();
52025182 defer error_bundle.deinit(gpa);
5203 error_bundle.renderToStdErr(ttyconf);
5183 error_bundle.renderToStdErr(get_tty_conf(fmt.color));
52045184 fmt.any_error = true;
52055185 }
52065186 }
......@@ -5235,14 +5215,9 @@ fn printAstErrorsToStderr(gpa: Allocator, tree: Ast, path: []const u8, color: Co
52355215
52365216 try putAstErrorsIntoBundle(gpa, tree, path, &wip_errors);
52375217
5238 const ttyconf: std.debug.TTY.Config = switch (color) {
5239 .auto => std.debug.detectTTYConfig(std.io.getStdErr()),
5240 .on => .escape_codes,
5241 .off => .no_color,
5242 };
52435218 var error_bundle = try wip_errors.toOwnedBundle();
52445219 defer error_bundle.deinit(gpa);
5245 error_bundle.renderToStdErr(ttyconf);
5220 error_bundle.renderToStdErr(get_tty_conf(color));
52465221}
52475222
52485223pub fn putAstErrorsIntoBundle(
......@@ -5848,11 +5823,6 @@ pub fn cmdAstCheck(
58485823 file.tree_loaded = true;
58495824 defer file.tree.deinit(gpa);
58505825
5851 try printAstErrorsToStderr(gpa, file.tree, file.sub_file_path, color);
5852 if (file.tree.errors.len != 0) {
5853 process.exit(1);
5854 }
5855
58565826 file.zir = try AstGen.generate(gpa, file.tree);
58575827 file.zir_loaded = true;
58585828 defer file.zir.deinit(gpa);
......@@ -5862,14 +5832,9 @@ pub fn cmdAstCheck(
58625832 try wip_errors.init(gpa);
58635833 defer wip_errors.deinit();
58645834 try Compilation.addZirErrorMessages(&wip_errors, &file);
5865 const ttyconf: std.debug.TTY.Config = switch (color) {
5866 .auto => std.debug.detectTTYConfig(std.io.getStdErr()),
5867 .on => .escape_codes,
5868 .off => .no_color,
5869 };
58705835 var error_bundle = try wip_errors.toOwnedBundle();
58715836 defer error_bundle.deinit(gpa);
5872 error_bundle.renderToStdErr(ttyconf);
5837 error_bundle.renderToStdErr(get_tty_conf(color));
58735838 process.exit(1);
58745839 }
58755840
......@@ -5974,11 +5939,6 @@ pub fn cmdChangelist(
59745939 file.tree_loaded = true;
59755940 defer file.tree.deinit(gpa);
59765941
5977 try printAstErrorsToStderr(gpa, file.tree, old_source_file, .auto);
5978 if (file.tree.errors.len != 0) {
5979 process.exit(1);
5980 }
5981
59825942 file.zir = try AstGen.generate(gpa, file.tree);
59835943 file.zir_loaded = true;
59845944 defer file.zir.deinit(gpa);
......@@ -6013,11 +5973,6 @@ pub fn cmdChangelist(
60135973 var new_tree = try Ast.parse(gpa, new_source, .zig);
60145974 defer new_tree.deinit(gpa);
60155975
6016 try printAstErrorsToStderr(gpa, new_tree, new_source_file, .auto);
6017 if (new_tree.errors.len != 0) {
6018 process.exit(1);
6019 }
6020
60215976 var old_zir = file.zir;
60225977 defer old_zir.deinit(gpa);
60235978 file.zir_loaded = false;
......@@ -6293,3 +6248,11 @@ const ClangSearchSanitizer = struct {
62936248 iframework: bool = false,
62946249 };
62956250};
6251
6252fn get_tty_conf(color: Color) std.debug.TTY.Config {
6253 return switch (color) {
6254 .auto => std.debug.detectTTYConfig(std.io.getStdErr()),
6255 .on => .escape_codes,
6256 .off => .no_color,
6257 };
6258}