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 {
242242 return LibExeObjStep.createObject(self, name, root_src_param);
243243 }
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
245259 pub fn addSharedLibrary(self: *Builder, name: []const u8, root_src: ?[]const u8, ver: Version) *LibExeObjStep {
246260 const root_src_param = if (root_src) |p| @as(FileSource, .{ .path = p }) else null;
247261 return LibExeObjStep.createSharedLibrary(self, name, root_src_param, ver);
test/tests.zig+22-30
......@@ -737,6 +737,7 @@ pub const CompileErrorContext = struct {
737737 test_index: usize,
738738 case: *const TestCase,
739739 build_mode: Mode,
740 write_src: *build.WriteFileStep,
740741
741742 const ErrLineIter = struct {
742743 lines: mem.SplitIterator,
......@@ -756,7 +757,13 @@ pub const CompileErrorContext = struct {
756757 }
757758 };
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 {
760767 const allocator = context.b.allocator;
761768 const ptr = allocator.create(CompileCmpOutputStep) catch unreachable;
762769 ptr.* = CompileCmpOutputStep{
......@@ -766,6 +773,7 @@ pub const CompileErrorContext = struct {
766773 .test_index = context.test_index,
767774 .case = case,
768775 .build_mode = build_mode,
776 .write_src = write_src,
769777 };
770778
771779 context.test_index += 1;
......@@ -776,11 +784,6 @@ pub const CompileErrorContext = struct {
776784 const self = @fieldParentPtr(CompileCmpOutputStep, "step", step);
777785 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
784787 var zig_args = ArrayList([]const u8).init(b.allocator);
785788 zig_args.append(b.zig_exe) catch unreachable;
786789
......@@ -791,7 +794,8 @@ pub const CompileErrorContext = struct {
791794 } else {
792795 try zig_args.append("build-obj");
793796 }
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
796800 zig_args.append("--name") catch unreachable;
797801 zig_args.append("test") catch unreachable;
......@@ -990,18 +994,14 @@ pub const CompileErrorContext = struct {
990994 if (self.test_filter) |filter| {
991995 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
992996 }
993
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 const write_src = b.addWriteFiles();
997998 for (case.sources.toSliceConst()) |src_file| {
998 const expanded_src_path = fs.path.join(
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);
999 write_src.add(src_file.filename, src_file.source);
10041000 }
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);
10051005 }
10061006};
10071007
......@@ -1195,10 +1195,6 @@ pub const GenHContext = struct {
11951195
11961196 pub fn addCase(self: *GenHContext, case: *const TestCase) void {
11971197 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
12031199 const mode = builtin.Mode.Debug;
12041200 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 {
12061202 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
12071203 }
12081204
1209 const obj = b.addObject("test", root_src);
1210 obj.setBuildMode(mode);
1211
1205 const write_src = b.addWriteFiles();
12121206 for (case.sources.toSliceConst()) |src_file| {
1213 const expanded_src_path = fs.path.join(
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);
1207 write_src.add(src_file.filename, src_file.source);
12191208 }
12201209
1210 const obj = b.addObjectFromWriteFileStep("test", write_src, case.sources.items[0].filename);
1211 obj.setBuildMode(mode);
1212
12211213 const cmp_h = GenHCmpOutputStep.create(self, obj, annotated_case_name, case);
12221214
12231215 self.step.dependOn(&cmp_h.step);