Subject: Re: bug#60640: Gnu: Add gdcm

From: Tor-björn Claesson <[email-masked]>
Date: Fri, 27 Jan 2023 17:06:37 +0200

Hi!

Ludovic Courtès <[email-masked]> writes:
>
> The following tests FAILED:
> 	195 - TestStrictScanner1 (Failed)
> 	196 - TestStrictScanner2_1 (Failed)
> 	197 - TestStrictScanner2 (Failed)
> 	198 - TestStrictScanner2_2 (Failed)
> Errors while running CTest
>
> Passing #:parallel-tests? #f doesn’t help.
>
> Could you take a look?

The TestStrictScanner tests fail because they expect TestWriter to have
run, but we disabled it.

TestWriter, TestAnonymizer4, and TestPrinter1 are also reported as
failing in the GDCM ctest dashboard
(https://open.cdash.org/index.php?project=GDCM).
It is strange that they passed previously in my local checkout
(they fail now, some change in the toolchain?)
I will try to look into this.

For now, here is a patch to ignore the remaining failures, giving us
an installable package, and also updated patches to add a bin output
and use more system libraries.

Investigating the remaining failing tests and using more system
libraries feels like a fairly big, if fun, task possibly involving
work on GDCM as well as this package. Should we close this bug report
if we have a working package when the attached patches are applied?

-- 
Mvh,
Tor-björn Claesson

>From 7aaae11c7efc38222bfbf503e52cdb15bfccc33c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tor-bj=C3=B6rn=20Claesson?= <[email-masked]>
Date: Fri, 27 Jan 2023 13:26:02 +0200
Subject: [PATCH 1/3] gnu: gdcm: Ignore remaining failing tests.
gnu: gdcm: Ignore remaining failing tests.
---
 gnu/packages/bioinformatics.scm | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/gnu/packages/bioinformatics.scm b/gnu/packages/bioinformatics.scm
index 8c75607a65..0fa7bb3746 100644
--- a/gnu/packages/bioinformatics.scm
+++ b/gnu/packages/bioinformatics.scm
@@ -18097,12 +18097,15 @@ (define-public gdcm
       #:configure-flags
       #~(list "-DGDCM_BUILD_TESTING=true"
               (string-append "-DCMAKE_CTEST_ARGUMENTS=-E;"
-                             "'TestFileMetaInformation"
-                             "|TestElement2"
-                             "|TestSCUValidation"
-                             "|TestWriter"
+                             "'TestWriter"
+                             "|TestStrictScanner1"
+			     "|TestStrictScanner2"
+			     "|TestStrictScanner2_1"
+			     "|TestStrictScanner2_2"
                              "|TestAnonymizer4"
                              "|TestPrinter1"
+                             ;; Disable tests that download data from the internet.
+                             "|TestSCUValidation"
                              "|TestEcho"
                              "|TestFind'")
               "-DGDCM_DOCUMENTATION:BOOL=ON"
-- 
2.39.1

>From 2bc5c46ca2fee406a7108e5d43ef66af2d392889 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tor-bj=C3=B6rn=20Claesson?= <[email-masked]>
Date: Fri, 27 Jan 2023 14:43:32 +0200
Subject: [PATCH 2/3] gnu: gdcm: Add bin output.
gnu: gdcm: Add bin output.
---
 gnu/packages/bioinformatics.scm | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/bioinformatics.scm b/gnu/packages/bioinformatics.scm
index 0fa7bb3746..9a3c0f7d42 100644
--- a/gnu/packages/bioinformatics.scm
+++ b/gnu/packages/bioinformatics.scm
@@ -18084,7 +18084,7 @@ (define-public gdcm
                (base32
                 "1rf0p7dnakjry0fa6ax1h762bn0l5n6ibfdxn077mjvwgpqan51l"))))
     (build-system cmake-build-system)
