| author | |
| committer | |
| log | 0870f17501aa7d2eaaf2d774ccbc5d72291664ca |
| tree | beaa280f67fa4ef4b03905e9f6b5fc3780ec8dc2 |
| parent | c05e2720a1acf0dc86e7f8a2661daae095d4d59b |
6 files changed, 104 insertions(+), 102 deletions(-)
lib/compiler/aro/aro/Driver.zig+2-1| ... | ... | @@ -134,8 +134,9 @@ strip: bool = false, |
| 134 | 134 | unwindlib: ?[]const u8 = null, |
| 135 | 135 | |
| 136 | 136 | pub fn deinit(d: *Driver) void { |
| 137 | const io = d.comp.io; | |
| 137 | 138 | for (d.link_objects.items[d.link_objects.items.len - d.temp_file_count ..]) |obj| { |
| 138 | std.fs.deleteFileAbsolute(obj) catch {}; | |
| 139 | Io.Dir.deleteFileAbsolute(io, obj) catch {}; | |
| 139 | 140 | d.comp.gpa.free(obj); |
| 140 | 141 | } |
| 141 | 142 | d.inputs.deinit(d.comp.gpa); |
lib/compiler/resinator/cli.zig+27-26| ... | ... | @@ -125,8 +125,8 @@ pub const Diagnostics = struct { |
| 125 | 125 | try self.errors.append(self.allocator, error_details); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | pub fn renderToStderr(self: *Diagnostics, io: Io, args: []const []const u8) void { | |
| 129 | const stderr = io.lockStderr(&.{}, null); | |
| 128 | pub fn renderToStderr(self: *Diagnostics, io: Io, args: []const []const u8) Io.Cancelable!void { | |
| 129 | const stderr = try io.lockStderr(&.{}, null); | |
| 130 | 130 | defer io.unlockStderr(); |
| 131 | 131 | self.renderToWriter(args, stderr.terminal()) catch return; |
| 132 | 132 | } |
| ... | ... | @@ -419,7 +419,7 @@ pub const Arg = struct { |
| 419 | 419 | }; |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | pub fn looksLikeFilepath(self: Arg) bool { | |
| 422 | pub fn looksLikeFilepath(self: Arg, io: Io) bool { | |
| 423 | 423 | const meets_min_requirements = self.prefix == .slash and isSupportedInputExtension(std.fs.path.extension(self.full)); |
| 424 | 424 | if (!meets_min_requirements) return false; |
| 425 | 425 | |
| ... | ... | @@ -438,7 +438,7 @@ pub const Arg = struct { |
| 438 | 438 | // It's still possible for a file path to look like a /fo option but not actually |
| 439 | 439 | // be one, e.g. `/foo/bar.rc`. As a last ditch effort to reduce false negatives, |
| 440 | 440 | // check if the file path exists and, if so, then we ignore the 'could be /fo option'-ness |
| 441 | std.fs.accessAbsolute(self.full, .{}) catch return false; | |
| 441 | Io.Dir.accessAbsolute(io, self.full, .{}) catch return false; | |
| 442 | 442 | return true; |
| 443 | 443 | } |
| 444 | 444 | |
| ... | ... | @@ -490,7 +490,7 @@ pub const ParseError = error{ParseError} || Allocator.Error; |
| 490 | 490 | |
| 491 | 491 | /// Note: Does not run `Options.maybeAppendRC` automatically. If that behavior is desired, |
| 492 | 492 | /// it must be called separately. |
| 493 | pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagnostics) ParseError!Options { | |
| 493 | pub fn parse(allocator: Allocator, io: Io, args: []const []const u8, diagnostics: *Diagnostics) ParseError!Options { | |
| 494 | 494 | var options = Options{ .allocator = allocator }; |
| 495 | 495 | errdefer options.deinit(); |
| 496 | 496 | |
| ... | ... | @@ -530,7 +530,7 @@ pub fn parse(allocator: Allocator, args: []const []const u8, diagnostics: *Diagn |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | const args_remaining = args.len - arg_i; |
| 533 | if (args_remaining <= 2 and arg.looksLikeFilepath()) { | |
| 533 | if (args_remaining <= 2 and arg.looksLikeFilepath(io)) { | |
| 534 | 534 | var err_details = Diagnostics.ErrorDetails{ .type = .note, .print_args = true, .arg_index = arg_i }; |
| 535 | 535 | try err_details.msg.appendSlice(allocator, "this argument was inferred to be a filepath, so argument parsing was terminated"); |
| 536 | 536 | try diagnostics.append(err_details); |
| ... | ... | @@ -1344,41 +1344,42 @@ test parsePercent { |
| 1344 | 1344 | try std.testing.expectError(error.InvalidFormat, parsePercent("~1")); |
| 1345 | 1345 | } |
| 1346 | 1346 | |
| 1347 | pub fn renderErrorMessage(writer: *std.Io.Writer, config: std.Io.tty.Config, err_details: Diagnostics.ErrorDetails, args: []const []const u8) !void { | |
| 1348 | try config.setColor(writer, .dim); | |
| 1347 | pub fn renderErrorMessage(t: Io.Terminal, err_details: Diagnostics.ErrorDetails, args: []const []const u8) !void { | |
| 1348 | const writer = t.writer; | |
| 1349 | try t.setColor(.dim); | |
| 1349 | 1350 | try writer.writeAll("<cli>"); |
| 1350 | try config.setColor(writer, .reset); | |
| 1351 | try config.setColor(writer, .bold); | |
| 1351 | try t.setColor(.reset); | |
| 1352 | try t.setColor(.bold); | |
| 1352 | 1353 | try writer.writeAll(": "); |
| 1353 | 1354 | switch (err_details.type) { |
| 1354 | 1355 | .err => { |
| 1355 | try config.setColor(writer, .red); | |
| 1356 | try t.setColor(.red); | |
| 1356 | 1357 | try writer.writeAll("error: "); |
| 1357 | 1358 | }, |
| 1358 | 1359 | .warning => { |
| 1359 | try config.setColor(writer, .yellow); | |
| 1360 | try t.setColor(.yellow); | |
| 1360 | 1361 | try writer.writeAll("warning: "); |
| 1361 | 1362 | }, |
| 1362 | 1363 | .note => { |
| 1363 | try config.setColor(writer, .cyan); | |
| 1364 | try t.setColor(.cyan); | |
| 1364 | 1365 | try writer.writeAll("note: "); |
| 1365 | 1366 | }, |
| 1366 | 1367 | } |
| 1367 | try config.setColor(writer, .reset); | |
| 1368 | try config.setColor(writer, .bold); | |
| 1368 | try t.setColor(.reset); | |
| 1369 | try t.setColor(.bold); | |
| 1369 | 1370 | try writer.writeAll(err_details.msg.items); |
| 1370 | 1371 | try writer.writeByte('\n'); |
| 1371 | try config.setColor(writer, .reset); | |
| 1372 | try t.setColor(.reset); | |
| 1372 | 1373 | |
| 1373 | 1374 | if (!err_details.print_args) { |
| 1374 | 1375 | try writer.writeByte('\n'); |
| 1375 | 1376 | return; |
| 1376 | 1377 | } |
| 1377 | 1378 | |
| 1378 | try config.setColor(writer, .dim); | |
| 1379 | try t.setColor(.dim); | |
| 1379 | 1380 | const prefix = " ... "; |
| 1380 | 1381 | try writer.writeAll(prefix); |
| 1381 | try config.setColor(writer, .reset); | |
| 1382 | try t.setColor(.reset); | |
| 1382 | 1383 | |
| 1383 | 1384 | const arg_with_name = args[err_details.arg_index]; |
| 1384 | 1385 | const prefix_slice = arg_with_name[0..err_details.arg_span.prefix_len]; |
| ... | ... | @@ -1389,15 +1390,15 @@ pub fn renderErrorMessage(writer: *std.Io.Writer, config: std.Io.tty.Config, err |
| 1389 | 1390 | |
| 1390 | 1391 | try writer.writeAll(prefix_slice); |
| 1391 | 1392 | if (before_name_slice.len > 0) { |
| 1392 | try config.setColor(writer, .dim); | |
| 1393 | try t.setColor(.dim); | |
| 1393 | 1394 | try writer.writeAll(before_name_slice); |
| 1394 | try config.setColor(writer, .reset); | |
| 1395 | try t.setColor(.reset); | |
| 1395 | 1396 | } |
| 1396 | 1397 | try writer.writeAll(name_slice); |
| 1397 | 1398 | if (after_name_slice.len > 0) { |
| 1398 | try config.setColor(writer, .dim); | |
| 1399 | try t.setColor(.dim); | |
| 1399 | 1400 | try writer.writeAll(after_name_slice); |
| 1400 | try config.setColor(writer, .reset); | |
| 1401 | try t.setColor(.reset); | |
| 1401 | 1402 | } |
| 1402 | 1403 | |
| 1403 | 1404 | var next_arg_len: usize = 0; |
| ... | ... | @@ -1415,13 +1416,13 @@ pub fn renderErrorMessage(writer: *std.Io.Writer, config: std.Io.tty.Config, err |
| 1415 | 1416 | if (err_details.arg_span.value_offset >= arg_with_name.len) { |
| 1416 | 1417 | try writer.writeByte(' '); |
| 1417 | 1418 | } |
| 1418 | try config.setColor(writer, .dim); | |
| 1419 | try t.setColor(.dim); | |
| 1419 | 1420 | try writer.writeAll(" ..."); |
| 1420 | try config.setColor(writer, .reset); | |
| 1421 | try t.setColor(.reset); | |
| 1421 | 1422 | } |
| 1422 | 1423 | try writer.writeByte('\n'); |
| 1423 | 1424 | |
| 1424 | try config.setColor(writer, .green); | |
| 1425 | try t.setColor(.green); | |
| 1425 | 1426 | try writer.splatByteAll(' ', prefix.len); |
| 1426 | 1427 | // Special case for when the option is *only* a prefix (e.g. invalid option: -) |
| 1427 | 1428 | if (err_details.arg_span.prefix_len == arg_with_name.len) { |
| ... | ... | @@ -1447,7 +1448,7 @@ pub fn renderErrorMessage(writer: *std.Io.Writer, config: std.Io.tty.Config, err |
| 1447 | 1448 | } |
| 1448 | 1449 | } |
| 1449 | 1450 | try writer.writeByte('\n'); |
| 1450 | try config.setColor(writer, .reset); | |
| 1451 | try t.setColor(.reset); | |
| 1451 | 1452 | } |
| 1452 | 1453 | |
| 1453 | 1454 | fn testParse(args: []const []const u8) !Options { |
lib/compiler/resinator/compile.zig+3-3| ... | ... | @@ -96,7 +96,7 @@ pub fn compile(allocator: Allocator, io: Io, source: []const u8, writer: *std.Io |
| 96 | 96 | var search_dirs: std.ArrayList(SearchDir) = .empty; |
| 97 | 97 | defer { |
| 98 | 98 | for (search_dirs.items) |*search_dir| { |
| 99 | search_dir.deinit(allocator); | |
| 99 | search_dir.deinit(allocator, io); | |
| 100 | 100 | } |
| 101 | 101 | search_dirs.deinit(allocator); |
| 102 | 102 | } |
| ... | ... | @@ -406,7 +406,7 @@ pub const Compiler = struct { |
| 406 | 406 | // `/test.bin` relative to include paths and instead only treats it as |
| 407 | 407 | // an absolute path. |
| 408 | 408 | if (std.fs.path.isAbsolute(path)) { |
| 409 | const file = try utils.openFileNotDir(Io.Dir.cwd(), path, .{}); | |
| 409 | const file = try utils.openFileNotDir(Io.Dir.cwd(), io, path, .{}); | |
| 410 | 410 | errdefer file.close(io); |
| 411 | 411 | |
| 412 | 412 | if (self.dependencies) |dependencies| { |
| ... | ... | @@ -418,7 +418,7 @@ pub const Compiler = struct { |
| 418 | 418 | |
| 419 | 419 | var first_error: ?(std.Io.File.OpenError || std.Io.File.StatError) = null; |
| 420 | 420 | for (self.search_dirs) |search_dir| { |
| 421 | if (utils.openFileNotDir(search_dir.dir, path, .{})) |file| { | |
| 421 | if (utils.openFileNotDir(search_dir.dir, io, path, .{})) |file| { | |
| 422 | 422 | errdefer file.close(io); |
| 423 | 423 | |
| 424 | 424 | if (self.dependencies) |dependencies| { |
lib/compiler/resinator/errors.zig+35-35| ... | ... | @@ -67,9 +67,9 @@ pub const Diagnostics = struct { |
| 67 | 67 | return @intCast(index); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | pub fn renderToStderr(self: *Diagnostics, cwd: Io.Dir, source: []const u8, source_mappings: ?SourceMappings) void { | |
| 70 | pub fn renderToStderr(self: *Diagnostics, cwd: Io.Dir, source: []const u8, source_mappings: ?SourceMappings) Io.Cancelable!void { | |
| 71 | 71 | const io = self.io; |
| 72 | const stderr = io.lockStderr(&.{}, null); | |
| 72 | const stderr = try io.lockStderr(&.{}, null); | |
| 73 | 73 | defer io.unlockStderr(); |
| 74 | 74 | for (self.errors.items) |err_details| { |
| 75 | 75 | renderErrorMessage(io, stderr.terminal(), cwd, err_details, source, self.strings.items, source_mappings) catch return; |
| ... | ... | @@ -901,8 +901,7 @@ const truncated_str = "<...truncated...>"; |
| 901 | 901 | |
| 902 | 902 | pub fn renderErrorMessage( |
| 903 | 903 | io: Io, |
| 904 | writer: *std.Io.Writer, | |
| 905 | tty_config: std.Io.tty.Config, | |
| 904 | t: Io.Terminal, | |
| 906 | 905 | cwd: Io.Dir, |
| 907 | 906 | err_details: ErrorDetails, |
| 908 | 907 | source: []const u8, |
| ... | ... | @@ -927,36 +926,37 @@ pub fn renderErrorMessage( |
| 927 | 926 | |
| 928 | 927 | const err_line = if (corresponding_span) |span| span.start_line else err_details.token.line_number; |
| 929 | 928 | |
| 930 | try tty_config.setColor(writer, .bold); | |
| 929 | const writer = t.writer; | |
| 930 | try t.setColor(.bold); | |
| 931 | 931 | if (corresponding_file) |file| { |
| 932 | 932 | try writer.writeAll(file); |
| 933 | 933 | } else { |
| 934 | try tty_config.setColor(writer, .dim); | |
| 934 | try t.setColor(.dim); | |
| 935 | 935 | try writer.writeAll("<after preprocessor>"); |
| 936 | try tty_config.setColor(writer, .reset); | |
| 937 | try tty_config.setColor(writer, .bold); | |
| 936 | try t.setColor(.reset); | |
| 937 | try t.setColor(.bold); | |
| 938 | 938 | } |
| 939 | 939 | try writer.print(":{d}:{d}: ", .{ err_line, column }); |
| 940 | 940 | switch (err_details.type) { |
| 941 | 941 | .err => { |
| 942 | try tty_config.setColor(writer, .red); | |
| 942 | try t.setColor(.red); | |
| 943 | 943 | try writer.writeAll("error: "); |
| 944 | 944 | }, |
| 945 | 945 | .warning => { |
| 946 | try tty_config.setColor(writer, .yellow); | |
| 946 | try t.setColor(.yellow); | |
| 947 | 947 | try writer.writeAll("warning: "); |
| 948 | 948 | }, |
| 949 | 949 | .note => { |
| 950 | try tty_config.setColor(writer, .cyan); | |
| 950 | try t.setColor(.cyan); | |
| 951 | 951 | try writer.writeAll("note: "); |
| 952 | 952 | }, |
| 953 | 953 | .hint => unreachable, |
| 954 | 954 | } |
| 955 | try tty_config.setColor(writer, .reset); | |
| 956 | try tty_config.setColor(writer, .bold); | |
| 955 | try t.setColor(.reset); | |
| 956 | try t.setColor(.bold); | |
| 957 | 957 | try err_details.render(writer, source, strings); |
| 958 | 958 | try writer.writeByte('\n'); |
| 959 | try tty_config.setColor(writer, .reset); | |
| 959 | try t.setColor(.reset); | |
| 960 | 960 | |
| 961 | 961 | if (!err_details.print_source_line) { |
| 962 | 962 | try writer.writeByte('\n'); |
| ... | ... | @@ -983,20 +983,20 @@ pub fn renderErrorMessage( |
| 983 | 983 | |
| 984 | 984 | try writer.writeAll(source_line_for_display.line); |
| 985 | 985 | if (source_line_for_display.truncated) { |
| 986 | try tty_config.setColor(writer, .dim); | |
| 986 | try t.setColor(.dim); | |
| 987 | 987 | try writer.writeAll(truncated_str); |
| 988 | try tty_config.setColor(writer, .reset); | |
| 988 | try t.setColor(.reset); | |
| 989 | 989 | } |
| 990 | 990 | try writer.writeByte('\n'); |
| 991 | 991 | |
| 992 | try tty_config.setColor(writer, .green); | |
| 992 | try t.setColor(.green); | |
| 993 | 993 | const num_spaces = truncated_visual_info.point_offset - truncated_visual_info.before_len; |
| 994 | 994 | try writer.splatByteAll(' ', num_spaces); |
| 995 | 995 | try writer.splatByteAll('~', truncated_visual_info.before_len); |
| 996 | 996 | try writer.writeByte('^'); |
| 997 | 997 | try writer.splatByteAll('~', truncated_visual_info.after_len); |
| 998 | 998 | try writer.writeByte('\n'); |
| 999 | try tty_config.setColor(writer, .reset); | |
| 999 | try t.setColor(.reset); | |
| 1000 | 1000 | |
| 1001 | 1001 | if (corresponding_span != null and corresponding_file != null) { |
| 1002 | 1002 | var worth_printing_lines: bool = true; |
| ... | ... | @@ -1021,22 +1021,22 @@ pub fn renderErrorMessage( |
| 1021 | 1021 | break :blk null; |
| 1022 | 1022 | }, |
| 1023 | 1023 | }; |
| 1024 | defer if (corresponding_lines) |*cl| cl.deinit(); | |
| 1024 | defer if (corresponding_lines) |*cl| cl.deinit(io); | |
| 1025 | 1025 | |
| 1026 | try tty_config.setColor(writer, .bold); | |
| 1026 | try t.setColor(.bold); | |
| 1027 | 1027 | if (corresponding_file) |file| { |
| 1028 | 1028 | try writer.writeAll(file); |
| 1029 | 1029 | } else { |
| 1030 | try tty_config.setColor(writer, .dim); | |
| 1030 | try t.setColor(.dim); | |
| 1031 | 1031 | try writer.writeAll("<after preprocessor>"); |
| 1032 | try tty_config.setColor(writer, .reset); | |
| 1033 | try tty_config.setColor(writer, .bold); | |
| 1032 | try t.setColor(.reset); | |
| 1033 | try t.setColor(.bold); | |
| 1034 | 1034 | } |
| 1035 | 1035 | try writer.print(":{d}:{d}: ", .{ err_line, column }); |
| 1036 | try tty_config.setColor(writer, .cyan); | |
| 1036 | try t.setColor(.cyan); | |
| 1037 | 1037 | try writer.writeAll("note: "); |
| 1038 | try tty_config.setColor(writer, .reset); | |
| 1039 | try tty_config.setColor(writer, .bold); | |
| 1038 | try t.setColor(.reset); | |
| 1039 | try t.setColor(.bold); | |
| 1040 | 1040 | try writer.writeAll("this line originated from line"); |
| 1041 | 1041 | if (corresponding_span.?.start_line != corresponding_span.?.end_line) { |
| 1042 | 1042 | try writer.print("s {}-{}", .{ corresponding_span.?.start_line, corresponding_span.?.end_line }); |
| ... | ... | @@ -1044,7 +1044,7 @@ pub fn renderErrorMessage( |
| 1044 | 1044 | try writer.print(" {}", .{corresponding_span.?.start_line}); |
| 1045 | 1045 | } |
| 1046 | 1046 | try writer.print(" of file '{s}'\n", .{corresponding_file.?}); |
| 1047 | try tty_config.setColor(writer, .reset); | |
| 1047 | try t.setColor(.reset); | |
| 1048 | 1048 | |
| 1049 | 1049 | if (!worth_printing_lines) return; |
| 1050 | 1050 | |
| ... | ... | @@ -1055,21 +1055,21 @@ pub fn renderErrorMessage( |
| 1055 | 1055 | }) |display_line| { |
| 1056 | 1056 | try writer.writeAll(display_line.line); |
| 1057 | 1057 | if (display_line.truncated) { |
| 1058 | try tty_config.setColor(writer, .dim); | |
| 1058 | try t.setColor(.dim); | |
| 1059 | 1059 | try writer.writeAll(truncated_str); |
| 1060 | try tty_config.setColor(writer, .reset); | |
| 1060 | try t.setColor(.reset); | |
| 1061 | 1061 | } |
| 1062 | 1062 | try writer.writeByte('\n'); |
| 1063 | 1063 | } |
| 1064 | 1064 | break :write_lines null; |
| 1065 | 1065 | }; |
| 1066 | 1066 | if (write_lines_err) |err| { |
| 1067 | try tty_config.setColor(writer, .red); | |
| 1067 | try t.setColor(.red); | |
| 1068 | 1068 | try writer.writeAll(" | "); |
| 1069 | try tty_config.setColor(writer, .reset); | |
| 1070 | try tty_config.setColor(writer, .dim); | |
| 1069 | try t.setColor(.reset); | |
| 1070 | try t.setColor(.dim); | |
| 1071 | 1071 | try writer.print("unable to print line(s) from file: {s}\n", .{@errorName(err)}); |
| 1072 | try tty_config.setColor(writer, .reset); | |
| 1072 | try t.setColor(.reset); | |
| 1073 | 1073 | } |
| 1074 | 1074 | try writer.writeByte('\n'); |
| 1075 | 1075 | } |
| ... | ... | @@ -1120,12 +1120,12 @@ const CorrespondingLines = struct { |
| 1120 | 1120 | |
| 1121 | 1121 | var corresponding_lines = CorrespondingLines{ |
| 1122 | 1122 | .span = corresponding_span, |
| 1123 | .file = try utils.openFileNotDir(cwd, corresponding_file, .{}), | |
| 1123 | .file = try utils.openFileNotDir(cwd, io, corresponding_file, .{}), | |
| 1124 | 1124 | .code_page = err_details.code_page, |
| 1125 | 1125 | .file_reader = undefined, |
| 1126 | 1126 | }; |
| 1127 | 1127 | corresponding_lines.file_reader = corresponding_lines.file.reader(io, file_reader_buf); |
| 1128 | errdefer corresponding_lines.deinit(); | |
| 1128 | errdefer corresponding_lines.deinit(io); | |
| 1129 | 1129 | |
| 1130 | 1130 | try corresponding_lines.writeLineFromStreamVerbatim( |
| 1131 | 1131 | &corresponding_lines.file_reader.interface, |
lib/compiler/resinator/main.zig+26-27| ... | ... | @@ -64,18 +64,18 @@ pub fn main() !void { |
| 64 | 64 | var options = options: { |
| 65 | 65 | var cli_diagnostics = cli.Diagnostics.init(gpa); |
| 66 | 66 | defer cli_diagnostics.deinit(); |
| 67 | var options = cli.parse(gpa, cli_args, &cli_diagnostics) catch |err| switch (err) { | |
| 67 | var options = cli.parse(gpa, io, cli_args, &cli_diagnostics) catch |err| switch (err) { | |
| 68 | 68 | error.ParseError => { |
| 69 | try error_handler.emitCliDiagnostics(gpa, cli_args, &cli_diagnostics); | |
| 69 | try error_handler.emitCliDiagnostics(gpa, io, cli_args, &cli_diagnostics); | |
| 70 | 70 | std.process.exit(1); |
| 71 | 71 | }, |
| 72 | 72 | else => |e| return e, |
| 73 | 73 | }; |
| 74 | try options.maybeAppendRC(Io.Dir.cwd()); | |
| 74 | try options.maybeAppendRC(io, Io.Dir.cwd()); | |
| 75 | 75 | |
| 76 | 76 | if (!zig_integration) { |
| 77 | 77 | // print any warnings/notes |
| 78 | cli_diagnostics.renderToStderr(io, cli_args); | |
| 78 | try cli_diagnostics.renderToStderr(io, cli_args); | |
| 79 | 79 | // If there was something printed, then add an extra newline separator |
| 80 | 80 | // so that there is a clear separation between the cli diagnostics and whatever |
| 81 | 81 | // gets printed after |
| ... | ... | @@ -193,7 +193,7 @@ pub fn main() !void { |
| 193 | 193 | }; |
| 194 | 194 | }, |
| 195 | 195 | .filename => |input_filename| { |
| 196 | break :full_input Io.Dir.cwd().readFileAlloc(input_filename, gpa, .unlimited) catch |err| { | |
| 196 | break :full_input Io.Dir.cwd().readFileAlloc(io, input_filename, gpa, .unlimited) catch |err| { | |
| 197 | 197 | try error_handler.emitMessage(gpa, io, .err, "unable to read input file path '{s}': {s}", .{ input_filename, @errorName(err) }); |
| 198 | 198 | std.process.exit(1); |
| 199 | 199 | }; |
| ... | ... | @@ -206,7 +206,7 @@ pub fn main() !void { |
| 206 | 206 | if (options.preprocess == .only) { |
| 207 | 207 | switch (options.output_source) { |
| 208 | 208 | .stdio => |output_file| { |
| 209 | try output_file.writeAll(full_input); | |
| 209 | try output_file.writeStreamingAll(io, full_input); | |
| 210 | 210 | }, |
| 211 | 211 | .filename => |output_filename| { |
| 212 | 212 | try Io.Dir.cwd().writeFile(io, .{ .sub_path = output_filename, .data = full_input }); |
| ... | ... | @@ -224,16 +224,16 @@ pub fn main() !void { |
| 224 | 224 | .source = .{ .memory = .empty }, |
| 225 | 225 | } |
| 226 | 226 | else if (options.input_format == .res) |
| 227 | IoStream.fromIoSource(options.input_source, .input) catch |err| { | |
| 227 | IoStream.fromIoSource(io, options.input_source, .input) catch |err| { | |
| 228 | 228 | try error_handler.emitMessage(gpa, io, .err, "unable to read res file path '{s}': {s}", .{ options.input_source.filename, @errorName(err) }); |
| 229 | 229 | std.process.exit(1); |
| 230 | 230 | } |
| 231 | 231 | else |
| 232 | IoStream.fromIoSource(options.output_source, .output) catch |err| { | |
| 232 | IoStream.fromIoSource(io, options.output_source, .output) catch |err| { | |
| 233 | 233 | try error_handler.emitMessage(gpa, io, .err, "unable to create output file '{s}': {s}", .{ options.output_source.filename, @errorName(err) }); |
| 234 | 234 | std.process.exit(1); |
| 235 | 235 | }; |
| 236 | defer res_stream.deinit(gpa); | |
| 236 | defer res_stream.deinit(gpa, io); | |
| 237 | 237 | |
| 238 | 238 | const res_data = res_data: { |
| 239 | 239 | if (options.input_format != .res) { |
| ... | ... | @@ -269,7 +269,7 @@ pub fn main() !void { |
| 269 | 269 | defer diagnostics.deinit(); |
| 270 | 270 | |
| 271 | 271 | var output_buffer: [4096]u8 = undefined; |
| 272 | var res_stream_writer = res_stream.source.writer(gpa, &output_buffer); | |
| 272 | var res_stream_writer = res_stream.source.writer(gpa, io, &output_buffer); | |
| 273 | 273 | defer res_stream_writer.deinit(&res_stream.source); |
| 274 | 274 | const output_buffered_stream = res_stream_writer.interface(); |
| 275 | 275 | |
| ... | ... | @@ -303,7 +303,7 @@ pub fn main() !void { |
| 303 | 303 | |
| 304 | 304 | // print any warnings/notes |
| 305 | 305 | if (!zig_integration) { |
| 306 | diagnostics.renderToStderr(io, Io.Dir.cwd(), final_input, mapping_results.mappings); | |
| 306 | try diagnostics.renderToStderr(Io.Dir.cwd(), final_input, mapping_results.mappings); | |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | // write the depfile |
| ... | ... | @@ -356,14 +356,14 @@ pub fn main() !void { |
| 356 | 356 | }; |
| 357 | 357 | defer resources.deinit(); |
| 358 | 358 | |
| 359 | var coff_stream = IoStream.fromIoSource(options.output_source, .output) catch |err| { | |
| 359 | var coff_stream = IoStream.fromIoSource(io, options.output_source, .output) catch |err| { | |
| 360 | 360 | try error_handler.emitMessage(gpa, io, .err, "unable to create output file '{s}': {s}", .{ options.output_source.filename, @errorName(err) }); |
| 361 | 361 | std.process.exit(1); |
| 362 | 362 | }; |
| 363 | defer coff_stream.deinit(gpa); | |
| 363 | defer coff_stream.deinit(gpa, io); | |
| 364 | 364 | |
| 365 | 365 | var coff_output_buffer: [4096]u8 = undefined; |
| 366 | var coff_output_buffered_stream = coff_stream.source.writer(gpa, &coff_output_buffer); | |
| 366 | var coff_output_buffered_stream = coff_stream.source.writer(gpa, io, &coff_output_buffer); | |
| 367 | 367 | |
| 368 | 368 | var cvtres_diagnostics: cvtres.Diagnostics = .{ .none = {} }; |
| 369 | 369 | cvtres.writeCoff(gpa, coff_output_buffered_stream.interface(), resources.list.items, options.coff_options, &cvtres_diagnostics) catch |err| { |
| ... | ... | @@ -413,22 +413,22 @@ const IoStream = struct { |
| 413 | 413 | |
| 414 | 414 | pub const IoDirection = enum { input, output }; |
| 415 | 415 | |
| 416 | pub fn fromIoSource(source: cli.Options.IoSource, io: IoDirection) !IoStream { | |
| 416 | pub fn fromIoSource(io: Io, source: cli.Options.IoSource, io_direction: IoDirection) !IoStream { | |
| 417 | 417 | return .{ |
| 418 | 418 | .name = switch (source) { |
| 419 | 419 | .filename => |filename| filename, |
| 420 | .stdio => switch (io) { | |
| 420 | .stdio => switch (io_direction) { | |
| 421 | 421 | .input => "<stdin>", |
| 422 | 422 | .output => "<stdout>", |
| 423 | 423 | }, |
| 424 | 424 | }, |
| 425 | 425 | .intermediate = false, |
| 426 | .source = try Source.fromIoSource(source, io), | |
| 426 | .source = try Source.fromIoSource(io, source, io_direction), | |
| 427 | 427 | }; |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | pub fn deinit(self: *IoStream, allocator: Allocator) void { | |
| 431 | self.source.deinit(allocator); | |
| 430 | pub fn deinit(self: *IoStream, allocator: Allocator, io: Io) void { | |
| 431 | self.source.deinit(allocator, io); | |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | pub fn cleanupAfterError(self: *IoStream, io: Io) void { |
| ... | ... | @@ -450,11 +450,11 @@ const IoStream = struct { |
| 450 | 450 | /// The source has been closed and any usage of the Source in this state is illegal (except deinit). |
| 451 | 451 | closed: void, |
| 452 | 452 | |
| 453 | pub fn fromIoSource(source: cli.Options.IoSource, io: IoDirection) !Source { | |
| 453 | pub fn fromIoSource(io: Io, source: cli.Options.IoSource, io_direction: IoDirection) !Source { | |
| 454 | 454 | switch (source) { |
| 455 | 455 | .filename => |filename| return .{ |
| 456 | .file = switch (io) { | |
| 457 | .input => try openFileNotDir(Io.Dir.cwd(), filename, .{}), | |
| 456 | .file = switch (io_direction) { | |
| 457 | .input => try openFileNotDir(Io.Dir.cwd(), io, filename, .{}), | |
| 458 | 458 | .output => try Io.Dir.cwd().createFile(io, filename, .{}), |
| 459 | 459 | }, |
| 460 | 460 | }, |
| ... | ... | @@ -641,7 +641,7 @@ fn getIncludePaths( |
| 641 | 641 | }; |
| 642 | 642 | const target = std.zig.resolveTargetQueryOrFatal(io, target_query); |
| 643 | 643 | const is_native_abi = target_query.isNativeAbi(); |
| 644 | const detected_libc = std.zig.LibCDirs.detect(arena, zig_lib_dir, &target, is_native_abi, true, null) catch |err| switch (err) { | |
| 644 | const detected_libc = std.zig.LibCDirs.detect(arena, io, zig_lib_dir, &target, is_native_abi, true, null) catch |err| switch (err) { | |
| 645 | 645 | error.OutOfMemory => |e| return e, |
| 646 | 646 | else => return error.MingwIncludesNotFound, |
| 647 | 647 | }; |
| ... | ... | @@ -672,7 +672,7 @@ const ErrorHandler = union(enum) { |
| 672 | 672 | |
| 673 | 673 | try server.serveErrorBundle(error_bundle); |
| 674 | 674 | }, |
| 675 | .stderr => diagnostics.renderToStderr(io, args), | |
| 675 | .stderr => return diagnostics.renderToStderr(io, args), | |
| 676 | 676 | } |
| 677 | 677 | } |
| 678 | 678 | |
| ... | ... | @@ -696,7 +696,7 @@ const ErrorHandler = union(enum) { |
| 696 | 696 | }, |
| 697 | 697 | .stderr => { |
| 698 | 698 | // aro errors have already been emitted |
| 699 | const stderr = io.lockStderr(&.{}, null); | |
| 699 | const stderr = try io.lockStderr(&.{}, null); | |
| 700 | 700 | defer io.unlockStderr(); |
| 701 | 701 | try renderErrorMessage(stderr.terminal(), .err, "{s}", .{fail_msg}); |
| 702 | 702 | }, |
| ... | ... | @@ -706,7 +706,6 @@ const ErrorHandler = union(enum) { |
| 706 | 706 | pub fn emitDiagnostics( |
| 707 | 707 | self: *ErrorHandler, |
| 708 | 708 | allocator: Allocator, |
| 709 | io: Io, | |
| 710 | 709 | cwd: Io.Dir, |
| 711 | 710 | source: []const u8, |
| 712 | 711 | diagnostics: *Diagnostics, |
| ... | ... | @@ -719,7 +718,7 @@ const ErrorHandler = union(enum) { |
| 719 | 718 | |
| 720 | 719 | try server.serveErrorBundle(error_bundle); |
| 721 | 720 | }, |
| 722 | .stderr => diagnostics.renderToStderr(io, cwd, source, mappings), | |
| 721 | .stderr => return diagnostics.renderToStderr(cwd, source, mappings), | |
| 723 | 722 | } |
| 724 | 723 | } |
| 725 | 724 |
lib/compiler/resinator/utils.zig+11-10| ... | ... | @@ -92,31 +92,32 @@ pub const ErrorMessageType = enum { err, warning, note }; |
| 92 | 92 | |
| 93 | 93 | /// Used for generic colored errors/warnings/notes, more context-specific error messages |
| 94 | 94 | /// are handled elsewhere. |
| 95 | pub fn renderErrorMessage(writer: *std.Io.Writer, config: std.Io.tty.Config, msg_type: ErrorMessageType, comptime format: []const u8, args: anytype) !void { | |
| 95 | pub fn renderErrorMessage(t: Io.Terminal, msg_type: ErrorMessageType, comptime format: []const u8, args: anytype) !void { | |
| 96 | const writer = t.writer; | |
| 96 | 97 | switch (msg_type) { |
| 97 | 98 | .err => { |
| 98 | try config.setColor(writer, .bold); | |
| 99 | try config.setColor(writer, .red); | |
| 99 | try t.setColor(.bold); | |
| 100 | try t.setColor(.red); | |
| 100 | 101 | try writer.writeAll("error: "); |
| 101 | 102 | }, |
| 102 | 103 | .warning => { |
| 103 | try config.setColor(writer, .bold); | |
| 104 | try config.setColor(writer, .yellow); | |
| 104 | try t.setColor(.bold); | |
| 105 | try t.setColor(.yellow); | |
| 105 | 106 | try writer.writeAll("warning: "); |
| 106 | 107 | }, |
| 107 | 108 | .note => { |
| 108 | try config.setColor(writer, .reset); | |
| 109 | try config.setColor(writer, .cyan); | |
| 109 | try t.setColor(.reset); | |
| 110 | try t.setColor(.cyan); | |
| 110 | 111 | try writer.writeAll("note: "); |
| 111 | 112 | }, |
| 112 | 113 | } |
| 113 | try config.setColor(writer, .reset); | |
| 114 | try t.setColor(.reset); | |
| 114 | 115 | if (msg_type == .err) { |
| 115 | try config.setColor(writer, .bold); | |
| 116 | try t.setColor(.bold); | |
| 116 | 117 | } |
| 117 | 118 | try writer.print(format, args); |
| 118 | 119 | try writer.writeByte('\n'); |
| 119 | try config.setColor(writer, .reset); | |
| 120 | try t.setColor(.reset); | |
| 120 | 121 | } |
| 121 | 122 | |
| 122 | 123 | pub fn isLineEndingPair(first: u8, second: u8) bool { |