[llvm] [CI] Add Support for Parsing Ninja Logs to generate_test_report_lib (PR #152620)

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 8 08:14:22 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
----------------
boomanaiden154 wrote:

Probably good to have. I don't think it would be too hard to implement (we can check if we hit `NINJA_LOG_SIZE_THRESHOLD` after the loop). I'll put it on the TODO list and look at doing it as a follow up.

I expect to hit this case pretty rarely though.

https://github.com/llvm/llvm-project/pull/152620


More information about the llvm-commits mailing list