| ... | @@ -737,6 +737,7 @@ pub const CompileErrorContext = struct { | ... | @@ -737,6 +737,7 @@ pub const CompileErrorContext = struct { |
| 737 | test_index: usize, | 737 | test_index: usize, |
| 738 | case: *const TestCase, | 738 | case: *const TestCase, |
| 739 | build_mode: Mode, | 739 | build_mode: Mode, |
| | 740 | write_src: *build.WriteFileStep, |
| 740 | | 741 | |
| 741 | const ErrLineIter = struct { | 742 | const ErrLineIter = struct { |
| 742 | lines: mem.SplitIterator, | 743 | lines: mem.SplitIterator, |
| ... | @@ -756,7 +757,13 @@ pub const CompileErrorContext = struct { | ... | @@ -756,7 +757,13 @@ pub const CompileErrorContext = struct { |
| 756 | } | 757 | } |
| 757 | }; | 758 | }; |
| 758 | | 759 | |
| 759 | pub fn create(context: *CompileErrorContext, name: []const u8, case: *const TestCase, build_mode: Mode) *CompileCmpOutputStep { | 760 | pub fn create( |
| | 761 | context: *CompileErrorContext, |
| | 762 | name: []const u8, |
| | 763 | case: *const TestCase, |
| | 764 | build_mode: Mode, |
| | 765 | write_src: *build.WriteFileStep, |
| | 766 | ) *CompileCmpOutputStep { |
| 760 | const allocator = context.b.allocator; | 767 | const allocator = context.b.allocator; |
| 761 | const ptr = allocator.create(CompileCmpOutputStep) catch unreachable; | 768 | const ptr = allocator.create(CompileCmpOutputStep) catch unreachable; |
| 762 | ptr.* = CompileCmpOutputStep{ | 769 | ptr.* = CompileCmpOutputStep{ |
| ... | @@ -766,6 +773,7 @@ pub const CompileErrorContext = struct { | ... | @@ -766,6 +773,7 @@ pub const CompileErrorContext = struct { |
| 766 | .test_index = context.test_index, | 773 | .test_index = context.test_index, |
| 767 | .case = case, | 774 | .case = case, |
| 768 | .build_mode = build_mode, | 775 | .build_mode = build_mode, |
| | 776 | .write_src = write_src, |
| 769 | }; | 777 | }; |
| 770 | | 778 | |
| 771 | context.test_index += 1; | 779 | context.test_index += 1; |
| ... | @@ -776,11 +784,6 @@ pub const CompileErrorContext = struct { | ... | @@ -776,11 +784,6 @@ pub const CompileErrorContext = struct { |
| 776 | const self = @fieldParentPtr(CompileCmpOutputStep, "step", step); | 784 | const self = @fieldParentPtr(CompileCmpOutputStep, "step", step); |
| 777 | const b = self.context.b; | 785 | const b = self.context.b; |
| 778 | | 786 | |
| 779 | const root_src = fs.path.join( | | |
| 780 | b.allocator, | | |
| 781 | &[_][]const u8{ b.cache_root, self.case.sources.items[0].filename }, | | |
| 782 | ) catch unreachable; | | |
| 783 | | | |
| 784 | var zig_args = ArrayList([]const u8).init(b.allocator); | 787 | var zig_args = ArrayList([]const u8).init(b.allocator); |
| 785 | zig_args.append(b.zig_exe) catch unreachable; | 788 | zig_args.append(b.zig_exe) catch unreachable; |
| 786 | | 789 | |
| ... | @@ -791,7 +794,8 @@ pub const CompileErrorContext = struct { | ... | @@ -791,7 +794,8 @@ pub const CompileErrorContext = struct { |
| 791 | } else { | 794 | } else { |
| 792 | try zig_args.append("build-obj"); | 795 | try zig_args.append("build-obj"); |
| 793 | } | 796 | } |
| 794 | zig_args.append(b.pathFromRoot(root_src)) catch unreachable; | 797 | const root_src_basename = self.case.sources.toSliceConst()[0].filename; |
| | 798 | try zig_args.append(self.write_src.getOutputPath(root_src_basename)); |
| 795 | | 799 | |
| 796 | zig_args.append("--name") catch unreachable; | 800 | zig_args.append("--name") catch unreachable; |
| 797 | zig_args.append("test") catch unreachable; | 801 | zig_args.append("test") catch unreachable; |
| ... | @@ -990,18 +994,14 @@ pub const CompileErrorContext = struct { | ... | @@ -990,18 +994,14 @@ pub const CompileErrorContext = struct { |
| 990 | if (self.test_filter) |filter| { | 994 | if (self.test_filter) |filter| { |
| 991 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; | 995 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 992 | } | 996 | } |
| 993 | | 997 | const write_src = b.addWriteFiles(); |
| 994 | const compile_and_cmp_errors = CompileCmpOutputStep.create(self, annotated_case_name, case, .Debug); | | |
| 995 | self.step.dependOn(&compile_and_cmp_errors.step); | | |
| 996 | | | |
| 997 | for (case.sources.toSliceConst()) |src_file| { | 998 | for (case.sources.toSliceConst()) |src_file| { |
| 998 | const expanded_src_path = fs.path.join( | 999 | write_src.add(src_file.filename, src_file.source); |
| 999 | b.allocator, | | |
| 1000 | &[_][]const u8{ b.cache_root, src_file.filename }, | | |
| 1001 | ) catch unreachable; | | |
| 1002 | const write_src = b.addWriteFile(expanded_src_path, src_file.source); | | |
| 1003 | compile_and_cmp_errors.step.dependOn(&write_src.step); | | |
| 1004 | } | 1000 | } |
| | 1001 | |
| | 1002 | const compile_and_cmp_errors = CompileCmpOutputStep.create(self, annotated_case_name, case, .Debug, write_src); |
| | 1003 | compile_and_cmp_errors.step.dependOn(&write_src.step); |
| | 1004 | self.step.dependOn(&compile_and_cmp_errors.step); |
| 1005 | } | 1005 | } |
| 1006 | }; | 1006 | }; |
| 1007 | | 1007 | |
| ... | @@ -1195,10 +1195,6 @@ pub const GenHContext = struct { | ... | @@ -1195,10 +1195,6 @@ pub const GenHContext = struct { |
| 1195 | | 1195 | |
| 1196 | pub fn addCase(self: *GenHContext, case: *const TestCase) void { | 1196 | pub fn addCase(self: *GenHContext, case: *const TestCase) void { |
| 1197 | const b = self.b; | 1197 | const b = self.b; |
| 1198 | const root_src = fs.path.join( | | |
| 1199 | b.allocator, | | |
| 1200 | &[_][]const u8{ b.cache_root, case.sources.items[0].filename }, | | |
| 1201 | ) catch unreachable; | | |
| 1202 | | 1198 | |
| 1203 | const mode = builtin.Mode.Debug; | 1199 | const mode = builtin.Mode.Debug; |
| 1204 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {} ({})", .{ case.name, @tagName(mode) }) catch unreachable; | 1200 | const annotated_case_name = fmt.allocPrint(self.b.allocator, "gen-h {} ({})", .{ case.name, @tagName(mode) }) catch unreachable; |
| ... | @@ -1206,18 +1202,14 @@ pub const GenHContext = struct { | ... | @@ -1206,18 +1202,14 @@ pub const GenHContext = struct { |
| 1206 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; | 1202 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 1207 | } | 1203 | } |
| 1208 | | 1204 | |
| 1209 | const obj = b.addObject("test", root_src); | 1205 | const write_src = b.addWriteFiles(); |
| 1210 | obj.setBuildMode(mode); | | |
| 1211 | | | |
| 1212 | for (case.sources.toSliceConst()) |src_file| { | 1206 | for (case.sources.toSliceConst()) |src_file| { |
| 1213 | const expanded_src_path = fs.path.join( | 1207 | write_src.add(src_file.filename, src_file.source); |
| 1214 | b.allocator, | | |
| 1215 | &[_][]const u8{ b.cache_root, src_file.filename }, | | |
| 1216 | ) catch unreachable; | | |
| 1217 | const write_src = b.addWriteFile(expanded_src_path, src_file.source); | | |
| 1218 | obj.step.dependOn(&write_src.step); | | |
| 1219 | } | 1208 | } |
| 1220 | | 1209 | |
| | 1210 | const obj = b.addObjectFromWriteFileStep("test", write_src, case.sources.items[0].filename); |
| | 1211 | obj.setBuildMode(mode); |
| | 1212 | |
| 1221 | const cmp_h = GenHCmpOutputStep.create(self, obj, annotated_case_name, case); | 1213 | const cmp_h = GenHCmpOutputStep.create(self, obj, annotated_case_name, case); |
| 1222 | | 1214 | |
| 1223 | self.step.dependOn(&cmp_h.step); | 1215 | self.step.dependOn(&cmp_h.step); |