diff mbox series

[bug#70031,core-updates,01/19] build-system/cmake: Parallelize tests using ctest.

Message ID cbc2309b5444207bb5805ca67241b572d545b104.1711549374.git.code@greghogan.com
State New
Headers show
Series Use CMake in build-system/cmake. | expand

Commit Message

Greg Hogan March 27, 2024, 2:52 p.m. UTC
* guix/build/cmake-build-system.scm (check): Replace call to gnu-build's
non-parallelizable check with an implementation using cmake's ctest.
---
 guix/build/cmake-build-system.scm | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/guix/build/cmake-build-system.scm b/guix/build/cmake-build-system.scm
index d1ff5071be5..ea342ff2ac9 100644
--- a/guix/build/cmake-build-system.scm
+++ b/guix/build/cmake-build-system.scm
@@ -23,6 +23,7 @@  (define-module (guix build cmake-build-system)
   #:use-module ((guix build gnu-build-system) #:prefix gnu:)
   #:use-module (guix build utils)
   #:use-module (ice-9 match)
+  #:use-module (srfi srfi-34)
   #:export (%standard-phases
             cmake-build))
 
@@ -77,12 +78,25 @@  (define* (configure #:key outputs (configure-flags '()) (out-of-source? #t)
       (format #t "running 'cmake' with arguments ~s~%" args)
       (apply invoke "cmake" args))))
 
-(define* (check #:key (tests? #t) (parallel-tests? #t) (test-target "test")
+(define %test-suite-log-regexp
+  ;; Name of test suite log files as commonly found in CMake.
+  "^LastTestFailed\\.log$")
+
+(define* (check #:key (tests? #t) (parallel-tests? #t)
+                (test-suite-log-regexp %test-suite-log-regexp)
                 #:allow-other-keys)
-  (let ((gnu-check (assoc-ref gnu:%standard-phases 'check)))
-    (setenv "CTEST_OUTPUT_ON_FAILURE" "1")
-    (gnu-check #:tests? tests? #:test-target test-target
-              #:parallel-tests? parallel-tests?)))
+  (if tests?
+      (guard (c ((invoke-error? c)
+                 ;; Dump the test suite log to facilitate debugging.
+                 (display "\nTest suite failed, dumping logs.\n"
+                          (current-error-port))
+                 (gnu:dump-file-contents "." test-suite-log-regexp)
+                 (raise c)))
+        (apply invoke "ctest" "--output-on-failure"
+               `(,@(if parallel-tests?
+                       `("-j" ,(number->string (parallel-job-count)))
+                       '()))))
+      (format #t "test suite not run~%")))
 
 (define %standard-phases
   ;; Everything is as with the GNU Build System except for the `configure'