Subject: [PATCH 6/8] gnu: docbook: Refactor docbook-sgml packages.

From: Bruno Victal <[email-masked]>
Date: Wed, 26 Apr 2023 01:56:58 +0100

* gnu/packages/docbook.scm
(docbook-sgml)[build-system]: Switch to copy-build-system.
[arguments]: Replace #:builder with #:install-plan.
Add phases 'fix-permission and 'patch-iso-entities.
[sources]: Use url-fetch/zipbomb.
(docbook-sgml-4.1, docbook-sgml-3.1)[sources]: Ditto.
(iso-8879-entities)[source]: Ditto.
[build-system]: Switch to copy-build-system.
[native-inputs]: Restyle.
---
 gnu/packages/docbook.scm | 70 ++++++++++++++++++----------------------
 1 file changed, 32 insertions(+), 38 deletions(-)

diff --git a/gnu/packages/docbook.scm b/gnu/packages/docbook.scm
index d4441bacee..cc0a663f68 100644
--- a/gnu/packages/docbook.scm
+++ b/gnu/packages/docbook.scm
@@ -585,35 +585,39 @@ (define-public docbook-sgml-4.2
     (name "docbook-sgml")
     (version "4.2")
     (source (origin
-              (method url-fetch)
+              (method url-fetch/zipbomb)
               (uri (string-append
                     "https://www.oasis-open.org/docbook/sgml/4.2/docbook-"
                     version ".zip"))
               (sha256
                (base32
                 "1hrm4qmmzi285bkxkc74lxvjvw2gbl7ycbaxhv31h9rl9g4x5sv7"))))
-    (build-system trivial-build-system)
+    (build-system copy-build-system)
     (arguments
-     '(#:modules ((guix build utils))
-       #:builder
-       (begin
-         (use-modules (guix build utils))
-         (let ((source (assoc-ref %build-inputs "source"))
-               (iso-entities-dir (string-append
-                                  (assoc-ref %build-inputs "iso-8879-entities")))
-               (unzip  (string-append (assoc-ref %build-inputs "unzip")
-                                      "/bin/unzip"))
-               (dtd    (string-append (assoc-ref %outputs "out")
-                                      "/sgml/dtd/docbook")))
-           ;; Extract the sources.
-           (mkdir-p dtd)
-           (chdir dtd)
-           (invoke unzip source)
-           ;; Reference the ISO 8879 character entities.
-           ;; e.g. "iso-lat1.gml" --> "<iso-entities-dir>/ISOlat1"
-           (substitute* "docbook.cat"
-             (("\"iso-(.*)\\.gml\"" _ name)
-              (string-append "\"" iso-entities-dir "/ISO" name "\"")))))))
+     (list
+      #:modules '((guix build copy-build-system)
+                  (guix build utils)
+                  (srfi srfi-26))
+      #:install-plan
+      #~`(("./" "sgml/dtd/docbook"
+           #:exclude-regexp ("catalog\\.xml$"
+                             "ChangeLog$"
+                             "README$"
+                             "\\.txt$")))
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'fix-permissions
+            (lambda _
+              (for-each (cut chmod <> #o644) (find-files "."))))
+          (add-before 'install 'patch-iso-entities
+            (lambda* (#:key inputs #:allow-other-keys)
+              ;; Reference the ISO 8879 character entities.
+              ;; e.g. "iso-lat1.gml" --> "<iso-entities-dir>/ISOlat1"
+              (let ((iso-entities-dir
+                     (assoc-ref %build-inputs "iso-8879-entities")))
+                (substitute* "docbook.cat"
+                  (("\"iso-(.*)\\.gml\"" _ name)
+                   (string-append "\"" iso-entities-dir "/ISO" name "\"")))))))))
     (native-inputs
      (list unzip))
     (inputs
@@ -628,7 +632,7 @@ (define-public docbook-sgml-4.1
     (inherit docbook-sgml-4.2)
     (version "4.1")
     (source (origin
-              (method url-fetch)
+              (method url-fetch/zipbomb)
               (uri (string-append "https://www.oasis-open.org/docbook/sgml/"
                                   version "/docbk41.zip"))
               (sha256
@@ -642,7 +646,7 @@ (define-public docbook-sgml-3.1
     (inherit docbook-sgml)
     (version "3.1")
     (source (origin
-              (method url-fetch)
+              (method url-fetch/zipbomb)
               (uri (string-append "https://www.oasis-open.org/docbook/sgml/"
                                   version "/docbk31.zip"))
               (sha256
@@ -655,23 +659,13 @@ (define iso-8879-entities
     (name "iso-8879-entities")
     (version "0.0")                     ;no proper version
     (source (origin
-              (method url-fetch)
-              (uri "http://www.oasis-open.org/cover/ISOEnts.zip")
+              (method url-fetch/zipbomb)
+              (uri "https://www.oasis-open.org/cover/ISOEnts.zip")
               (sha256
                (base32
                 "1clrkaqnvc1ja4lj8blr0rdlphngkcda3snm7b9jzvcn76d3br6w"))))
-    (build-system trivial-build-system)
-    (arguments
-     '(#:modules ((guix build utils))
-       #:builder
-       (begin
-         (use-modules (guix build utils))
-         (let ((source (assoc-ref %build-inputs "source"))
-               (unzip  (string-append (assoc-ref %build-inputs "unzip")
-                                      "/bin/unzip"))
-               (out (string-append (assoc-ref %outputs "out"))))
-           (invoke unzip source "-d" out)))))
-    (native-inputs `(("unzip" ,unzip)))
+    (build-system copy-build-system)
+    (native-inputs (list unzip))
     (home-page "https://www.oasis-open.org/")
     (synopsis "ISO 8879 character entities")
     (description "ISO 8879 character entities that are typically used in
-- 
2.39.2