authorgravatar for sahnvour@pm.meSahnvour <sahnvour@pm.me> 2023-08-13 11:25:48+02:00
committergravatar for sahnvour@pm.meSahnvour <sahnvour@pm.me> 2023-08-13 11:25:48+02:00
logf43402f883bff6c1934c551b5cb29f70dac1b1b6
tree205f9c383a28ca96cde891a0d8f1370295282ca8
parent078e3305555f117efbaa83a91b2e79444847363c

std.Build: factorize Step stack trace dumping code


2 files changed, 15 insertions(+), 47 deletions(-)

lib/std/Build.zig+11-39
......@@ -1768,49 +1768,21 @@ pub fn dumpBadGetPathHelp(
17681768 });
17691769
17701770 const tty_config = std.io.tty.detectConfig(stderr);
1771 if (s.getStackTrace()) |stack_trace| {
1772 tty_config.setColor(w, .red) catch {};
1773 try stderr.writeAll(" The step was created by this stack trace:\n");
1774 tty_config.setColor(w, .reset) catch {};
1775
1776 const debug_info = std.debug.getSelfDebugInfo() catch |err| {
1777 try w.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)});
1778 return;
1779 };
1780 const ally = debug_info.allocator;
1771 tty_config.setColor(w, .red) catch {};
1772 try stderr.writeAll(" The step was created by this stack trace:\n");
1773 tty_config.setColor(w, .reset) catch {};
17811774
1782 std.debug.writeStackTrace(stack_trace, w, ally, debug_info, tty_config) catch |err| {
1783 try stderr.writer().print("Unable to dump stack trace: {s}\n", .{@errorName(err)});
1784 return;
1785 };
1786 if (asking_step) |as| {
1787 tty_config.setColor(w, .red) catch {};
1788 try stderr.writer().print(" The step '{s}' that is missing a dependency on the above step was created by this stack trace:\n", .{as.name});
1789 tty_config.setColor(w, .reset) catch {};
1790
1791 if (as.getStackTrace()) |as_stack_trace| {
1792 std.debug.writeStackTrace(as_stack_trace, w, ally, debug_info, tty_config) catch |err| {
1793 try stderr.writer().print("Unable to dump stack trace: {s}\n", .{@errorName(err)});
1794 return;
1795 };
1796 } else {
1797 const field = "debug_stack_frames_count";
1798 comptime assert(@hasField(Build, field));
1799 tty_config.setColor(w, .yellow) catch {};
1800 try stderr.writer().print("no stack trace collected for this step, see std.Build." ++ field ++ "\n", .{});
1801 tty_config.setColor(w, .reset) catch {};
1802 }
1803 }
1775 s.dump(stderr);
1776 if (asking_step) |as| {
18041777 tty_config.setColor(w, .red) catch {};
1805 try stderr.writeAll(" Hope that helps. Proceeding to panic.\n");
1806 tty_config.setColor(w, .reset) catch {};
1807 } else {
1808 const field = "debug_stack_frames_count";
1809 comptime assert(@hasField(Build, field));
1810 tty_config.setColor(w, .yellow) catch {};
1811 try stderr.writer().print("no stack trace collected for this step, see std.Build." ++ field ++ "\n", .{});
1778 try stderr.writer().print(" The step '{s}' that is missing a dependency on the above step was created by this stack trace:\n", .{as.name});
18121779 tty_config.setColor(w, .reset) catch {};
1780
1781 as.dump(stderr);
18131782 }
1783 tty_config.setColor(w, .red) catch {};
1784 try stderr.writeAll(" Hope that helps. Proceeding to panic.\n");
1785 tty_config.setColor(w, .reset) catch {};
18141786}
18151787
18161788/// Allocates a new string for assigning a value to a named macro.
lib/std/Build/Step.zig+4-8
......@@ -231,13 +231,9 @@ pub fn cast(step: *Step, comptime T: type) ?*T {
231231}
232232
233233/// For debugging purposes, prints identifying information about this Step.
234pub fn dump(step: *Step) void {
235 std.debug.getStderrMutex().lock();
236 defer std.debug.getStderrMutex().unlock();
237
238 const stderr = std.io.getStdErr();
239 const w = stderr.writer();
240 const tty_config = std.io.tty.detectConfig(stderr);
234pub fn dump(step: *Step, file: std.fs.File) void {
235 const w = file.writer();
236 const tty_config = std.io.tty.detectConfig(file);
241237 const debug_info = std.debug.getSelfDebugInfo() catch |err| {
242238 w.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{
243239 @errorName(err),
......@@ -248,7 +244,7 @@ pub fn dump(step: *Step) void {
248244 if (step.getStackTrace()) |stack_trace| {
249245 w.print("name: '{s}'. creation stack trace:\n", .{step.name}) catch {};
250246 std.debug.writeStackTrace(stack_trace, w, ally, debug_info, tty_config) catch |err| {
251 stderr.writer().print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch {};
247 w.print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch {};
252248 return;
253249 };
254250 } else {