python311Packages.moto: 4.2.6 -> 4.2.10
[NixPkgs.git] / pkgs / build-support / setup-hooks / wrap-gapps-hook / wrap-gapps-hook.sh
blob0acf4a8e6f8d41400eb504117c5ebc0f5faca073
1 # shellcheck shell=bash
2 gappsWrapperArgs=()
4 find_gio_modules() {
5 if [ -d "$1/lib/gio/modules" ] && [ -n "$(ls -A "$1/lib/gio/modules")" ] ; then
6 gappsWrapperArgs+=(--prefix GIO_EXTRA_MODULES : "$1/lib/gio/modules")
7 fi
10 addEnvHooks "${targetOffset:?}" find_gio_modules
12 gappsWrapperArgsHook() {
13 if [ -n "$GDK_PIXBUF_MODULE_FILE" ]; then
14 gappsWrapperArgs+=(--set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE")
17 if [ -n "$GSETTINGS_SCHEMAS_PATH" ]; then
18 gappsWrapperArgs+=(--prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH")
21 # Check for prefix as well
22 if [ -d "${prefix:?}/share" ]; then
23 gappsWrapperArgs+=(--prefix XDG_DATA_DIRS : "$prefix/share")
26 if [ -d "$prefix/lib/gio/modules" ] && [ -n "$(ls -A "$prefix/lib/gio/modules")" ]; then
27 gappsWrapperArgs+=(--prefix GIO_EXTRA_MODULES : "$prefix/lib/gio/modules")
30 for v in ${wrapPrefixVariables:-} GST_PLUGIN_SYSTEM_PATH_1_0 GI_TYPELIB_PATH GRL_PLUGIN_PATH; do
31 if [ -n "${!v}" ]; then
32 gappsWrapperArgs+=(--prefix "$v" : "${!v}")
34 done
37 preFixupPhases+=" gappsWrapperArgsHook"
39 wrapGApp() {
40 local program="$1"
41 shift 1
42 wrapProgram "$program" "${gappsWrapperArgs[@]}" "$@"
45 # Note: $gappsWrapperArgs still gets defined even if ${dontWrapGApps-} is set.
46 wrapGAppsHook() {
47 # guard against running multiple times (e.g. due to propagation)
48 [ -z "$wrapGAppsHookHasRun" ] || return 0
49 wrapGAppsHookHasRun=1
51 if [[ -z "${dontWrapGApps:-}" ]]; then
52 targetDirsThatExist=()
53 targetDirsRealPath=()
55 # wrap binaries
56 targetDirs=("${prefix}/bin" "${prefix}/libexec")
57 for targetDir in "${targetDirs[@]}"; do
58 if [[ -d "${targetDir}" ]]; then
59 targetDirsThatExist+=("${targetDir}")
60 targetDirsRealPath+=("$(realpath "${targetDir}")/")
61 find "${targetDir}" -type f -executable -print0 |
62 while IFS= read -r -d '' file; do
63 echo "Wrapping program '${file}'"
64 wrapGApp "${file}"
65 done
67 done
69 # wrap links to binaries that point outside targetDirs
70 # Note: links to binaries within targetDirs do not need
71 # to be wrapped as the binaries have already been wrapped
72 if [[ ${#targetDirsThatExist[@]} -ne 0 ]]; then
73 find "${targetDirsThatExist[@]}" -type l -xtype f -executable -print0 |
74 while IFS= read -r -d '' linkPath; do
75 linkPathReal=$(realpath "${linkPath}")
76 for targetPath in "${targetDirsRealPath[@]}"; do
77 if [[ "$linkPathReal" == "$targetPath"* ]]; then
78 echo "Not wrapping link: '$linkPath' (already wrapped)"
79 continue 2
81 done
82 echo "Wrapping link: '$linkPath'"
83 wrapGApp "${linkPath}"
84 done
89 fixupOutputHooks+=(wrapGAppsHook)