Print the failure header + error excerpt + diagnostics for a failed compile.
(
*,
ctx: SequentialCompileContext,
last_result: Optional[CompileResult],
last_error_output: str,
has_fallbacks: bool,
targets_to_try: list[str],
all_suppressed_errors: list[str],
)
| 88 | |
| 89 | |
| 90 | def _print_compile_failure( |
| 91 | *, |
| 92 | ctx: SequentialCompileContext, |
| 93 | last_result: Optional[CompileResult], |
| 94 | last_error_output: str, |
| 95 | has_fallbacks: bool, |
| 96 | targets_to_try: list[str], |
| 97 | all_suppressed_errors: list[str], |
| 98 | ) -> None: |
| 99 | """Print the failure header + error excerpt + diagnostics for a failed compile.""" |
| 100 | last_error_file = ( |
| 101 | ctx.build_dir.parent / "meson-state" / "last-compilation-error.txt" |
| 102 | ) |
| 103 | phase_data = ctx.phase_tracker.get_phase() |
| 104 | phase_name = phase_data.get("phase", "COMPILE") if phase_data else "COMPILE" |
| 105 | |
| 106 | print_error(f"\n[MESON] ❌ Build FAILED during {phase_name} phase") |
| 107 | print_error("=" * 80) |
| 108 | |
| 109 | if last_result and last_result.error_log_file: |
| 110 | print_error(f"[MESON] 📄 Full compilation log:") |
| 111 | print_error(f"[MESON] {last_result.error_log_file}") |
| 112 | print_error("") |
| 113 | |
| 114 | error_snippet_shown = False |
| 115 | |
| 116 | if last_error_file.exists(): |
| 117 | with open(last_error_file, "r", encoding="utf-8") as f: |
| 118 | error_context = f.read() |
| 119 | for line in error_context.splitlines(): |
| 120 | if _is_compilation_error(line): |
| 121 | print_error(f"\033[91m{line}\033[0m") |
| 122 | else: |
| 123 | print_error(line) |
| 124 | error_snippet_shown = True |
| 125 | |
| 126 | elif ( |
| 127 | last_result |
| 128 | and last_result.error_log_file |
| 129 | and last_result.error_log_file.exists() |
| 130 | ): |
| 131 | print_error("[MESON] 🔍 Error excerpt from compilation log:") |
| 132 | print_error("") |
| 133 | try: |
| 134 | with open(last_result.error_log_file, "r", encoding="utf-8") as f: |
| 135 | log_lines = f.readlines() |
| 136 | error_lines = [ |
| 137 | (i, line.rstrip()) |
| 138 | for i, line in enumerate(log_lines) |
| 139 | if _is_compilation_error(line) |
| 140 | ] |
| 141 | if error_lines: |
| 142 | last_error_idx = error_lines[-1][0] |
| 143 | start_idx = max(0, last_error_idx - 5) |
| 144 | end_idx = min(len(log_lines), last_error_idx + 5) |
| 145 | for line in log_lines[start_idx:end_idx]: |
| 146 | line = line.rstrip() |
| 147 | if _is_compilation_error(line): |
no test coverage detected