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(...@@ -1768,49 +1768,21 @@ pub fn dumpBadGetPathHelp(
1768 });1768 });
17691769
1770 const tty_config = std.io.tty.detectConfig(stderr);1770 const tty_config = std.io.tty.detectConfig(stderr);
1771 if (s.getStackTrace()) |stack_trace| {1771 tty_config.setColor(w, .red) catch {};
1772 tty_config.setColor(w, .red) catch {};1772 try stderr.writeAll(" The step was created by this stack trace:\n");
1773 try stderr.writeAll(" The step was created by this stack trace:\n");1773 tty_config.setColor(w, .reset) catch {};
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;
17811774
1782 std.debug.writeStackTrace(stack_trace, w, ally, debug_info, tty_config) catch |err| {1775 s.dump(stderr);
1783 try stderr.writer().print("Unable to dump stack trace: {s}\n", .{@errorName(err)});1776 if (asking_step) |as| {
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 }
1804 tty_config.setColor(w, .red) catch {};1777 tty_config.setColor(w, .red) catch {};
1805 try stderr.writeAll(" Hope that helps. Proceeding to panic.\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});
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", .{});
1812 tty_config.setColor(w, .reset) catch {};1779 tty_config.setColor(w, .reset) catch {};
1780
1781 as.dump(stderr);
1813 }1782 }
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 {};
1814}1786}
18151787
1816/// Allocates a new string for assigning a value to a named macro.1788/// 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 {...@@ -231,13 +231,9 @@ pub fn cast(step: *Step, comptime T: type) ?*T {
231}231}
232232
233/// For debugging purposes, prints identifying information about this Step.233/// For debugging purposes, prints identifying information about this Step.
234pub fn dump(step: *Step) void {234pub fn dump(step: *Step, file: std.fs.File) void {
235 std.debug.getStderrMutex().lock();235 const w = file.writer();
236 defer std.debug.getStderrMutex().unlock();236 const tty_config = std.io.tty.detectConfig(file);
237
238 const stderr = std.io.getStdErr();
239 const w = stderr.writer();
240 const tty_config = std.io.tty.detectConfig(stderr);
241 const debug_info = std.debug.getSelfDebugInfo() catch |err| {237 const debug_info = std.debug.getSelfDebugInfo() catch |err| {
242 w.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{238 w.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{
243 @errorName(err),239 @errorName(err),
...@@ -248,7 +244,7 @@ pub fn dump(step: *Step) void {...@@ -248,7 +244,7 @@ pub fn dump(step: *Step) void {
248 if (step.getStackTrace()) |stack_trace| {244 if (step.getStackTrace()) |stack_trace| {
249 w.print("name: '{s}'. creation stack trace:\n", .{step.name}) catch {};245 w.print("name: '{s}'. creation stack trace:\n", .{step.name}) catch {};
250 std.debug.writeStackTrace(stack_trace, w, ally, debug_info, tty_config) catch |err| {246 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 {};
252 return;248 return;
253 };249 };
254 } else {250 } else {