| ... | ... | @@ -2,6 +2,7 @@ const Compile = @This(); |
| 2 | 2 | |
| 3 | 3 | const std = @import("std"); |
| 4 | 4 | const Allocator = std.mem.Allocator; |
| 5 | const mem = std.mem; |
| 5 | 6 | const Configuration = std.Build.Configuration; |
| 6 | 7 | const Dir = std.Io.Dir; |
| 7 | 8 | const Path = std.Build.Cache.Path; |
| ... | ... | @@ -9,7 +10,6 @@ const Module = std.Build.Configuration.Module; |
| 9 | 10 | const Io = std.Io; |
| 10 | 11 | const Sha256 = std.crypto.hash.sha2.Sha256; |
| 11 | 12 | const assert = std.debug.assert; |
| 12 | | const mem = std.mem; |
| 13 | 13 | const allocPrint = std.fmt.allocPrint; |
| 14 | 14 | |
| 15 | 15 | const Step = @import("../Step.zig"); |
| ... | ... | @@ -51,7 +51,7 @@ pub fn make( |
| 51 | 51 | (graph.incremental == true) and (maker.watch or maker.web_server != null), |
| 52 | 52 | ) catch |err| switch (err) { |
| 53 | 53 | error.NeedCompileErrorCheck => { |
| 54 | | try checkCompileErrors(compile, maker); |
| 54 | try checkCompileErrors(maker, compile_index); |
| 55 | 55 | return; |
| 56 | 56 | }, |
| 57 | 57 | else => |e| return e, |
| ... | ... | @@ -518,7 +518,7 @@ fn lowerZigArgs( |
| 518 | 518 | const import_cli_name = cli_named_modules.names.keys()[import_index]; |
| 519 | 519 | zig_args.appendAssumeCapacity("--dep"); |
| 520 | 520 | const name_slice = name.slice(conf); |
| 521 | | if (std.mem.eql(u8, import_cli_name, name_slice)) { |
| 521 | if (mem.eql(u8, import_cli_name, name_slice)) { |
| 522 | 522 | zig_args.appendAssumeCapacity(import_cli_name); |
| 523 | 523 | } else { |
| 524 | 524 | zig_args.appendAssumeCapacity(try allocPrint(arena, "{s}={s}", .{ |
| ... | ... | @@ -898,8 +898,8 @@ fn lowerZigArgs( |
| 898 | 898 | |
| 899 | 899 | // Write the args to zig-cache/args/<SHA256 hash of args> to avoid conflicts with |
| 900 | 900 | // other zig build commands running in parallel. |
| 901 | | const partially_quoted = try std.mem.join(arena, "\" \"", escaped_args.items); |
| 902 | | const args = try std.mem.concat(arena, u8, &[_][]const u8{ "\"", partially_quoted, "\"" }); |
| 901 | const partially_quoted = try mem.join(arena, "\" \"", escaped_args.items); |
| 902 | const args = try mem.concat(arena, u8, &[_][]const u8{ "\"", partially_quoted, "\"" }); |
| 903 | 903 | |
| 904 | 904 | var args_hash: [Sha256.digest_length]u8 = undefined; |
| 905 | 905 | Sha256.hash(args, &args_hash, .{}); |
| ... | ... | @@ -943,24 +943,30 @@ fn lowerZigArgs( |
| 943 | 943 | } |
| 944 | 944 | } |
| 945 | 945 | |
| 946 | | pub fn rebuildInFuzzMode(compile: *Compile, maker: *Maker, progress_node: std.Progress.Node) !Path { |
| 946 | pub fn rebuildInFuzzMode( |
| 947 | compile: *Compile, |
| 948 | maker: *Maker, |
| 949 | step_index: Configuration.Step.Index, |
| 950 | progress_node: std.Progress.Node, |
| 951 | ) !Path { |
| 947 | 952 | const gpa = maker.graph.gpa; |
| 953 | const step = maker.stepByIndex(step_index); |
| 948 | 954 | |
| 949 | | compile.step.result_error_msgs.clearRetainingCapacity(); |
| 950 | | compile.step.result_stderr = ""; |
| 955 | step.result_error_msgs.clearRetainingCapacity(); |
| 956 | step.result_stderr = ""; |
| 951 | 957 | |
| 952 | | compile.step.result_error_bundle.deinit(gpa); |
| 953 | | compile.step.result_error_bundle = std.zig.ErrorBundle.empty; |
| 958 | step.result_error_bundle.deinit(gpa); |
| 959 | step.result_error_bundle = std.zig.ErrorBundle.empty; |
| 954 | 960 | |
| 955 | | if (compile.step.result_failed_command) |cmd| { |
| 961 | if (step.result_failed_command) |cmd| { |
| 956 | 962 | gpa.free(cmd); |
| 957 | | compile.step.result_failed_command = null; |
| 963 | step.result_failed_command = null; |
| 958 | 964 | } |
| 959 | 965 | |
| 960 | 966 | const zig_args = &compile.zig_args; |
| 961 | 967 | zig_args.clearRetainingCapacity(); |
| 962 | 968 | try lowerZigArgs(compile, maker, progress_node, zig_args, true); |
| 963 | | const maybe_output_bin_path = try compile.step.evalZigProcess(zig_args.items, progress_node, false, maker); |
| 969 | const maybe_output_bin_path = try step.evalZigProcess(zig_args.items, progress_node, false, maker); |
| 964 | 970 | return maybe_output_bin_path.?; |
| 965 | 971 | } |
| 966 | 972 | |
| ... | ... | @@ -973,35 +979,43 @@ fn addFlag(gpa: Allocator, args: *std.ArrayList([]const u8), comptime name: []co |
| 973 | 979 | try args.append(gpa, if (cond) "-f" ++ name else "-fno-" ++ name); |
| 974 | 980 | } |
| 975 | 981 | |
| 976 | | fn checkCompileErrors(compile: *Compile, maker: *Maker) !void { |
| 977 | | if (true) @panic("TODO checkCompileErrors"); |
| 978 | | // Clear this field so that it does not get printed by the build runner. |
| 979 | | const actual_eb = compile.step.result_error_bundle; |
| 980 | | compile.step.result_error_bundle = .empty; |
| 982 | fn checkCompileErrors( |
| 983 | maker: *Maker, |
| 984 | step_index: Configuration.Step.Index, |
| 985 | ) Step.ExtendedMakeError!void { |
| 986 | const step = maker.stepByIndex(step_index); |
| 987 | const graph = maker.graph; |
| 988 | const arena = graph.arena; // TODO don't leak into the process arena |
| 989 | const conf = &maker.scanned_config.configuration; |
| 990 | const conf_step = step_index.ptr(conf); |
| 991 | const conf_comp = conf_step.extended.get(conf.extra).compile; |
| 981 | 992 | |
| 982 | | const arena = compile.step.owner.allocator; |
| 993 | // Clear this field so that it does not get printed by the build runner. |
| 994 | const actual_eb = step.result_error_bundle; |
| 995 | step.result_error_bundle = .empty; |
| 983 | 996 | |
| 984 | 997 | const actual_errors = ae: { |
| 985 | 998 | var aw: std.Io.Writer.Allocating = .init(arena); |
| 986 | 999 | defer aw.deinit(); |
| 987 | | try actual_eb.renderToWriter(.{ |
| 1000 | actual_eb.renderToWriter(.{ |
| 988 | 1001 | .include_reference_trace = false, |
| 989 | 1002 | .include_source_line = false, |
| 990 | | }, &aw.writer); |
| 1003 | }, &aw.writer) catch |err| switch (err) { |
| 1004 | error.WriteFailed => return error.OutOfMemory, |
| 1005 | }; |
| 991 | 1006 | break :ae try aw.toOwnedSlice(); |
| 992 | 1007 | }; |
| 993 | 1008 | |
| 994 | 1009 | // Render the expected lines into a string that we can compare verbatim. |
| 995 | 1010 | var expected_generated: std.ArrayList(u8) = .empty; |
| 996 | | const expect_errors = compile.expect_errors.?; |
| 997 | | |
| 998 | 1011 | var actual_line_it = mem.splitScalar(u8, actual_errors, '\n'); |
| 999 | 1012 | |
| 1000 | | // TODO merge this with the testing.expectEqualStrings logic, and also CheckFile |
| 1001 | | switch (expect_errors) { |
| 1002 | | .starts_with => |expect_starts_with| { |
| 1003 | | if (std.mem.startsWith(u8, actual_errors, expect_starts_with)) return; |
| 1004 | | return compile.step.fail(maker, |
| 1013 | switch (conf_comp.expect_errors.u) { |
| 1014 | .none => unreachable, |
| 1015 | .starts_with => |expect_starts_with_string| { |
| 1016 | const expect_starts_with = expect_starts_with_string.slice(conf); |
| 1017 | if (mem.startsWith(u8, actual_errors, expect_starts_with)) return; |
| 1018 | return step.fail(maker, |
| 1005 | 1019 | \\ |
| 1006 | 1020 | \\========= should start with: ============ |
| 1007 | 1021 | \\{s} |
| ... | ... | @@ -1010,13 +1024,14 @@ fn checkCompileErrors(compile: *Compile, maker: *Maker) !void { |
| 1010 | 1024 | \\========================================= |
| 1011 | 1025 | , .{ expect_starts_with, actual_errors }); |
| 1012 | 1026 | }, |
| 1013 | | .contains => |expect_line| { |
| 1027 | .contains => |expect_line_string| { |
| 1028 | const expect_line = expect_line_string.slice(conf); |
| 1014 | 1029 | while (actual_line_it.next()) |actual_line| { |
| 1015 | 1030 | if (!matchCompileError(actual_line, expect_line)) continue; |
| 1016 | 1031 | return; |
| 1017 | 1032 | } |
| 1018 | 1033 | |
| 1019 | | return compile.step.fail(maker, |
| 1034 | return step.fail(maker, |
| 1020 | 1035 | \\ |
| 1021 | 1036 | \\========= should contain: =============== |
| 1022 | 1037 | \\{s} |
| ... | ... | @@ -1025,12 +1040,13 @@ fn checkCompileErrors(compile: *Compile, maker: *Maker) !void { |
| 1025 | 1040 | \\========================================= |
| 1026 | 1041 | , .{ expect_line, actual_errors }); |
| 1027 | 1042 | }, |
| 1028 | | .stderr_contains => |expect_line| { |
| 1029 | | const actual_stderr: []const u8 = if (compile.step.result_error_msgs.items.len > 0) |
| 1030 | | compile.step.result_error_msgs.items[0] |
| 1043 | .stderr_contains => |expect_line_string| { |
| 1044 | const expect_line = expect_line_string.slice(conf); |
| 1045 | const actual_stderr: []const u8 = if (step.result_error_msgs.items.len > 0) |
| 1046 | step.result_error_msgs.items[0] |
| 1031 | 1047 | else |
| 1032 | 1048 | &.{}; |
| 1033 | | compile.step.result_error_msgs.clearRetainingCapacity(); |
| 1049 | step.result_error_msgs.clearRetainingCapacity(); |
| 1034 | 1050 | |
| 1035 | 1051 | var stderr_line_it = mem.splitScalar(u8, actual_stderr, '\n'); |
| 1036 | 1052 | |
| ... | ... | @@ -1039,7 +1055,7 @@ fn checkCompileErrors(compile: *Compile, maker: *Maker) !void { |
| 1039 | 1055 | return; |
| 1040 | 1056 | } |
| 1041 | 1057 | |
| 1042 | | return compile.step.fail(maker, |
| 1058 | return step.fail(maker, |
| 1043 | 1059 | \\ |
| 1044 | 1060 | \\========= should contain: =============== |
| 1045 | 1061 | \\{s} |
| ... | ... | @@ -1049,7 +1065,8 @@ fn checkCompileErrors(compile: *Compile, maker: *Maker) !void { |
| 1049 | 1065 | , .{ expect_line, actual_stderr }); |
| 1050 | 1066 | }, |
| 1051 | 1067 | .exact => |expect_lines| { |
| 1052 | | for (expect_lines) |expect_line| { |
| 1068 | for (expect_lines.slice) |expect_line_string| { |
| 1069 | const expect_line = expect_line_string.slice(conf); |
| 1053 | 1070 | const actual_line = actual_line_it.next() orelse { |
| 1054 | 1071 | try expected_generated.appendSlice(arena, expect_line); |
| 1055 | 1072 | try expected_generated.append(arena, '\n'); |
| ... | ... | @@ -1066,7 +1083,7 @@ fn checkCompileErrors(compile: *Compile, maker: *Maker) !void { |
| 1066 | 1083 | |
| 1067 | 1084 | if (mem.eql(u8, expected_generated.items, actual_errors)) return; |
| 1068 | 1085 | |
| 1069 | | return compile.step.fail(maker, |
| 1086 | return step.fail(maker, |
| 1070 | 1087 | \\ |
| 1071 | 1088 | \\========= expected: ===================== |
| 1072 | 1089 | \\{s} |