authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-07 13:40:17-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-07 13:40:17-05:00
log4e4ba6c3e1273fda8137f9f7e26325051f92bfa4
tree107702f4e31526b19e103c35ef0940dafc8cad4e
parent2933a8241a54af436f2df5eac73aa2acf5eabd40
signaturelock-open Commit is signed but in an unrecognized format.

test harness: show annotated case name when translate-c test fails


4 files changed, 15 insertions(+), 4 deletions(-)

lib/std/build.zig+9-2
...@@ -957,7 +957,7 @@ pub const Builder = struct {...@@ -957,7 +957,7 @@ pub const Builder = struct {
957 }957 }
958 }958 }
959959
960 pub fn exec(self: *Builder, argv: []const []const u8) ![]u8 {960 pub fn execFromStep(self: *Builder, argv: []const []const u8, src_step: ?*Step) ![]u8 {
961 assert(argv.len != 0);961 assert(argv.len != 0);
962962
963 if (self.verbose) {963 if (self.verbose) {
...@@ -967,16 +967,19 @@ pub const Builder = struct {...@@ -967,16 +967,19 @@ pub const Builder = struct {
967 var code: u8 = undefined;967 var code: u8 = undefined;
968 return self.execAllowFail(argv, &code, .Inherit) catch |err| switch (err) {968 return self.execAllowFail(argv, &code, .Inherit) catch |err| switch (err) {
969 error.FileNotFound => {969 error.FileNotFound => {
970 if (src_step) |s| warn("{}...", .{s.name});
970 warn("Unable to spawn the following command: file not found\n", .{});971 warn("Unable to spawn the following command: file not found\n", .{});
971 printCmd(null, argv);972 printCmd(null, argv);
972 std.os.exit(@truncate(u8, code));973 std.os.exit(@truncate(u8, code));
973 },974 },
974 error.ExitCodeFailure => {975 error.ExitCodeFailure => {
976 if (src_step) |s| warn("{}...", .{s.name});
975 warn("The following command exited with error code {}:\n", .{code});977 warn("The following command exited with error code {}:\n", .{code});
976 printCmd(null, argv);978 printCmd(null, argv);
977 std.os.exit(@truncate(u8, code));979 std.os.exit(@truncate(u8, code));
978 },980 },
979 error.ProcessTerminated => {981 error.ProcessTerminated => {
982 if (src_step) |s| warn("{}...", .{s.name});
980 warn("The following command terminated unexpectedly:\n", .{});983 warn("The following command terminated unexpectedly:\n", .{});
981 printCmd(null, argv);984 printCmd(null, argv);
982 std.os.exit(@truncate(u8, code));985 std.os.exit(@truncate(u8, code));
...@@ -985,6 +988,10 @@ pub const Builder = struct {...@@ -985,6 +988,10 @@ pub const Builder = struct {
985 };988 };
986 }989 }
987990
991 pub fn exec(self: *Builder, argv: []const []const u8) ![]u8 {
992 return self.execFromStep(argv, null);
993 }
994
988 pub fn addSearchPrefix(self: *Builder, search_prefix: []const u8) void {995 pub fn addSearchPrefix(self: *Builder, search_prefix: []const u8) void {
989 self.search_prefixes.append(search_prefix) catch unreachable;996 self.search_prefixes.append(search_prefix) catch unreachable;
990 }997 }
...@@ -2133,7 +2140,7 @@ pub const LibExeObjStep = struct {...@@ -2133,7 +2140,7 @@ pub const LibExeObjStep = struct {
2133 try zig_args.append("--cache");2140 try zig_args.append("--cache");
2134 try zig_args.append("on");2141 try zig_args.append("on");
21352142
2136 const output_path_nl = try builder.exec(zig_args.toSliceConst());2143 const output_path_nl = try builder.execFromStep(zig_args.toSliceConst(), &self.step);
2137 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");2144 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");
21382145
2139 if (self.output_dir) |output_dir| {2146 if (self.output_dir) |output_dir| {
lib/std/build/translate_c.zig+2-2
...@@ -19,7 +19,7 @@ pub const TranslateCStep = struct {...@@ -19,7 +19,7 @@ pub const TranslateCStep = struct {
19 pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep {19 pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep {
20 const self = builder.allocator.create(TranslateCStep) catch unreachable;20 const self = builder.allocator.create(TranslateCStep) catch unreachable;
21 self.* = TranslateCStep{21 self.* = TranslateCStep{
22 .step = Step.init("zig translate-c", builder.allocator, make),22 .step = Step.init("translate-c", builder.allocator, make),
23 .builder = builder,23 .builder = builder,
24 .source = source,24 .source = source,
25 .output_dir = null,25 .output_dir = null,
...@@ -73,7 +73,7 @@ pub const TranslateCStep = struct {...@@ -73,7 +73,7 @@ pub const TranslateCStep = struct {
7373
74 try argv_list.append(self.source.getPath(self.builder));74 try argv_list.append(self.source.getPath(self.builder));
7575
76 const output_path_nl = try self.builder.exec(argv_list.toSliceConst());76 const output_path_nl = try self.builder.execFromStep(argv_list.toSliceConst(), &self.step);
77 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");77 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");
7878
79 self.out_basename = fs.path.basename(output_path);79 self.out_basename = fs.path.basename(output_path);
test/src/run_translated_c.zig+3
...@@ -91,9 +91,12 @@ pub const RunTranslatedCContext = struct {...@@ -91,9 +91,12 @@ pub const RunTranslatedCContext = struct {
91 .basename = case.sources.toSliceConst()[0].filename,91 .basename = case.sources.toSliceConst()[0].filename,
92 },92 },
93 });93 });
94 translate_c.step.name = b.fmt("{} translate-c", .{annotated_case_name});
94 const exe = translate_c.addExecutable();95 const exe = translate_c.addExecutable();
96 exe.step.name = b.fmt("{} build-exe", .{annotated_case_name});
95 exe.linkLibC();97 exe.linkLibC();
96 const run = exe.run();98 const run = exe.run();
99 run.step.name = b.fmt("{} run", .{annotated_case_name});
97 if (!case.allow_warnings) {100 if (!case.allow_warnings) {
98 run.expectStdErrEqual("");101 run.expectStdErrEqual("");
99 }102 }
test/src/translate_c.zig+1
...@@ -114,6 +114,7 @@ pub const TranslateCContext = struct {...@@ -114,6 +114,7 @@ pub const TranslateCContext = struct {
114 .basename = case.sources.toSliceConst()[0].filename,114 .basename = case.sources.toSliceConst()[0].filename,
115 },115 },
116 });116 });
117 translate_c.step.name = annotated_case_name;
117 translate_c.setTarget(case.target);118 translate_c.setTarget(case.target);
118119
119 const check_file = translate_c.addCheckFile(case.expected_lines.toSliceConst());120 const check_file = translate_c.addCheckFile(case.expected_lines.toSliceConst());