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

View File

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

View File

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

View File

@ -17,9 +17,10 @@ runHook() {
shift shift
local var="$hookName" local var="$hookName"
if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
local -n var
local varRef="$var[@]"
local hook local hook
for hook in "_callImplicitHook 0 $hookName" "${var[@]}"; do for hook in "_callImplicitHook 0 $hookName" "${!varRef}"; do
_eval "$hook" "$@" _eval "$hook" "$@"
done done
return 0 return 0
@ -33,9 +34,10 @@ runOneHook() {
shift shift
local var="$hookName" local var="$hookName"
if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
local -n var
local varRef="$var[@]"
local hook local hook
for hook in "_callImplicitHook 1 $hookName" "${var[@]}"; do for hook in "_callImplicitHook 1 $hookName" "${!varRef}"; do
if _eval "$hook" "$@"; then if _eval "$hook" "$@"; then
return 0 return 0
fi fi
@ -271,12 +273,22 @@ runHook addInputsHook
findInputs() { findInputs() {
local pkg="$1" local pkg="$1"
local var="$2" local var="$2"
local -n varDeref="$var"
local propagatedBuildInputsFile="$3" local propagatedBuildInputsFile="$3"
# Stop if we've already added this one # TODO(@Ericson2314): Restore using associative array once Darwin
[[ -z "${varDeref["$pkg"]}" ]] || return 0 # nix-shell doesn't use impure bash. This should replace the O(n)
varDeref["$pkg"]=1 # 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 if ! [ -e "$pkg" ]; then
echo "build input $pkg does not exist" >&2 echo "build input $pkg does not exist" >&2
@ -306,19 +318,19 @@ findInputs() {
if [ -z "$crossConfig" ]; then if [ -z "$crossConfig" ]; then
# Not cross-compiling - both buildInputs (and variants like propagatedBuildInputs) # Not cross-compiling - both buildInputs (and variants like propagatedBuildInputs)
# are handled identically to nativeBuildInputs # are handled identically to nativeBuildInputs
declare -gA nativePkgs declare -ga nativePkgs
for i in $nativeBuildInputs $buildInputs \ for i in $nativeBuildInputs $buildInputs \
$defaultNativeBuildInputs $defaultBuildInputs \ $defaultNativeBuildInputs $defaultBuildInputs \
$propagatedNativeBuildInputs $propagatedBuildInputs; do $propagatedNativeBuildInputs $propagatedBuildInputs; do
findInputs "$i" nativePkgs propagated-native-build-inputs findInputs "$i" nativePkgs propagated-native-build-inputs
done done
else else
declare -gA crossPkgs declare -ga crossPkgs
for i in $buildInputs $defaultBuildInputs $propagatedBuildInputs; do for i in $buildInputs $defaultBuildInputs $propagatedBuildInputs; do
findInputs "$i" crossPkgs propagated-build-inputs findInputs "$i" crossPkgs propagated-build-inputs
done done
declare -gA nativePkgs declare -ga nativePkgs
for i in $nativeBuildInputs $defaultNativeBuildInputs $propagatedNativeBuildInputs; do for i in $nativeBuildInputs $defaultNativeBuildInputs $propagatedNativeBuildInputs; do
findInputs "$i" nativePkgs propagated-native-build-inputs findInputs "$i" nativePkgs propagated-native-build-inputs
done done
@ -334,7 +346,7 @@ _addToNativeEnv() {
runHook envHook "$pkg" runHook envHook "$pkg"
} }
for i in "${!nativePkgs[@]}"; do for i in "${nativePkgs[@]}"; do
_addToNativeEnv "$i" _addToNativeEnv "$i"
done done
@ -345,7 +357,7 @@ _addToCrossEnv() {
runHook crossEnvHook "$pkg" runHook crossEnvHook "$pkg"
} }
for i in "${!crossPkgs[@]}"; do for i in "${crossPkgs[@]}"; do
_addToCrossEnv "$i" _addToCrossEnv "$i"
done done