Subject: [PATCH] gnu: gnome-builder: Fix python and GI paths.

From: Leo Prikler <[email-masked]>
Date: Fri, 18 Dec 2020 15:16:16 +0100

This patch fixes #45270 by patching PYTHON_PATH at application start time and
prepending "the correct" GI typelib paths at plugin load time.

* gnu/packages/gnome.scm (gnome-builder)[#:phases]: Add python-wrap and
patch-gi-repository-path.
---
 gnu/packages/gnome.scm | 49 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/gnome.scm b/gnu/packages/gnome.scm
index 6b2ddf15f3..5a166d1b86 100644
--- a/gnu/packages/gnome.scm
+++ b/gnu/packages/gnome.scm
@@ -11890,6 +11890,38 @@ libraries.  Applications do not need to be recompiled--or even restarted.")
                 (string-append (assoc-ref inputs "python-pygobject")
                                "/lib")))
              #t))
+         (add-after 'unpack 'patch-gi-repository-path
+           (lambda* (#:key inputs #:allow-other-keys)
+             (letrec ((gir (lambda (input)
+                             (string-append (assoc-ref inputs input)
+                                            "/lib/girepository-1.0")))
+                      (prepend
+                       (lambda (path)
+                         (let ((fn "g_irepository_prepend_search_path"))
+                           (format #f "~a (~s);~%  " fn path))))
+                      (prepend-gir (lambda (input) (prepend (gir input)))))
+               (substitute* "src/libide/gui/ide-application-plugins.c"
+                 (("g_irepository_prepend_search_path .*" all)
+                  ;; TODO: Try to establish working set.
+                  (string-append
+                   (prepend-gir "template-glib")
+                   (prepend-gir "at-spi2-core")
+                   (prepend-gir "atk")
+                   (prepend-gir "harfbuzz")
+                   (prepend-gir "pango")
+                   (prepend-gir "gtk+")
+                   ;; XXX: Adding gdk-pixbuf results in a load error, despite
+                   ;;      it being needed.
+                   ;; (prepend-gir "gdk-pixbuf")
+                   (prepend-gir "json-glib")
+                   (prepend-gir "jsonrpc-glib")
+                   (prepend-gir "libdazzle")
+                   (prepend-gir "libpeas")
+                   (prepend-gir "libsoup")
+                   (prepend-gir "vte")
+                   (prepend-gir "webkitgtk")
+                   (prepend-gir "gtksourceview")
+                   all))))))
          (add-after 'configure 'fix-ninja
            (lambda _
              ;; #43296: meson(?) incorrectly assumes we want to link
@@ -11901,7 +11933,22 @@ libraries.  Applications do not need to be recompiled--or even restarted.")
            (lambda _
              (system "Xvfb :1 &")
              (setenv "DISPLAY" ":1")
-             #t)))))
+             #t))
+         (add-after 'glib-or-gtk-wrap 'python-wrap
+           (lambda* (#:key inputs outputs #:allow-other-keys)
+             (let ((prog (string-append (assoc-ref outputs "out")
+                                        "/bin/gnome-builder"))
+                   (lib (string-append (assoc-ref outputs "out")
+                                       "/lib")))
+               (wrap-program prog
+                 `("PYTHONPATH" = (,(string-append lib
+                                                   "/python"
+                                                   ,(version-major+minor
+                                                     (package-version
+                                                      python))
+                                                   "/site-packages")
+                                   ,(getenv "PYTHONPATH"))))
+               #t))))))
     (inputs
      `(("devhelp" ,devhelp)
        ("gspell" ,gspell)
-- 
2.29.2