authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-20 20:56:53+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-21 19:13:26+01:00
log4f437e4d2450dd2aca719ec0dcafa5aed141ca01
treee4b674f42a183657455007bf2cb55def54f73fcb
parent7bbbbf8ffa3fa9be085cef8e8237cd94ce342483
signaturelock-open Commit is signed but in an unrecognized format.

translate-c: populate file system inputs on error

Resolves: #20648

1 files changed, 31 insertions(+), 14 deletions(-)

src/main.zig+31-14
......@@ -4526,7 +4526,12 @@ fn cmdTranslateC(
45264526 Compilation.dump_argv(argv.items);
45274527 }
45284528
4529 const formatted = switch (comp.config.c_frontend) {
4529 const Result = union(enum) {
4530 success: []const u8,
4531 error_bundle: std.zig.ErrorBundle,
4532 };
4533
4534 const result: Result = switch (comp.config.c_frontend) {
45304535 .aro => f: {
45314536 var stdout: []u8 = undefined;
45324537 try jitCmd(comp.gpa, arena, argv.items, .{
......@@ -4536,7 +4541,7 @@ fn cmdTranslateC(
45364541 .capture = &stdout,
45374542 .progress_node = prog_node,
45384543 });
4539 break :f stdout;
4544 break :f .{ .success = stdout };
45404545 },
45414546 .clang => f: {
45424547 if (!build_options.have_llvm) unreachable;
......@@ -4564,31 +4569,43 @@ fn cmdTranslateC(
45644569 c_headers_dir_path_z,
45654570 ) catch |err| switch (err) {
45664571 error.OutOfMemory => return error.OutOfMemory,
4567 error.SemanticAnalyzeFail => {
4568 if (fancy_output) |p| {
4569 p.errors = errors;
4570 return;
4571 } else {
4572 errors.renderToStdErr(color.renderOptions());
4573 process.exit(1);
4574 }
4575 },
4572 error.SemanticAnalyzeFail => break :f .{ .error_bundle = errors },
45764573 };
45774574 defer tree.deinit(comp.gpa);
4578 break :f try tree.render(arena);
4575 break :f .{ .success = try tree.render(arena) };
45794576 },
45804577 };
45814578
4582 if (out_dep_path) |dep_file_path| {
4579 if (out_dep_path) |dep_file_path| add_deps: {
45834580 const dep_basename = fs.path.basename(dep_file_path);
45844581 // Add the files depended on to the cache system.
4585 try man.addDepFilePost(zig_cache_tmp_dir, dep_basename);
4582 man.addDepFilePost(zig_cache_tmp_dir, dep_basename) catch |err| switch (err) {
4583 error.FileNotFound => {
4584 // Clang didn't emit the dep file; nothing to add to the manifest.
4585 break :add_deps;
4586 },
4587 else => |e| return e,
4588 };
45864589 // Just to save disk space, we delete the file because it is never needed again.
45874590 zig_cache_tmp_dir.deleteFile(dep_basename) catch |err| {
45884591 warn("failed to delete '{s}': {s}", .{ dep_file_path, @errorName(err) });
45894592 };
45904593 }
45914594
4595 const formatted = switch (result) {
4596 .success => |formatted| formatted,
4597 .error_bundle => |eb| {
4598 if (file_system_inputs) |buf| try man.populateFileSystemInputs(buf);
4599 if (fancy_output) |p| {
4600 p.errors = eb;
4601 return;
4602 } else {
4603 eb.renderToStdErr(color.renderOptions());
4604 process.exit(1);
4605 }
4606 },
4607 };
4608
45924609 const bin_digest = man.finalBin();
45934610 const hex_digest = Cache.binToHex(bin_digest);
45944611