Skip to content

Commit

Permalink
stdenv-setup: Make the package accumulators associative arrays instea…
Browse files Browse the repository at this point in the history
…d 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.
  • Loading branch information
Ericson2314 committed Jul 12, 2017
1 parent 3cb745d commit 8d76eff
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pkgs/development/haskell-modules/generic-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/interpreters/python/wrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
4 changes: 2 additions & 2 deletions pkgs/servers/x11/xorg/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 12 additions & 15 deletions pkgs/stdenv/generic/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -345,7 +342,7 @@ _addToNativeEnv() {
runHook envHook "$pkg"
}

for i in $nativePkgs; do
for i in "${!nativePkgs[@]}"; do
_addToNativeEnv $i
done

Expand All @@ -356,7 +353,7 @@ _addToCrossEnv() {
runHook crossEnvHook "$pkg"
}

for i in $crossPkgs; do
for i in "${!crossPkgs[@]}"; do
_addToCrossEnv $i
done

Expand Down

0 comments on commit 8d76eff

Please sign in to comment.