Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / development / interpreters / tcl / tcl-package-hook.sh
blob8548ac66402f0fb66fc72cb209b787a4e8d29d09
1 # This hook ensures that we do the following in post-fixup:
2 # * wrap any installed executables with a wrapper that configures TCLLIBPATH
3 # * write a setup hook that extends the TCLLIBPATH of any anti-dependencies
5 tclWrapperArgs=( ${tclWrapperArgs-} )
7 # Add a directory to TCLLIBPATH, provided that it exists
8 _addToTclLibPath() {
9 local tclPkg="$1"
10 if [[ -z "$tclPkg" ]]; then
11 return
14 if [[ ! -d "$tclPkg" ]]; then
15 >&2 echo "can't add $tclPkg to TCLLIBPATH; that directory doesn't exist"
16 exit 1
19 if [[ "$tclPkg" == *" "* ]]; then
20 tclPkg="{$tclPkg}"
23 if [[ -z "${TCLLIBPATH-}" ]]; then
24 export TCLLIBPATH="$tclPkg"
25 else
26 if [[ "$TCLLIBPATH" != *"$tclPkg "* && "$TCLLIBPATH" != *"$tclPkg" ]]; then
27 export TCLLIBPATH="${TCLLIBPATH} $tclPkg"
32 # Locate any directory containing an installed pkgIndex file
33 findInstalledTclPkgs() {
34 local -r newLibDir="${!outputLib}/lib"
35 if [[ ! -d "$newLibDir" ]]; then
36 >&2 echo "Assuming no loadable tcl packages installed ($newLibDir does not exist)"
37 return
39 echo "$(find "$newLibDir" -name pkgIndex.tcl -exec dirname {} \;)"
42 # Wrap any freshly-installed binaries and set up their TCLLIBPATH
43 wrapTclBins() {
44 if [ "$dontWrapTclBinaries" ]; then return; fi
46 if [[ -z "${TCLLIBPATH-}" ]]; then
47 echo "skipping automatic Tcl binary wrapping (nothing to do)"
48 return
51 local -r tclBinsDir="${!outputBin}/bin"
52 if [[ ! -d "$tclBinsDir" ]]; then
53 echo "No outputBin found, not using any TCLLIBPATH wrapper"
54 return
57 tclWrapperArgs+=(--prefix TCLLIBPATH ' ' "$TCLLIBPATH")
59 find "$tclBinsDir" -type f -executable -print |
60 while read -r someBin; do
61 echo "Adding TCLLIBPATH wrapper for $someBin"
62 wrapProgram "$someBin" "${tclWrapperArgs[@]}"
63 done
66 # Generate hook to adjust TCLLIBPATH in anti-dependencies
67 writeTclLibPathHook() {
68 local -r hookPath="${!outputLib}/nix-support/setup-hook"
69 mkdir -p "$(dirname "$hookPath")"
71 typeset -f _addToTclLibPath >> "$hookPath"
72 local -r tclPkgs=$(findInstalledTclPkgs)
73 while IFS= read -r tclPkg; do
74 echo "_addToTclLibPath \"$tclPkg\"" >> "$hookPath"
75 _addToTclLibPath "$tclPkg" true
76 done <<< "$tclPkgs"
79 postFixupHooks+=(writeTclLibPathHook)
80 postFixupHooks+=(wrapTclBins)