Human-readable rendering. Empty sections collapse to a one-liner.
(report: DriftReport)
| 360 | |
| 361 | |
| 362 | def render_report(report: DriftReport) -> str: |
| 363 | """Human-readable rendering. Empty sections collapse to a one-liner.""" |
| 364 | lines: list[str] = [] |
| 365 | header = f"Backend flag-drift report for {report.board!r}" |
| 366 | lines.append(header) |
| 367 | lines.append("=" * len(header)) |
| 368 | lines.append("") |
| 369 | |
| 370 | sections = [ |
| 371 | ("cc_flags", report.cc_only_in_fbuild, report.cc_only_in_pio), |
| 372 | ("cxx_flags", report.cxx_only_in_fbuild, report.cxx_only_in_pio), |
| 373 | ("defines", report.defines_only_in_fbuild, report.defines_only_in_pio), |
| 374 | ("includes", report.includes_only_in_fbuild, report.includes_only_in_pio), |
| 375 | ] |
| 376 | |
| 377 | for name, only_fbuild, only_pio in sections: |
| 378 | if not only_fbuild and not only_pio: |
| 379 | lines.append(f" [{name}] OK (no drift)") |
| 380 | continue |
| 381 | lines.append(f" [{name}] drift:") |
| 382 | for f in only_fbuild: |
| 383 | lines.append(f" + (fbuild only) {f}") |
| 384 | for f in only_pio: |
| 385 | lines.append(f" - (pio only) {f}") |
| 386 | |
| 387 | lines.append("") |
| 388 | lines.append("VERDICT: DRIFT DETECTED" if report.has_drift() else "VERDICT: clean") |
| 389 | return "\n".join(lines) |
| 390 | |
| 391 | |
| 392 | # --------------------------------------------------------------------------- |