Skip to content

Commit

Permalink
stdenv substituteAll: use yet another implementation
Browse files Browse the repository at this point in the history
It turned out that process substitution fed into a while-cycle
isn't recognized during darwin bootstrap:
http://hydra.nixos.org/build/35382446/nixlog/1/raw

Also fix broken NIX_DEBUG output, noticed by abbradar.
  • Loading branch information
vcunat committed May 8, 2016
1 parent e892c52 commit 62fc885
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkgs/stdenv/generic/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ substitute() {
content="${content%X}"

for ((n = 2; n < ${#params[*]}; n += 1)); do
p=${params[$n]}
p="${params[$n]}"

if [ "$p" = --replace ]; then
pattern="${params[$((n + 1))]}"
Expand Down Expand Up @@ -448,13 +448,18 @@ substituteAll() {
local -a args=()

# We need to be careful due to vars with multi-line contents or weird names.
while IFS= read -r -d '' varName; do
local IFS==
local varNames="$(env -0 | cut -z -d= -f1 | grep -z -v '^[_A-Z]' | tr '\000' '=')"
local varName
for varName in $varNames; do
if [ "$NIX_DEBUG" = "1" ]; then
echo "@varName@ -> '${varName}'"
echo "@${varName}@ -> '${!varName}'"
fi
args+=("--subst-var" "$varName")
done < <(env -0 | cut -z -d= -f1 | grep -z -v '^[_A-Z]')
done

# restore default $IFS for the child
IFS=$' \t\n'
substitute "$input" "$output" "${args[@]}"
}

Expand Down

4 comments on commit 62fc885

@abbradar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 ~  export shell=ddddd 
 ~  env -0 | cut -z -d= -f1 | grep -z -v '^[_A-Z]' | tr '\000' '='
shell=%                                                                                                    ~    

I suppose = should be cut.

@abbradar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I would have tried to help more, but am immersed in things -- sorry)

@vcunat
Copy link
Member Author

@vcunat vcunat commented on 62fc885 May 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= acts as separator (IFS), so the list is also ended by one, but they get removed in for. I had tested the commit on linux, even building full stdenv.

@abbradar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nice trick and thanks for the explanation!

Please sign in to comment.