stdenv-setup and misc hooks: Work with bash-3.4 for MacOS nix-shell

This is a temporary measure until this impurity is removed from Nix.
This commit is contained in:
John Ericson 2017-07-25 17:48:50 -04:00
parent f6f40e3fe5
commit ea7d13cf1a
4 changed files with 29 additions and 17 deletions

View File

@ -54,7 +54,7 @@ do
if
PATH=$_PATH type -p "@binPrefix@$CMD" > /dev/null
then
export "${ENV_PREFIX}${CMD^^}=@binPrefix@${CMD}";
export "${ENV_PREFIX}$(echo "$CMD" | tr "[:lower:]" "[:upper:]")=@binPrefix@${CMD}";
fi
done

View File

@ -211,7 +211,7 @@ stdenv.mkDerivation ({
configureFlags="${concatStringsSep " " defaultConfigureFlags} $configureFlags"
# nativePkgs defined in stdenv/setup.hs
for p in "''${!nativePkgs[@]}"; do
for p in "''${nativePkgs[@]}"; do
if [ -d "$p/lib/${ghc.name}/package.conf.d" ]; then
cp -f "$p/lib/${ghc.name}/package.conf.d/"*.conf $packageConfDir/
continue

View File

@ -18,14 +18,14 @@ postInstall() {
for r in $requires; do
if test -n "$crossConfig"; then
for p in "${!crossPkgs[@]}"; do
for p in "${crossPkgs[@]}"; do
if test -e $p/lib/pkgconfig/$r.pc; then
echo " found requisite $r in $p"
propagatedBuildInputs="$propagatedBuildInputs $p"
fi
done
else
for p in "${!nativePkgs[@]}"; do
for p in "${nativePkgs[@]}"; do
if test -e $p/lib/pkgconfig/$r.pc; then
echo " found requisite $r in $p"
propagatedNativeBuildInputs="$propagatedNativeBuildInputs $p"

View File

@ -17,9 +17,10 @@ runHook() {
shift
local var="$hookName"
if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
local -n var
local varRef="$var[@]"
local hook
for hook in "_callImplicitHook 0 $hookName" "${var[@]}"; do
for hook in "_callImplicitHook 0 $hookName" "${!varRef}"; do
_eval "$hook" "$@"
done
return 0
@ -33,9 +34,10 @@ runOneHook() {
shift
local var="$hookName"
if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
local -n var
local varRef="$var[@]"
local hook
for hook in "_callImplicitHook 1 $hookName" "${var[@]}"; do
for hook in "_callImplicitHook 1 $hookName" "${!varRef}"; do
if _eval "$hook" "$@"; then
return 0
fi
@ -271,12 +273,22 @@ runHook addInputsHook
findInputs() {
local pkg="$1"
local var="$2"
local -n varDeref="$var"
local propagatedBuildInputsFile="$3"
# Stop if we've already added this one
[[ -z "${varDeref["$pkg"]}" ]] || return 0
varDeref["$pkg"]=1
# TODO(@Ericson2314): Restore using associative array once Darwin
# nix-shell doesn't use impure bash. This should replace the O(n)
# case with an O(1) hash map lookup, assuming bash is implemented
# well :D.
local varRef="$var[*]"
case "${!varRef}" in
*" $pkg "*) return 0 ;;
esac
# For some reason, bash gives us some (hopefully limited) eval
# "for free"! Everything is single-quoted except for `"$var"`
# so `var` is expanded first.
declare -g "$var"'=("${'"$var"'[@]}" "$pkg")'
if ! [ -e "$pkg" ]; then
echo "build input $pkg does not exist" >&2
@ -306,19 +318,19 @@ findInputs() {
if [ -z "$crossConfig" ]; then
# Not cross-compiling - both buildInputs (and variants like propagatedBuildInputs)
# are handled identically to nativeBuildInputs
declare -gA nativePkgs
declare -ga nativePkgs
for i in $nativeBuildInputs $buildInputs \
$defaultNativeBuildInputs $defaultBuildInputs \
$propagatedNativeBuildInputs $propagatedBuildInputs; do
findInputs "$i" nativePkgs propagated-native-build-inputs
done
else
declare -gA crossPkgs
declare -ga crossPkgs
for i in $buildInputs $defaultBuildInputs $propagatedBuildInputs; do
findInputs "$i" crossPkgs propagated-build-inputs
done
declare -gA nativePkgs
declare -ga nativePkgs
for i in $nativeBuildInputs $defaultNativeBuildInputs $propagatedNativeBuildInputs; do
findInputs "$i" nativePkgs propagated-native-build-inputs
done
@ -334,7 +346,7 @@ _addToNativeEnv() {
runHook envHook "$pkg"
}
for i in "${!nativePkgs[@]}"; do
for i in "${nativePkgs[@]}"; do
_addToNativeEnv "$i"
done
@ -345,7 +357,7 @@ _addToCrossEnv() {
runHook crossEnvHook "$pkg"
}
for i in "${!crossPkgs[@]}"; do
for i in "${crossPkgs[@]}"; do
_addToCrossEnv "$i"
done