···6accumulateRoles
78for var in "${var_templates_list[@]}"; do
9- mangleVarList "$var" ${role_suffixes[@]+"${role_suffixes[@]}"}
10done
1112export NIX_PKG_CONFIG_WRAPPER_FLAGS_SET_@suffixSalt@=1
···6accumulateRoles
78for var in "${var_templates_list[@]}"; do
9+ mangleVarListGeneric ":" "$var" ${role_suffixes[@]+"${role_suffixes[@]}"}
10done
1112export NIX_PKG_CONFIG_WRAPPER_FLAGS_SET_@suffixSalt@=1
+8-2
pkgs/build-support/wrapper-common/utils.bash
···13 fi
14}
1516-mangleVarList() {
0017 local var="$1"
18 shift
19 local -a role_suffixes=("$@")
···25 for suffix in "${role_suffixes[@]}"; do
26 local inputVar="${var}${suffix}"
27 if [ -v "$inputVar" ]; then
28- export ${outputVar}+="${!outputVar:+ }${!inputVar}"
29 fi
30 done
000031}
3233mangleVarBool() {
···13 fi
14}
1516+mangleVarListGeneric() {
17+ local sep="$1"
18+ shift
19 local var="$1"
20 shift
21 local -a role_suffixes=("$@")
···27 for suffix in "${role_suffixes[@]}"; do
28 local inputVar="${var}${suffix}"
29 if [ -v "$inputVar" ]; then
30+ export ${outputVar}+="${!outputVar:+$sep}${!inputVar}"
31 fi
32 done
33+}
34+35+mangleVarList() {
36+ mangleVarListGeneric " " "$@"
37}
3839mangleVarBool() {
···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
4+5+# Add a directory to TCLLIBPATH, provided that it exists
6+_addToTclLibPath() {
7+ local tclPkg="$1"
8+ if [[ -z "$tclPkg" ]]; then
9+ return
10+ fi
11+12+ if [[ ! -d "$tclPkg" ]]; then
13+ >&2 echo "can't add $tclPkg to TCLLIBPATH; that directory doesn't exist"
14+ exit 1
15+ fi
16+17+ if [[ "$tclPkg" == *" "* ]]; then
18+ tclPkg="{$tclPkg}"
19+ fi
20+21+ if [[ -z "${TCLLIBPATH-}" ]]; then
22+ export TCLLIBPATH="$tclPkg"
23+ else
24+ if [[ "$TCLLIBPATH" != *"$tclPkg "* && "$TCLLIBPATH" != *"$tclPkg" ]]; then
25+ export TCLLIBPATH="${TCLLIBPATH} $tclPkg"
26+ fi
27+ fi
28+}
29+30+# Locate any directory containing an installed pkgIndex file
31+findInstalledTclPkgs() {
32+ local -r newLibDir="${!outputLib}/lib"
33+ if [[ ! -d "$newLibDir" ]]; then
34+ >&2 echo "Assuming no loadable tcl packages installed ($newLibDir does not exist)"
35+ return
36+ fi
37+ echo "$(find "$newLibDir" -name pkgIndex.tcl -exec dirname {} \;)"
38+}
39+40+# Wrap any freshly-installed binaries and set up their TCLLIBPATH
41+wrapTclBins() {
42+ if [[ -z "${TCLLIBPATH-}" ]]; then
43+ echo "skipping automatic Tcl binary wrapping (nothing to do)"
44+ return
45+ fi
46+47+ local -r tclBinsDir="${!outputBin}/bin"
48+ if [[ ! -d "$tclBinsDir" ]]; then
49+ echo "No outputBin found, not using any TCLLIBPATH wrapper"
50+ return
51+ fi
52+53+ find "$tclBinsDir" -type f -executable -print |
54+ while read -r someBin; do
55+ echo "Adding TCLLIBPATH wrapper for $someBin"
56+ wrapProgram "$someBin" --prefix TCLLIBPATH ' ' "$TCLLIBPATH"
57+ done
58+}
59+60+# Generate hook to adjust TCLLIBPATH in anti-dependencies
61+writeTclLibPathHook() {
62+ local -r hookPath="${!outputLib}/nix-support/setup-hook"
63+ mkdir -p "$(dirname "$hookPath")"
64+65+ typeset -f _addToTclLibPath >> "$hookPath"
66+ local -r tclPkgs=$(findInstalledTclPkgs)
67+ while IFS= read -r tclPkg; do
68+ echo "_addToTclLibPath \"$tclPkg\"" >> "$hookPath"
69+ _addToTclLibPath "$tclPkg" true
70+ done <<< "$tclPkgs"
71+}
72+73+postFixupHooks+=(writeTclLibPathHook)
74+postFixupHooks+=(wrapTclBins)