[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 06:53:28 PDT 2025


================
@@ -12,6 +12,57 @@
     "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
+        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: subcommand failed"
+            )
+            and len(failure_log) < NINJA_LOG_SIZE_THRESHOLD
+        ):
+            failure_log.append(ninja_log[index])
+            index += 1
+        failures.append((failing_action, "\n".join(failure_log)))
+    return failures
+
+
+def find_failure_in_ninja_logs(ninja_logs: list[list[str]]) -> list[tuple[str, str]]:
+    """Extracts failure messages from ninja output.
+
+    This patch takes stdout/stderr from ninja in the form of a list of files
----------------
boomanaiden154 wrote:

Just a docstring, so aimed at developer documentation. Thanks for the catch.

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


More information about the llvm-commits mailing list