-    (outputs '("out" "doc"))
+    (outputs '("out" "bin" "doc"))
     (arguments
      (list
       #:phases
@@ -18093,7 +18093,14 @@ (define-public gdcm
             ;; The build spams ‘Fontconfig error: No writable cache
             ;; directories’ in a seemingly endless loop otherwise.
             (lambda _
-              (setenv "HOME" "/tmp"))))
+              (setenv "HOME" "/tmp")))
+          (add-after 'install 'move-files
+            ;; Move utilities to bin output.
+            (lambda _
+              (mkdir-p (string-append #$output:bin "/bin"))
+              (rename-file
+               (string-append #$output "/bin")
+               (string-append #$output:bin "/bin")))))
       #:configure-flags
       #~(list "-DGDCM_BUILD_TESTING=true"
               (string-append "-DCMAKE_CTEST_ARGUMENTS=-E;"
@@ -18105,9 +18112,13 @@ (define-public gdcm
                              "|TestAnonymizer4"
                              "|TestPrinter1"
                              ;; Disable tests that download data from the internet.
+                             "|gdcmscu-echo-dicomserver"
+                             "|gdcmscu-store-dicomserver"
+                             "|gdcmscu-find-dicomserver"
                              "|TestSCUValidation"
                              "|TestEcho"
                              "|TestFind'")
+              "-DGDCM_BUILD_APPLICATIONS:BOOL=ON"
               "-DGDCM_DOCUMENTATION:BOOL=ON"
               "-DGDCM_PDF_DOCUMENTATION:BOOL=OFF"
               (string-append "-DGDCM_INSTALL_DOC_DIR="
-- 
2.39.1

>From 467a7b614ccafa2de51a8e56a6ecf384fb6fa07b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tor-bj=C3=B6rn=20Claesson?= <[email-masked]>
Date: Fri, 27 Jan 2023 17:03:36 +0200
Subject: [PATCH 3/3] gnu: gdcm: Use more system libraries.
gnu: gdcm: Use more system libraries.
---
 gnu/packages/bioinformatics.scm | 48 ++++++++++++++++++++++++++++++---
 1 file changed, 45 insertions(+), 3 deletions(-)

diff --git a/gnu/packages/bioinformatics.scm b/gnu/packages/bioinformatics.scm
index 9a3c0f7d42..77b3388f2e 100644
--- a/gnu/packages/bioinformatics.scm
+++ b/gnu/packages/bioinformatics.scm
@@ -18082,7 +18082,28 @@ (define-public gdcm
               (file-name (git-file-name name version))
               (sha256
                (base32
-                "1rf0p7dnakjry0fa6ax1h762bn0l5n6ibfdxn077mjvwgpqan51l"))))
+                "1rf0p7dnakjry0fa6ax1h762bn0l5n6ibfdxn077mjvwgpqan51l"))
+              (modules '((guix build utils)
+                         (ice-9 ftw)))
+              (snippet
+               '(begin
+                  (define (unbundle? file)
+                    (member file '("dicom3tools"
+                                   "gdcmexpat"
+                                   "gdcmutfcpp"
+                                   "gdcmuuid"
+                                   "gdcmzlib"
+                                   "getopt"
+                                   "KWStyle"
+                                   "pvrg"
+                                   "Release"
+                                   "VTK")))
+                  (with-directory-excursion "Utilities"
+                    (for-each (lambda (utility)
+                                (delete-file-recursively utility)
+                                (substitute* "CMakeLists.txt"
+                                  (((string-append ".*/" utility "/.*")) "")))
+                              (scandir "." unbundle?)))))))
     (build-system cmake-build-system)
     (outputs '("out" "bin" "doc"))
     (arguments
@@ -18123,8 +18144,29 @@ (define-public gdcm
               "-DGDCM_PDF_DOCUMENTATION:BOOL=OFF"
               (string-append "-DGDCM_INSTALL_DOC_DIR="
                              #$output:doc "/share/doc/" #$name)
-              "-DGDCM_BUILD_DOCBOOK_MANPAGES:BOOL=OFF"))) ; TODO: need ‘xsl-ns’
-    (native-inputs (list doxygen graphviz))
+              "-DGDCM_BUILD_DOCBOOK_MANPAGES:BOOL=OFF"  ; TODO: need ‘xsl-ns’
+              ;; Libraries
+              "-DGDCM_USE_SYSTEM_EXPAT:BOOL=ON"
+              "-DGDCM_USE_SYSTEM_LIBXML2:BOOL=ON"
+              "-DGDCM_USE_SYSTEM_OPENSSL:BOOL=ON"
+              "-DGDCM_USE_SYSTEM_POPPLER:BOOL=ON"
+              "-DGDCM_USE_SYSTEM_UUID:BOOL=ON"
+              "-DGDCM_USE_SYSTEM_ZLIB:BOOL=ON"
+              ;; TODO: Unbundle these if possible.
+              "-DGDCM_USE_SYSTEM_CHARLS:BOOL=OFF"
+              "-DGDCM_USE_SYSTEM_JSON:BOOL=OFF"
+              "-DGDCM_USE_SYSTEM_LJPEG:BOOL=OFF"
+              "-DGDCM_USE_SYSTEM_OPENJPEG:BOOL=OFF"
+              "-DGDCM_USE_SYSTEM_PAPYRUS3:BOOL=OFF"
+              "-DGDCM_USE_SYSTEM_SOCKETXX:BOOL=OFF")))
+    (inputs (list
+             expat
+             libxml2
+             openssl
+             poppler
+             `(,util-linux "lib")
+             zlib))
+    (native-inputs (list doxygen graphviz pkg-config))
     (home-page "https://gdcm.sourceforge.net/wiki/index.php/Main_Page")
     (synopsis "Grassroots DICOM library")
     (description
-- 
2.39.1