stdenv-setup: Make the package accumulators associative arrays instead of strings

This is generally cleaner: less eval, less worrying about separators,
and probably also faster. I got the idea from that python wrapper
script.
This commit is contained in:
John Ericson 2017-07-11 16:04:14 -04:00
parent 3cb745d5a6
commit 8d76effc17
4 changed files with 16 additions and 19 deletions

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

@ -86,7 +86,7 @@ wrapPythonProgramsIn() {
_addToPythonPath() {
local dir="$1"
# Stop if we've already visited here.
if [ -n "${pythonPathsSeen[$dir]}" ]; then return; fi
[ -n "${pythonPathsSeen[$dir]}" ] || return 0
pythonPathsSeen[$dir]=1
# addToSearchPath is defined in stdenv/generic/setup.sh. It will have
# the effect of calling `export program_X=$dir/...:$program_X`.

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

@ -275,17 +275,14 @@ runHook addInputsHook
# Recursively find all build inputs.
findInputs() {
local pkg="$1"
local pkg=$1
local var=$2
local -n varDeref=$var
local propagatedBuildInputsFile=$3
case ${!var} in
*\ $pkg\ *)
return 0
;;
esac
eval $var="'${!var} $pkg '"
# Stop if we've already added this one
[[ -z "${varDeref["$pkg"]}" ]] || return 0
varDeref["$pkg"]=1
if ! [ -e "$pkg" ]; then
echo "build input $pkg does not exist" >&2
@ -296,8 +293,8 @@ findInputs() {
source "$pkg"
fi
if [ -d $1/bin ]; then
addToSearchPath _PATH $1/bin
if [ -d "$pkg/bin" ]; then
addToSearchPath _PATH "$pkg/bin"
fi
if [ -f "$pkg/nix-support/setup-hook" ]; then
@ -317,19 +314,19 @@ findInputs() {
if [ -z "$crossConfig" ]; then
# Not cross-compiling - both buildInputs (and variants like propagatedBuildInputs)
# are handled identically to nativeBuildInputs
nativePkgs=""
declare -gA nativePkgs
for i in $nativeBuildInputs $buildInputs \
$defaultNativeBuildInputs $defaultBuildInputs \
$propagatedNativeBuildInputs $propagatedBuildInputs; do
findInputs $i nativePkgs propagated-native-build-inputs
done
else
crossPkgs=""
declare -gA crossPkgs
for i in $buildInputs $defaultBuildInputs $propagatedBuildInputs; do
findInputs $i crossPkgs propagated-build-inputs
done
nativePkgs=""
declare -gA nativePkgs
for i in $nativeBuildInputs $defaultNativeBuildInputs $propagatedNativeBuildInputs; do
findInputs $i nativePkgs propagated-native-build-inputs
done
@ -345,7 +342,7 @@ _addToNativeEnv() {
runHook envHook "$pkg"
}
for i in $nativePkgs; do
for i in "${!nativePkgs[@]}"; do
_addToNativeEnv $i
done
@ -356,7 +353,7 @@ _addToCrossEnv() {
runHook crossEnvHook "$pkg"
}
for i in $crossPkgs; do
for i in "${!crossPkgs[@]}"; do
_addToCrossEnv $i
done