wrapQtAppsHook: wrap Qt applications for runtime dependencies

This commit is contained in:
Thomas Tuegel
2019-07-05 10:41:41 -05:00
parent 0daecd2d7a
commit f79fd2e826
16 changed files with 315 additions and 107 deletions
@@ -19,12 +19,14 @@ export QMAKEPATH
QMAKEMODULES=
export QMAKEMODULES
addToQMAKEPATH() {
if [ -d "$1/mkspecs" ]; then
qmakePathHook() {
if [ -d "$1/mkspecs" ]
then
QMAKEMODULES="${QMAKEMODULES}${QMAKEMODULES:+:}/mkspecs"
QMAKEPATH="${QMAKEPATH}${QMAKEPATH:+:}$1"
fi
}
envBuildHostHooks+=(qmakePathHook)
# Propagate any runtime dependency of the building package.
# Each dependency is propagated to the user environment and as a build
@@ -32,18 +34,18 @@ addToQMAKEPATH() {
# package depending on the building package. (This is necessary in case
# the building package does not provide runtime dependencies itself and so
# would not be propagated to the user environment.)
qtEnvHook() {
addToQMAKEPATH "$1"
if providesQtRuntime "$1"; then
if [ "z${!outputBin}" != "z${!outputDev}" ]; then
propagatedBuildInputs+=" $1"
fi
propagatedUserEnvPkgs+=" $1"
qtEnvHostTargetHook() {
if providesQtRuntime "$1" && [ "z${!outputBin}" != "z${!outputDev}" ]
then
propagatedBuildInputs+=" $1"
fi
}
envHostTargetHooks+=(qtEnvHook)
envHostTargetHooks+=(qtEnvHostTargetHook)
postPatchMkspecs() {
# Prevent this hook from running multiple times
dontPatchMkspecs=1
local bin="${!outputBin}"
local dev="${!outputDev}"
local doc="${!outputDoc}"
@@ -0,0 +1,106 @@
# Inherit arguments given in mkDerivation
qtWrapperArgs=( $qtWrapperArgs )
qtHostPathSeen=()
qtUnseenHostPath() {
for pkg in "${qtHostPathSeen[@]}"
do
if [ "${pkg:?}" == "$1" ]
then
return 1
fi
done
qtHostPathSeen+=("$1")
return 0
}
qtHostPathHook() {
qtUnseenHostPath "$1" || return 0
local pluginDir="$1/${qtPluginPrefix:?}"
if [ -d "$pluginDir" ]
then
qtWrapperArgs+=(--prefix QT_PLUGIN_PATH : "$pluginDir")
fi
local qmlDir="$1/${qtQmlPrefix:?}"
if [ -d "$qmlDir" ]
then
qtWrapperArgs+=(--prefix QML2_IMPORT_PATH : "$qmlDir")
fi
}
addEnvHooks "$hostOffset" qtHostPathHook
makeQtWrapper() {
local original="$1"
local wrapper="$2"
shift 2
makeWrapper "$original" "$wrapper" "${qtWrapperArgs[@]}" "$@"
}
wrapQtApp() {
local program="$1"
shift 1
wrapProgram "$program" "${qtWrapperArgs[@]}" "$@"
}
qtOwnPathsHook() {
local xdgDataDir="${!outputBin}/share"
if [ -d "$xdgDataDir" ]
then
qtWrapperArgs+=(--prefix XDG_DATA_DIRS : "$xdgDataDir")
fi
local xdgConfigDir="${!outputBin}/etc/xdg"
if [ -d "$xdgConfigDir" ]
then
qtWrapperArgs+=(--prefix XDG_CONFIG_DIRS : "$xdgConfigDir")
fi
qtHostPathHook "${!outputBin}"
}
preFixupPhases+=" qtOwnPathsHook"
isQtApp () {
readelf -d "$1" 2>/dev/null | grep -q -F 'libQt5Core'
}
# Note: $qtWrapperArgs still gets defined even if $dontWrapQtApps is set.
wrapQtAppsHook() {
# skip this hook when requested
[ -z "$dontWrapQtApps" ] || return 0
# guard against running multiple times (e.g. due to propagation)
[ -z "$wrapQtAppsHookHasRun" ] || return 0
wrapQtAppsHookHasRun=1
local targetDirs=( "$prefix/bin" )
echo "wrapping Qt applications in ${targetDirs[@]}"
for targetDir in "${targetDirs[@]}"
do
[ -d "$targetDir" ] || continue
find "$targetDir" -executable -print0 | while IFS= read -r -d '' file
do
isQtApp "$file" || continue
if [ -f "$file" ]
then
echo "wrapping $file"
wrapQtApp "$file"
elif [ -h "$file" ]
then
target="$(readlink -e "$file")"
echo "wrapping $file -> $target"
rm "$file"
makeQtWrapper "$target" "$file"
fi
done
done
}
fixupOutputHooks+=(wrapQtAppsHook)