Subject: Re: bug#37850: Glib documentation is missing

From: Pierre Neidhardt <[email-masked]>
Date: Fri, 15 Nov 2019 16:06:15 +0100

Oh, that makes total sense, thanks for the explanation Marius!

Alright, final patch attached.
Let me know if I should merge on master.

-- 
Pierre Neidhardt
https://ambrevar.xyz/
>From 29d27b64fb7bbf96a2ed59a3e1c4179717770f5c Mon Sep 17 00:00:00 2001
From: Pierre Neidhardt <[email-masked]>
Date: Mon, 11 Nov 2019 15:38:11 +0100
Subject: [PATCH] gnu: Add glib-with-documentation.

* gnu/packages/glib.scm (glib-with-documentation): New variable.
(glib): Hide package.
---
 gnu/packages/glib.scm | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/gnu/packages/glib.scm b/gnu/packages/glib.scm
index b3e85f8df9..47e4f7006a 100644
--- a/gnu/packages/glib.scm
+++ b/gnu/packages/glib.scm
@@ -339,6 +339,7 @@ shared NFS home directories.")
            (variable "GIO_EXTRA_MODULES")
            (files '("lib/gio/modules")))))
    (search-paths native-search-paths)
+   (properties '((hidden? . #t)) )
 
    (synopsis "Thread-safe general utility library; basis of GTK+ and GNOME")
    (description
@@ -348,6 +349,45 @@ dynamic loading, and an object system.")
    (home-page "https://developer.gnome.org/glib/")
    (license license:lgpl2.1+)))
 
+(define-public glib-with-documentation
+  ;; glib's doc must be built in a separate package since it requires gtk-doc,
+  ;; which in turn depends on glib.
+  (package
+    (inherit glib)
+    (properties '((hidden? . #f)))
+    (outputs (cons "doc" (package-outputs glib))) ; 20 MiB of GTK-Doc reference
+    (native-inputs
+     `(("gtk-doc" ,gtk-doc)             ; for the doc
+       ("docbook-xml" ,docbook-xml)
+       ,@(package-native-inputs glib)))
+    (arguments
+     (substitute-keyword-arguments (package-arguments glib)
+       ((#:configure-flags flags ''())
+        `(cons "-Dgtk_doc=true" ,flags))
+       ((#:phases phases)
+        `(modify-phases ,phases
+           (add-after 'unpack 'make-local-docbook-xml
+             (lambda* (#:key inputs #:allow-other-keys)
+               (let ((replace-http
+                      (lambda (file)
+                        (substitute* file
+                          ;; Warning: gio.xml uses docbook 4.2, hence the "4.." pattern.
+                          (("http://www.oasis-open.org/docbook/xml/4../docbookx.dtd")
+                           (string-append (assoc-ref inputs "docbook-xml")
+                                          "/xml/dtd/docbook/docbookx.dtd"))))))
+                 (replace-http "gio/gdbus-2.0/codegen/codegen_docbook.py")
+                 (for-each replace-http (find-files "." "\\.xml$"))
+                 #t)))
+           (add-after 'install 'move-doc
+             (lambda* (#:key outputs #:allow-other-keys)
+               (let ((out (assoc-ref outputs "out"))
+                     (doc (assoc-ref outputs "doc"))
+                     (html (string-append "/share/gtk-doc")))
+                 (copy-recursively (string-append out html)
+                                   (string-append doc html))
+                 (delete-file-recursively (string-append out html))
+                 #t)))))))))
+
 (define gobject-introspection
   (package
     (name "gobject-introspection")
-- 
2.23.0