linux_xanmod: 5.11.14 -> 5.11.15
[NixPkgs.git] / pkgs / development / libraries / qt-5 / hooks / wrap-qt-apps-hook.sh
blobce4d78fbb50f1e3d8cd13756fc2042d024bdae31
1 if [[ -z "${__nix_wrapQtAppsHook-}" ]]; then
2 __nix_wrapQtAppsHook=1 # Don't run this hook more than once.
4 # Inherit arguments given in mkDerivation
5 qtWrapperArgs=( ${qtWrapperArgs-} )
7 qtHostPathSeen=()
9 qtUnseenHostPath() {
10 for pkg in "${qtHostPathSeen[@]}"
12 if [ "${pkg:?}" == "$1" ]
13 then
14 return 1
16 done
18 qtHostPathSeen+=("$1")
19 return 0
22 qtHostPathHook() {
23 qtUnseenHostPath "$1" || return 0
25 local pluginDir="$1/${qtPluginPrefix:?}"
26 if [ -d "$pluginDir" ]
27 then
28 qtWrapperArgs+=(--prefix QT_PLUGIN_PATH : "$pluginDir")
31 local qmlDir="$1/${qtQmlPrefix:?}"
32 if [ -d "$qmlDir" ]
33 then
34 qtWrapperArgs+=(--prefix QML2_IMPORT_PATH : "$qmlDir")
37 addEnvHooks "$hostOffset" qtHostPathHook
39 makeQtWrapper() {
40 local original="$1"
41 local wrapper="$2"
42 shift 2
43 makeWrapper "$original" "$wrapper" "${qtWrapperArgs[@]}" "$@"
46 wrapQtApp() {
47 local program="$1"
48 shift 1
49 wrapProgram "$program" "${qtWrapperArgs[@]}" "$@"
52 qtOwnPathsHook() {
53 local xdgDataDir="${!outputBin}/share"
54 if [ -d "$xdgDataDir" ]
55 then
56 qtWrapperArgs+=(--prefix XDG_DATA_DIRS : "$xdgDataDir")
59 local xdgConfigDir="${!outputBin}/etc/xdg"
60 if [ -d "$xdgConfigDir" ]
61 then
62 qtWrapperArgs+=(--prefix XDG_CONFIG_DIRS : "$xdgConfigDir")
65 qtHostPathHook "${!outputBin}"
68 preFixupPhases+=" qtOwnPathsHook"
70 # Note: $qtWrapperArgs still gets defined even if ${dontWrapQtApps-} is set.
71 wrapQtAppsHook() {
72 # skip this hook when requested
73 [ -z "${dontWrapQtApps-}" ] || return 0
75 # guard against running multiple times (e.g. due to propagation)
76 [ -z "$wrapQtAppsHookHasRun" ] || return 0
77 wrapQtAppsHookHasRun=1
79 local targetDirs=( "$prefix/bin" "$prefix/sbin" "$prefix/libexec" )
80 echo "wrapping Qt applications in ${targetDirs[@]}"
82 for targetDir in "${targetDirs[@]}"
84 [ -d "$targetDir" ] || continue
86 find "$targetDir" ! -type d -executable -print0 | while IFS= read -r -d '' file
88 patchelf --print-interpreter "$file" >/dev/null 2>&1 || continue
90 if [ -f "$file" ]
91 then
92 echo "wrapping $file"
93 wrapQtApp "$file"
94 elif [ -h "$file" ]
95 then
96 target="$(readlink -e "$file")"
97 echo "wrapping $file -> $target"
98 rm "$file"
99 makeQtWrapper "$target" "$file"
101 done
102 done
105 fixupOutputHooks+=(wrapQtAppsHook)