2021-05-01 00:25:06 +02:00
|
|
|
# This hook ensures that we do the following in post-fixup:
|
|
|
|
# * wrap any installed executables with a wrapper that configures TCLLIBPATH
|
|
|
|
# * write a setup hook that extends the TCLLIBPATH of any anti-dependencies
|
|
|
|
|
2021-06-17 20:39:44 +02:00
|
|
|
tclWrapperArgs=( ${tclWrapperArgs-} )
|
|
|
|
|
2021-05-01 00:25:06 +02:00
|
|
|
# Add a directory to TCLLIBPATH, provided that it exists
|
|
|
|
_addToTclLibPath() {
|
2021-05-11 17:27:51 +02:00
|
|
|
local tclPkg="$1"
|
2021-05-11 18:17:44 +02:00
|
|
|
if [[ -z "$tclPkg" ]]; then
|
2021-05-01 00:25:06 +02:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2021-05-11 18:17:44 +02:00
|
|
|
if [[ ! -d "$tclPkg" ]]; then
|
2021-05-01 00:25:06 +02:00
|
|
|
>&2 echo "can't add $tclPkg to TCLLIBPATH; that directory doesn't exist"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$tclPkg" == *" "* ]]; then
|
|
|
|
tclPkg="{$tclPkg}"
|
|
|
|
fi
|
|
|
|
|
2021-05-11 18:17:44 +02:00
|
|
|
if [[ -z "${TCLLIBPATH-}" ]]; then
|
2021-05-01 00:25:06 +02:00
|
|
|
export TCLLIBPATH="$tclPkg"
|
|
|
|
else
|
2021-05-10 18:01:19 +02:00
|
|
|
if [[ "$TCLLIBPATH" != *"$tclPkg "* && "$TCLLIBPATH" != *"$tclPkg" ]]; then
|
2021-05-01 00:25:06 +02:00
|
|
|
export TCLLIBPATH="${TCLLIBPATH} $tclPkg"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Locate any directory containing an installed pkgIndex file
|
|
|
|
findInstalledTclPkgs() {
|
|
|
|
local -r newLibDir="${!outputLib}/lib"
|
2021-05-11 18:17:44 +02:00
|
|
|
if [[ ! -d "$newLibDir" ]]; then
|
2021-05-01 00:25:06 +02:00
|
|
|
>&2 echo "Assuming no loadable tcl packages installed ($newLibDir does not exist)"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
echo "$(find "$newLibDir" -name pkgIndex.tcl -exec dirname {} \;)"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Wrap any freshly-installed binaries and set up their TCLLIBPATH
|
|
|
|
wrapTclBins() {
|
2023-01-19 10:45:35 +01:00
|
|
|
if [ "$dontWrapTclBinaries" ]; then return; fi
|
|
|
|
|
2021-05-11 18:17:44 +02:00
|
|
|
if [[ -z "${TCLLIBPATH-}" ]]; then
|
2021-05-01 00:25:06 +02:00
|
|
|
echo "skipping automatic Tcl binary wrapping (nothing to do)"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
local -r tclBinsDir="${!outputBin}/bin"
|
2021-05-11 18:17:44 +02:00
|
|
|
if [[ ! -d "$tclBinsDir" ]]; then
|
2021-05-01 00:25:06 +02:00
|
|
|
echo "No outputBin found, not using any TCLLIBPATH wrapper"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2021-06-17 20:39:44 +02:00
|
|
|
tclWrapperArgs+=(--prefix TCLLIBPATH ' ' "$TCLLIBPATH")
|
|
|
|
|
2021-05-01 00:25:06 +02:00
|
|
|
find "$tclBinsDir" -type f -executable -print |
|
|
|
|
while read -r someBin; do
|
|
|
|
echo "Adding TCLLIBPATH wrapper for $someBin"
|
2021-06-17 20:39:44 +02:00
|
|
|
wrapProgram "$someBin" "${tclWrapperArgs[@]}"
|
2021-05-01 00:25:06 +02:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Generate hook to adjust TCLLIBPATH in anti-dependencies
|
|
|
|
writeTclLibPathHook() {
|
|
|
|
local -r hookPath="${!outputLib}/nix-support/setup-hook"
|
|
|
|
mkdir -p "$(dirname "$hookPath")"
|
|
|
|
|
|
|
|
typeset -f _addToTclLibPath >> "$hookPath"
|
|
|
|
local -r tclPkgs=$(findInstalledTclPkgs)
|
|
|
|
while IFS= read -r tclPkg; do
|
|
|
|
echo "_addToTclLibPath \"$tclPkg\"" >> "$hookPath"
|
|
|
|
_addToTclLibPath "$tclPkg" true
|
|
|
|
done <<< "$tclPkgs"
|
|
|
|
}
|
|
|
|
|
|
|
|
postFixupHooks+=(writeTclLibPathHook)
|
|
|
|
postFixupHooks+=(wrapTclBins)
|