Subject: [PATCH 1/6] gnu: qtbase: Use the store paths for other packages and dynamically loaded libs.

From: Hartmut Goebel <[email-masked]>
Date: Sat, 3 Feb 2018 20:25:00 +0100

Adobt the NixOS patches as of 2018-01-19:

- .cmake.in and .prf files are not patches.

- src/corelib/tools/qtimezoneprivate_tz.cpp: NixOS uses $TZDIR, we use
  hardcoded path to tzdata.

- src/corelib/kernel/qcoreapplication.cpp: NixOS adds plugin paths derived
  from PATH. We do not need this, since we have native-search-path
  QT_PLUGIN_PATH.

- src/network/kernel/qdnslookup_unix.cpp,
  src/network/kernel/qhostinfo_unix.cpp: Use hardcoded path to libresolv.

- src/network/ssl/qsslcontext_openssl.cpp: NixOS changes a conditional
  compilation for Qt 5.9 (but leaves it unchanged for Qt 5.10) to fix
  compilation with libressl.  But Qt does not support libressl anway, see
  config.tests/openssl/openssl.cpp in qtbase 5.9.4.

- src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp:
  Use hardcoded path to libx11.

- src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp:
  Use hardcoded path to mess's libGL, no need for a fall-back.

- src/plugins/platforms/xcb/qxcbcursor.cpp: Use hardcoded path to Xcursor.

- src/plugins/platformthemes/gtk3/main.cpp: NixOS changes $XDG_DATA_DIRS and
  $GIO_EXTRA_MODULES in the code. We use search-path-specification for this.

- src/testlib/qtestassert.h: Unchanged for guix.

* gnu/packages/qt.scm (qtbase) Add comment. [inputs]: Add tzdata.
  [aguments]<phases>: Add 'patch-paths'.
---
 gnu/packages/qt.scm | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/qt.scm b/gnu/packages/qt.scm
index 8bd51ae66..606c5035a 100644
--- a/gnu/packages/qt.scm
+++ b/gnu/packages/qt.scm
@@ -35,6 +35,7 @@
   #:use-module (guix packages)
   #:use-module (guix utils)
   #:use-module (gnu packages)
+  #:use-module (gnu packages base)
   #:use-module (gnu packages bison)
   #:use-module (gnu packages compression)
   #:use-module (gnu packages cups)
@@ -430,6 +431,7 @@ developers using C++ or QML, a CSS & JavaScript like language.")
        ("postgresql" ,postgresql)
        ("pulseaudio" ,pulseaudio)
        ("sqlite" ,sqlite)
+       ("tzdata" ,tzdata)
        ("unixodbc" ,unixodbc)
        ("xcb-util" ,xcb-util)
        ("xcb-util-image" ,xcb-util-image)
@@ -540,7 +542,42 @@ developers using C++ or QML, a CSS & JavaScript like language.")
                           "qt_config.prf" "winrt/package_manifest.prf"))
                  (("\\$\\$\\[QT_HOST_DATA/get\\]") archdata)
                  (("\\$\\$\\[QT_HOST_DATA/src\\]") archdata))
-               #t))))))
+               #t)))
+         (add-after 'unpack 'patch-paths
+           ;; Use the absolute paths for dynamically loaded libs, otherwise
+           ;; the lib will be searched in the actual executable's RUNPATH,
+           ;; which may not include the requested lib.
+           (lambda* (#:key inputs #:allow-other-keys)
+             ;; tzdata
+             (substitute* "src/corelib/tools/qtimezoneprivate_tz.cpp"
+               (("\"/usr(/(share|lib)/zoneinfo/)" _ path _)
+                (string-append "\"" (assoc-ref inputs "tzdata") path)))
+             ;; libresolve. TODO: Check is this is really required
+             (let ((glibc (assoc-ref inputs ,(if (%current-target-system)
+                                                 "cross-libc" "libc"))))
+               (substitute* '("src/network/kernel/qdnslookup_unix.cpp"
+                              "src/network/kernel/qhostinfo_unix.cpp")
+                 (("^\\s*(lib.setFileName\\(QLatin1String\\(\")(resolv\"\\)\\);)" _ a b)
+                (string-append a glibc "/lib/lib" b))))
+             ;; X11/locale (compose path)
+             (substitute* "src/plugins/platforminputcontexts/compose/generator/qtablegenerator.cpp"
+               ;; Don't search in /usr/…/X11/locale, …
+               (("^\\s*m_possibleLocations.append\\(QStringLiteral\\(\"/usr/.*/X11/locale\"\\)\\);" line)
+                (string-append "// " line))
+               ;; … but use libx11's path
+               (("^\\s*(m_possibleLocations.append\\(QStringLiteral\\()X11_PREFIX \"(/.*/X11/locale\"\\)\\);)" _ a b)
+                (string-append a "\"" (assoc-ref inputs "libx11") b)))
+             ;; libGL
+             (substitute* "src/plugins/platforms/xcb/gl_integrations/xcb_glx/qglxintegration.cpp"
+               (("^\\s*(QLibrary lib\\(QLatin1String\\(\")(GL\"\\)\\);)" _ a b)
+                (string-append a (assoc-ref inputs "mesa") "/lib/lib" b)))
+             ;; libXcusor
+             (substitute* "src/plugins/platforms/xcb/qxcbcursor.cpp"
+               (("^\\s*(QLibrary xcursorLib\\(QLatin1String\\(\")(Xcursor\"\\), 1\\);)" _ a b)
+                (string-append a (assoc-ref inputs "libxcursor") "/lib/lib" b))
+               (("^\\s*(xcursorLib.setFileName\\(QLatin1String\\(\")(Xcursor\"\\)\\);)" _ a b)
+                (string-append a (assoc-ref inputs "libxcursor") "/lib/lib" b)))
+             #t)))))
     (native-search-paths
      (list (search-path-specification
             (variable "QMAKEPATH")
-- 
2.13.6