python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / pkgs / development / libraries / qt-6 / hooks / wrap-qt-apps-hook.sh
blob8b135a7d7492f0cb66d5fb89e1ce14a2f2864af1
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[@]}"; do
11 if [ "${pkg:?}" == "$1" ]; then
12 return 1
14 done
16 qtHostPathSeen+=("$1")
17 return 0
20 qtHostPathHook() {
21 qtUnseenHostPath "$1" || return 0
23 if ! [ -v qtPluginPrefix ]; then
24 echo "wrapQtAppsHook qtHostPathHook: qtPluginPrefix is unset. hint: add qt6.qtbase to buildInputs"
27 local pluginDir="$1/${qtPluginPrefix:?}"
28 if [ -d "$pluginDir" ]; then
29 qtWrapperArgs+=(--prefix QT_PLUGIN_PATH : "$pluginDir")
32 local qmlDir="$1/${qtQmlPrefix:?}"
33 if [ -d "$qmlDir" ]; then
34 qtWrapperArgs+=(--prefix QML2_IMPORT_PATH : "$qmlDir")
37 addEnvHooks "$targetOffset" 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" ]; then
55 qtWrapperArgs+=(--prefix XDG_DATA_DIRS : "$xdgDataDir")
58 local xdgConfigDir="${!outputBin}/etc/xdg"
59 if [ -d "$xdgConfigDir" ]; then
60 qtWrapperArgs+=(--prefix XDG_CONFIG_DIRS : "$xdgConfigDir")
63 qtHostPathHook "${!outputBin}"
66 preFixupPhases+=" qtOwnPathsHook"
68 # Note: $qtWrapperArgs still gets defined even if ${dontWrapQtApps-} is set.
69 wrapQtAppsHook() {
70 # skip this hook when requested
71 [ -z "${dontWrapQtApps-}" ] || return 0
73 # guard against running multiple times (e.g. due to propagation)
74 [ -z "$wrapQtAppsHookHasRun" ] || return 0
75 wrapQtAppsHookHasRun=1
77 local targetDirs=("$prefix/bin" "$prefix/sbin" "$prefix/libexec" "$prefix/Applications" "$prefix/"*.app)
78 echo "wrapping Qt applications in ${targetDirs[@]}"
80 for targetDir in "${targetDirs[@]}"; do
81 [ -d "$targetDir" ] || continue
83 find "$targetDir" ! -type d -executable -print0 | while IFS= read -r -d '' file; do
84 if [ -f "$file" ]; then
85 echo "wrapping $file"
86 wrapQtApp "$file"
87 elif [ -h "$file" ]; then
88 target="$(readlink -e "$file")"
89 echo "wrapping $file -> $target"
90 rm "$file"
91 makeQtWrapper "$target" "$file"
93 done
94 done
97 fixupOutputHooks+=(wrapQtAppsHook)