2019-09-22 08:38:09 +01:00
|
|
|
# shellcheck shell=bash
|
2015-07-29 12:14:50 +01:00
|
|
|
gappsWrapperArgs=()
|
|
|
|
|
2015-07-30 11:33:52 +01:00
|
|
|
find_gio_modules() {
|
2019-09-22 08:38:09 +01:00
|
|
|
if [ -d "$1/lib/gio/modules" ] && [ -n "$(ls -A "$1/lib/gio/modules")" ] ; then
|
2015-07-30 11:33:52 +01:00
|
|
|
gappsWrapperArgs+=(--prefix GIO_EXTRA_MODULES : "$1/lib/gio/modules")
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-09-22 08:38:09 +01:00
|
|
|
addEnvHooks "${targetOffset:?}" find_gio_modules
|
|
|
|
|
|
|
|
wrapGApp() {
|
|
|
|
local program="$1"
|
|
|
|
shift 1
|
|
|
|
wrapProgram "$program" "${gappsWrapperArgs[@]}" "$@"
|
|
|
|
}
|
2019-09-10 06:11:53 +01:00
|
|
|
|
2015-11-09 14:38:26 +00:00
|
|
|
# Note: $gappsWrapperArgs still gets defined even if $dontWrapGApps is set.
|
2015-07-29 12:14:50 +01:00
|
|
|
wrapGAppsHook() {
|
2015-11-09 14:38:26 +00:00
|
|
|
# guard against running multiple times (e.g. due to propagation)
|
2016-03-17 19:57:46 +00:00
|
|
|
[ -z "$wrapGAppsHookHasRun" ] || return 0
|
2015-11-09 14:38:26 +00:00
|
|
|
wrapGAppsHookHasRun=1
|
2015-11-09 14:18:13 +00:00
|
|
|
|
2015-07-29 12:14:50 +01:00
|
|
|
if [ -n "$GDK_PIXBUF_MODULE_FILE" ]; then
|
|
|
|
gappsWrapperArgs+=(--set GDK_PIXBUF_MODULE_FILE "$GDK_PIXBUF_MODULE_FILE")
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$XDG_ICON_DIRS" ]; then
|
|
|
|
gappsWrapperArgs+=(--prefix XDG_DATA_DIRS : "$XDG_ICON_DIRS")
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$GSETTINGS_SCHEMAS_PATH" ]; then
|
|
|
|
gappsWrapperArgs+=(--prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH")
|
|
|
|
fi
|
|
|
|
|
2019-09-22 08:38:09 +01:00
|
|
|
if [ -d "${prefix:?}/share" ]; then
|
2015-08-12 04:37:36 +01:00
|
|
|
gappsWrapperArgs+=(--prefix XDG_DATA_DIRS : "$prefix/share")
|
2015-07-29 12:14:50 +01:00
|
|
|
fi
|
|
|
|
|
2019-09-22 08:38:09 +01:00
|
|
|
if [ -d "$prefix/lib/gio/modules" ] && [ -n "$(ls -A "$prefix/lib/gio/modules")" ] ; then
|
2019-03-13 21:51:11 +00:00
|
|
|
gappsWrapperArgs+=(--prefix GIO_EXTRA_MODULES : "$prefix/lib/gio/modules")
|
|
|
|
fi
|
|
|
|
|
2019-09-22 08:38:09 +01:00
|
|
|
for v in ${wrapPrefixVariables:-} GST_PLUGIN_SYSTEM_PATH_1_0 GI_TYPELIB_PATH GRL_PLUGIN_PATH; do
|
|
|
|
gappsWrapperArgs+=(--prefix "$v" : "${!v}")
|
2015-07-29 12:14:50 +01:00
|
|
|
done
|
|
|
|
|
2019-09-22 08:38:09 +01:00
|
|
|
if [[ -z "${dontWrapGApps:-}" ]]; then
|
wrap-gapps-hook.sh: only wrap links when required
Unless dontWrapGapps is set, the wrap-gapps-hook.sh will currently
wrap all executables (and symbolic links to executables) found under
the target directories: bin and libexec.
As a result, if a symbolic link in a target directory points to an
executable in a target directory, both will get wrapped. This
causes an extra shell/exec when following the symbolic link,
as well as increasing the size of the final executable's environment.
To avoid wrapping a link to an already wrapped executable, this
commit splits the determination of what gets wrapped into two phases:
1. All binaries under the target directories are wrapped and logged
with "Wrapping program ..."
2. All links to executables under the target directories are
identified and checked to see if they reference an executable
under one of the target directories.
If yes, the required wrapping has already been performed on
the associated binary (in phase 1), so no wrapping is done
and "Not wrapping link: ... (already wrapped)" is logged.
If no, the link points at an executable that hasn't been
wrapped, so the link is wrapped and "Wrapping link: ..." is logged.
As an example, the yelp package has a bin directory that contains
an executable "yelp" and a symbolic link "gnome-help" -> "yelp".
Prior to this commit, the bin directory would contain these files
after wrapping:
gnome-help -- wrapper to exec .gnome-help-wrapped
.gnome-help-wrapped -- a symbolic link to yelp
yelp -- wrapper to exec .yelp-wrapped
.yelp-wrapped -- the original yelp binary
After this commit, the bin directory will instead contain:
gnome-help -- a symbolic link to yelp
yelp -- wrapper to exec .yelp-wrapped
.yelp-wrapped -- the original yelp binary
NOTE: The primary motivation for this commit is to avoid obscuring
the fact that two or more paths are simple aliases and expected to
behave identically. It also reduces the likelihood of hitting
limits related to environment variable size.
LIMITATION: The method used above is intended to be conservative
and will still wrap symbolic links to other symbolic links when
the ultimate target is outside of bin or libexec.
2019-01-28 21:40:31 +00:00
|
|
|
targetDirsThatExist=()
|
|
|
|
targetDirsRealPath=()
|
|
|
|
|
|
|
|
# wrap binaries
|
2017-04-16 03:50:13 +01:00
|
|
|
targetDirs=( "${prefix}/bin" "${prefix}/libexec" )
|
|
|
|
for targetDir in "${targetDirs[@]}"; do
|
|
|
|
if [[ -d "${targetDir}" ]]; then
|
wrap-gapps-hook.sh: only wrap links when required
Unless dontWrapGapps is set, the wrap-gapps-hook.sh will currently
wrap all executables (and symbolic links to executables) found under
the target directories: bin and libexec.
As a result, if a symbolic link in a target directory points to an
executable in a target directory, both will get wrapped. This
causes an extra shell/exec when following the symbolic link,
as well as increasing the size of the final executable's environment.
To avoid wrapping a link to an already wrapped executable, this
commit splits the determination of what gets wrapped into two phases:
1. All binaries under the target directories are wrapped and logged
with "Wrapping program ..."
2. All links to executables under the target directories are
identified and checked to see if they reference an executable
under one of the target directories.
If yes, the required wrapping has already been performed on
the associated binary (in phase 1), so no wrapping is done
and "Not wrapping link: ... (already wrapped)" is logged.
If no, the link points at an executable that hasn't been
wrapped, so the link is wrapped and "Wrapping link: ..." is logged.
As an example, the yelp package has a bin directory that contains
an executable "yelp" and a symbolic link "gnome-help" -> "yelp".
Prior to this commit, the bin directory would contain these files
after wrapping:
gnome-help -- wrapper to exec .gnome-help-wrapped
.gnome-help-wrapped -- a symbolic link to yelp
yelp -- wrapper to exec .yelp-wrapped
.yelp-wrapped -- the original yelp binary
After this commit, the bin directory will instead contain:
gnome-help -- a symbolic link to yelp
yelp -- wrapper to exec .yelp-wrapped
.yelp-wrapped -- the original yelp binary
NOTE: The primary motivation for this commit is to avoid obscuring
the fact that two or more paths are simple aliases and expected to
behave identically. It also reduces the likelihood of hitting
limits related to environment variable size.
LIMITATION: The method used above is intended to be conservative
and will still wrap symbolic links to other symbolic links when
the ultimate target is outside of bin or libexec.
2019-01-28 21:40:31 +00:00
|
|
|
targetDirsThatExist+=("${targetDir}")
|
|
|
|
targetDirsRealPath+=("$(realpath "${targetDir}")/")
|
|
|
|
find "${targetDir}" -type f -executable -print0 \
|
2017-04-16 03:50:13 +01:00
|
|
|
| while IFS= read -r -d '' file; do
|
wrap-gapps-hook.sh: only wrap links when required
Unless dontWrapGapps is set, the wrap-gapps-hook.sh will currently
wrap all executables (and symbolic links to executables) found under
the target directories: bin and libexec.
As a result, if a symbolic link in a target directory points to an
executable in a target directory, both will get wrapped. This
causes an extra shell/exec when following the symbolic link,
as well as increasing the size of the final executable's environment.
To avoid wrapping a link to an already wrapped executable, this
commit splits the determination of what gets wrapped into two phases:
1. All binaries under the target directories are wrapped and logged
with "Wrapping program ..."
2. All links to executables under the target directories are
identified and checked to see if they reference an executable
under one of the target directories.
If yes, the required wrapping has already been performed on
the associated binary (in phase 1), so no wrapping is done
and "Not wrapping link: ... (already wrapped)" is logged.
If no, the link points at an executable that hasn't been
wrapped, so the link is wrapped and "Wrapping link: ..." is logged.
As an example, the yelp package has a bin directory that contains
an executable "yelp" and a symbolic link "gnome-help" -> "yelp".
Prior to this commit, the bin directory would contain these files
after wrapping:
gnome-help -- wrapper to exec .gnome-help-wrapped
.gnome-help-wrapped -- a symbolic link to yelp
yelp -- wrapper to exec .yelp-wrapped
.yelp-wrapped -- the original yelp binary
After this commit, the bin directory will instead contain:
gnome-help -- a symbolic link to yelp
yelp -- wrapper to exec .yelp-wrapped
.yelp-wrapped -- the original yelp binary
NOTE: The primary motivation for this commit is to avoid obscuring
the fact that two or more paths are simple aliases and expected to
behave identically. It also reduces the likelihood of hitting
limits related to environment variable size.
LIMITATION: The method used above is intended to be conservative
and will still wrap symbolic links to other symbolic links when
the ultimate target is outside of bin or libexec.
2019-01-28 21:40:31 +00:00
|
|
|
echo "Wrapping program '${file}'"
|
2019-09-22 08:38:09 +01:00
|
|
|
wrapGApp "${file}"
|
2017-04-16 03:50:13 +01:00
|
|
|
done
|
|
|
|
fi
|
2015-11-09 14:38:26 +00:00
|
|
|
done
|
wrap-gapps-hook.sh: only wrap links when required
Unless dontWrapGapps is set, the wrap-gapps-hook.sh will currently
wrap all executables (and symbolic links to executables) found under
the target directories: bin and libexec.
As a result, if a symbolic link in a target directory points to an
executable in a target directory, both will get wrapped. This
causes an extra shell/exec when following the symbolic link,
as well as increasing the size of the final executable's environment.
To avoid wrapping a link to an already wrapped executable, this
commit splits the determination of what gets wrapped into two phases:
1. All binaries under the target directories are wrapped and logged
with "Wrapping program ..."
2. All links to executables under the target directories are
identified and checked to see if they reference an executable
under one of the target directories.
If yes, the required wrapping has already been performed on
the associated binary (in phase 1), so no wrapping is done
and "Not wrapping link: ... (already wrapped)" is logged.
If no, the link points at an executable that hasn't been
wrapped, so the link is wrapped and "Wrapping link: ..." is logged.
As an example, the yelp package has a bin directory that contains
an executable "yelp" and a symbolic link "gnome-help" -> "yelp".
Prior to this commit, the bin directory would contain these files
after wrapping:
gnome-help -- wrapper to exec .gnome-help-wrapped
.gnome-help-wrapped -- a symbolic link to yelp
yelp -- wrapper to exec .yelp-wrapped
.yelp-wrapped -- the original yelp binary
After this commit, the bin directory will instead contain:
gnome-help -- a symbolic link to yelp
yelp -- wrapper to exec .yelp-wrapped
.yelp-wrapped -- the original yelp binary
NOTE: The primary motivation for this commit is to avoid obscuring
the fact that two or more paths are simple aliases and expected to
behave identically. It also reduces the likelihood of hitting
limits related to environment variable size.
LIMITATION: The method used above is intended to be conservative
and will still wrap symbolic links to other symbolic links when
the ultimate target is outside of bin or libexec.
2019-01-28 21:40:31 +00:00
|
|
|
|
|
|
|
# wrap links to binaries that point outside targetDirs
|
|
|
|
# Note: links to binaries within targetDirs do not need
|
|
|
|
# to be wrapped as the binaries have already been wrapped
|
|
|
|
if [[ ${#targetDirsThatExist[@]} -ne 0 ]]; then
|
|
|
|
find "${targetDirsThatExist[@]}" -type l -xtype f -executable -print0 \
|
|
|
|
| while IFS= read -r -d '' linkPath; do
|
|
|
|
linkPathReal=$(realpath "${linkPath}")
|
|
|
|
for targetPath in "${targetDirsRealPath[@]}"; do
|
|
|
|
if [[ "$linkPathReal" == "$targetPath"* ]]; then
|
|
|
|
echo "Not wrapping link: '$linkPath' (already wrapped)"
|
|
|
|
continue 2
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "Wrapping link: '$linkPath'"
|
2019-09-22 08:38:09 +01:00
|
|
|
wrapGApp "${linkPath}"
|
wrap-gapps-hook.sh: only wrap links when required
Unless dontWrapGapps is set, the wrap-gapps-hook.sh will currently
wrap all executables (and symbolic links to executables) found under
the target directories: bin and libexec.
As a result, if a symbolic link in a target directory points to an
executable in a target directory, both will get wrapped. This
causes an extra shell/exec when following the symbolic link,
as well as increasing the size of the final executable's environment.
To avoid wrapping a link to an already wrapped executable, this
commit splits the determination of what gets wrapped into two phases:
1. All binaries under the target directories are wrapped and logged
with "Wrapping program ..."
2. All links to executables under the target directories are
identified and checked to see if they reference an executable
under one of the target directories.
If yes, the required wrapping has already been performed on
the associated binary (in phase 1), so no wrapping is done
and "Not wrapping link: ... (already wrapped)" is logged.
If no, the link points at an executable that hasn't been
wrapped, so the link is wrapped and "Wrapping link: ..." is logged.
As an example, the yelp package has a bin directory that contains
an executable "yelp" and a symbolic link "gnome-help" -> "yelp".
Prior to this commit, the bin directory would contain these files
after wrapping:
gnome-help -- wrapper to exec .gnome-help-wrapped
.gnome-help-wrapped -- a symbolic link to yelp
yelp -- wrapper to exec .yelp-wrapped
.yelp-wrapped -- the original yelp binary
After this commit, the bin directory will instead contain:
gnome-help -- a symbolic link to yelp
yelp -- wrapper to exec .yelp-wrapped
.yelp-wrapped -- the original yelp binary
NOTE: The primary motivation for this commit is to avoid obscuring
the fact that two or more paths are simple aliases and expected to
behave identically. It also reduces the likelihood of hitting
limits related to environment variable size.
LIMITATION: The method used above is intended to be conservative
and will still wrap symbolic links to other symbolic links when
the ultimate target is outside of bin or libexec.
2019-01-28 21:40:31 +00:00
|
|
|
done
|
|
|
|
fi
|
2015-11-09 14:38:26 +00:00
|
|
|
fi
|
2015-07-29 12:14:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fixupOutputHooks+=(wrapGAppsHook)
|