authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-05 13:08:18-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-05 13:08:18-05:00
log242f5d10d57eb9239e7a89d4e705fc05785abe7c
treec941946f8f5aa09dbc71a4f9761b1127508f9e13
parent157b8e68894df4b4497f9caa5275dc4d22b0efca
signature Commit is signed but in an unrecognized format.

fix test-gen-h and test-compile-errors regression


2 files changed, 36 insertions(+), 30 deletions(-)

lib/std/build.zig+14
...@@ -242,6 +242,20 @@ pub const Builder = struct {...@@ -242,6 +242,20 @@ pub const Builder = struct {
242 return LibExeObjStep.createObject(self, name, root_src_param);242 return LibExeObjStep.createObject(self, name, root_src_param);
243 }243 }
244244
245 pub fn addObjectFromWriteFileStep(
246 self: *Builder,
247 name: []const u8,
248 wfs: *WriteFileStep,
249 basename: []const u8,
250 ) *LibExeObjStep {
251 return LibExeObjStep.createObject(self, name, @as(FileSource, .{
252 .write_file = .{
253 .step = wfs,
254 .basename = basename,
255 },
256 }));
257 }
258
245 pub fn addSharedLibrary(self: *Builder, name: []const u8, root_src: ?[]const u8, ver: Version) *LibExeObjStep {259 pub fn addSharedLibrary(self: *Builder, name: []const u8, root_src: ?[]const u8, ver: Version) *LibExeObjStep {
246 const root_src_param = if (root_src) |p| @as(FileSource, .{ .path = p }) else null;260 const root_src_param = if (root_src) |p| @as(FileSource, .{ .path = p }) else null;
247 return LibExeObjStep.createSharedLibrary(self, name, root_src_param, ver);261 return LibExeObjStep.createSharedLibrary(self, name, root_src_param, ver);
test/tests.zig+22-30
...@@ -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,
740741
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 };
758759
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 };
770778
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;
778786
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;
786789
...@@ -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));
795799
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 }
993997 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};
10071007
...@@ -1195,10 +1195,6 @@ pub const GenHContext = struct {...@@ -1195,10 +1195,6 @@ pub const GenHContext = struct {
11951195
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;
12021198
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 }
12081204
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 }
12201209
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);
12221214
1223 self.step.dependOn(&cmp_h.step);1215 self.step.dependOn(&cmp_h.step);