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 {
957957 }
958958 }
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 {
961961 assert(argv.len != 0);
962962
963963 if (self.verbose) {
......@@ -967,16 +967,19 @@ pub const Builder = struct {
967967 var code: u8 = undefined;
968968 return self.execAllowFail(argv, &code, .Inherit) catch |err| switch (err) {
969969 error.FileNotFound => {
970 if (src_step) |s| warn("{}...", .{s.name});
970971 warn("Unable to spawn the following command: file not found\n", .{});
971972 printCmd(null, argv);
972973 std.os.exit(@truncate(u8, code));
973974 },
974975 error.ExitCodeFailure => {
976 if (src_step) |s| warn("{}...", .{s.name});
975977 warn("The following command exited with error code {}:\n", .{code});
976978 printCmd(null, argv);
977979 std.os.exit(@truncate(u8, code));
978980 },
979981 error.ProcessTerminated => {
982 if (src_step) |s| warn("{}...", .{s.name});
980983 warn("The following command terminated unexpectedly:\n", .{});
981984 printCmd(null, argv);
982985 std.os.exit(@truncate(u8, code));
......@@ -985,6 +988,10 @@ pub const Builder = struct {
985988 };
986989 }
987990
991 pub fn exec(self: *Builder, argv: []const []const u8) ![]u8 {
992 return self.execFromStep(argv, null);
993 }
994
988995 pub fn addSearchPrefix(self: *Builder, search_prefix: []const u8) void {
989996 self.search_prefixes.append(search_prefix) catch unreachable;
990997 }
......@@ -2133,7 +2140,7 @@ pub const LibExeObjStep = struct {
21332140 try zig_args.append("--cache");
21342141 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);
21372144 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");
21382145
21392146 if (self.output_dir) |output_dir| {
lib/std/build/translate_c.zig+2-2
......@@ -19,7 +19,7 @@ pub const TranslateCStep = struct {
1919 pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep {
2020 const self = builder.allocator.create(TranslateCStep) catch unreachable;
2121 self.* = TranslateCStep{
22 .step = Step.init("zig translate-c", builder.allocator, make),
22 .step = Step.init("translate-c", builder.allocator, make),
2323 .builder = builder,
2424 .source = source,
2525 .output_dir = null,
......@@ -73,7 +73,7 @@ pub const TranslateCStep = struct {
7373
7474 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);
7777 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");
7878
7979 self.out_basename = fs.path.basename(output_path);
test/src/run_translated_c.zig+3
......@@ -91,9 +91,12 @@ pub const RunTranslatedCContext = struct {
9191 .basename = case.sources.toSliceConst()[0].filename,
9292 },
9393 });
94 translate_c.step.name = b.fmt("{} translate-c", .{annotated_case_name});
9495 const exe = translate_c.addExecutable();
96 exe.step.name = b.fmt("{} build-exe", .{annotated_case_name});
9597 exe.linkLibC();
9698 const run = exe.run();
99 run.step.name = b.fmt("{} run", .{annotated_case_name});
97100 if (!case.allow_warnings) {
98101 run.expectStdErrEqual("");
99102 }
test/src/translate_c.zig+1
......@@ -114,6 +114,7 @@ pub const TranslateCContext = struct {
114114 .basename = case.sources.toSliceConst()[0].filename,
115115 },
116116 });
117 translate_c.step.name = annotated_case_name;
117118 translate_c.setTarget(case.target);
118119
119120 const check_file = translate_c.addCheckFile(case.expected_lines.toSliceConst());