mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
std.Build: factorize Step stack trace dumping code
This commit is contained in:
parent
078e330555
commit
f43402f883
@ -1768,49 +1768,21 @@ pub fn dumpBadGetPathHelp(
|
||||
});
|
||||
|
||||
const tty_config = std.io.tty.detectConfig(stderr);
|
||||
if (s.getStackTrace()) |stack_trace| {
|
||||
tty_config.setColor(w, .red) catch {};
|
||||
try stderr.writeAll(" The step was created by this stack trace:\n");
|
||||
tty_config.setColor(w, .reset) catch {};
|
||||
|
||||
s.dump(stderr);
|
||||
if (asking_step) |as| {
|
||||
tty_config.setColor(w, .red) catch {};
|
||||
try stderr.writeAll(" The step was created by this stack trace:\n");
|
||||
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});
|
||||
tty_config.setColor(w, .reset) catch {};
|
||||
|
||||
const debug_info = std.debug.getSelfDebugInfo() catch |err| {
|
||||
try w.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)});
|
||||
return;
|
||||
};
|
||||
const ally = debug_info.allocator;
|
||||
|
||||
std.debug.writeStackTrace(stack_trace, w, ally, debug_info, tty_config) catch |err| {
|
||||
try stderr.writer().print("Unable to dump stack trace: {s}\n", .{@errorName(err)});
|
||||
return;
|
||||
};
|
||||
if (asking_step) |as| {
|
||||
tty_config.setColor(w, .red) catch {};
|
||||
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});
|
||||
tty_config.setColor(w, .reset) catch {};
|
||||
|
||||
if (as.getStackTrace()) |as_stack_trace| {
|
||||
std.debug.writeStackTrace(as_stack_trace, w, ally, debug_info, tty_config) catch |err| {
|
||||
try stderr.writer().print("Unable to dump stack trace: {s}\n", .{@errorName(err)});
|
||||
return;
|
||||
};
|
||||
} else {
|
||||
const field = "debug_stack_frames_count";
|
||||
comptime assert(@hasField(Build, field));
|
||||
tty_config.setColor(w, .yellow) catch {};
|
||||
try stderr.writer().print("no stack trace collected for this step, see std.Build." ++ field ++ "\n", .{});
|
||||
tty_config.setColor(w, .reset) catch {};
|
||||
}
|
||||
}
|
||||
tty_config.setColor(w, .red) catch {};
|
||||
try stderr.writeAll(" Hope that helps. Proceeding to panic.\n");
|
||||
tty_config.setColor(w, .reset) catch {};
|
||||
} else {
|
||||
const field = "debug_stack_frames_count";
|
||||
comptime assert(@hasField(Build, field));
|
||||
tty_config.setColor(w, .yellow) catch {};
|
||||
try stderr.writer().print("no stack trace collected for this step, see std.Build." ++ field ++ "\n", .{});
|
||||
tty_config.setColor(w, .reset) catch {};
|
||||
as.dump(stderr);
|
||||
}
|
||||
tty_config.setColor(w, .red) catch {};
|
||||
try stderr.writeAll(" Hope that helps. Proceeding to panic.\n");
|
||||
tty_config.setColor(w, .reset) catch {};
|
||||
}
|
||||
|
||||
/// Allocates a new string for assigning a value to a named macro.
|
||||
|
||||
@ -231,13 +231,9 @@ pub fn cast(step: *Step, comptime T: type) ?*T {
|
||||
}
|
||||
|
||||
/// For debugging purposes, prints identifying information about this Step.
|
||||
pub fn dump(step: *Step) void {
|
||||
std.debug.getStderrMutex().lock();
|
||||
defer std.debug.getStderrMutex().unlock();
|
||||
|
||||
const stderr = std.io.getStdErr();
|
||||
const w = stderr.writer();
|
||||
const tty_config = std.io.tty.detectConfig(stderr);
|
||||
pub fn dump(step: *Step, file: std.fs.File) void {
|
||||
const w = file.writer();
|
||||
const tty_config = std.io.tty.detectConfig(file);
|
||||
const debug_info = std.debug.getSelfDebugInfo() catch |err| {
|
||||
w.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{
|
||||
@errorName(err),
|
||||
@ -248,7 +244,7 @@ pub fn dump(step: *Step) void {
|
||||
if (step.getStackTrace()) |stack_trace| {
|
||||
w.print("name: '{s}'. creation stack trace:\n", .{step.name}) catch {};
|
||||
std.debug.writeStackTrace(stack_trace, w, ally, debug_info, tty_config) catch |err| {
|
||||
stderr.writer().print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch {};
|
||||
w.print("Unable to dump stack trace: {s}\n", .{@errorName(err)}) catch {};
|
||||
return;
|
||||
};
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user