[llvm] [CI] Add Support for Parsing Ninja Logs to generate_test_report_lib (PR #152620)
David Spickett via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 8 08:03:56 PDT 2025
================
@@ -12,6 +12,65 @@
"https://github.com/llvm/llvm-project/issues and add the "
"`infrastructure` label."
)
+# The maximum number of lines to pull from a ninja failure.
+NINJA_LOG_SIZE_THRESHOLD = 500
+
+
+def _parse_ninja_log(ninja_log: list[str]) -> list[tuple[str, str]]:
+ """Parses an individual ninja log."""
+ failures = []
+ index = 0
+ while index < len(ninja_log):
+ while index < len(ninja_log) and not ninja_log[index].startswith("FAILED:"):
+ index += 1
+ if index == len(ninja_log):
+ # We hit the end of the log without finding a build failure, go to
+ # the next log.
+ return failures
+ # We are trying to parse cases like the following:
+ #
+ # [4/5] test/4.stamp
+ # FAILED: touch test/4.stamp
+ # touch test/4.stamp
+ #
+ # index will point to the line that starts with Failed:. The progress
+ # indicator is the line before this ([4/5] test/4.stamp) and contains a pretty
+ # printed version of the target being built (test/4.stamp). We use this line
+ # and remove the progress information to get a succinct name for the target.
+ failing_action = ninja_log[index - 1].split("] ")[1]
+ failure_log = []
+ while (
+ index < len(ninja_log)
+ and not ninja_log[index].startswith("[")
+ and not ninja_log[index].startswith("ninja: build stopped:")
+ and len(failure_log) < NINJA_LOG_SIZE_THRESHOLD
----------------
DavidSpickett wrote:
Having a threshold is a good idea, I definitely would have forgotten to do that.
If it hits the threshold, should there be some indicator that it has done so? We hope the useful bit of the error is in the first 500 lines, but for the rare cases, maybe:
```
<output truncated, download the log file to see the rest>
```
As the very last line?
This will ruin your neat while loop though so you can do it as a follow up if you agree it's good to have.
https://github.com/llvm/llvm-project/pull/152620
More information about the llvm-commits
mailing list