summary refs log tree commit diff
path: root/pkgs/stdenv/generic/setup.sh
diff options
context:
space:
mode:
authorVladimír Čunát <vcunat@gmail.com>2016-05-12 03:48:05 +0200
committerVladimír Čunát <vcunat@gmail.com>2016-05-12 04:53:37 +0200
commit81df0354290389128077e00edfd2368eeeea0c24 (patch)
tree385795279a4d0c8754755170368cc1908cefc9d6 /pkgs/stdenv/generic/setup.sh
parent6521529c23fe979cc29867a25ede3a355e5b410c (diff)
downloadnixlib-81df0354290389128077e00edfd2368eeeea0c24.tar
nixlib-81df0354290389128077e00edfd2368eeeea0c24.tar.gz
nixlib-81df0354290389128077e00edfd2368eeeea0c24.tar.bz2
nixlib-81df0354290389128077e00edfd2368eeeea0c24.tar.lz
nixlib-81df0354290389128077e00edfd2368eeeea0c24.tar.xz
nixlib-81df0354290389128077e00edfd2368eeeea0c24.tar.zst
nixlib-81df0354290389128077e00edfd2368eeeea0c24.zip
stdenv setup.sh: revert most of changes around #14907
I'm giving this up. Feel free to find some reasonable variant that works
at least on Linux and Darwin. Problems encountered:
- During bootstrap of Darwin stdenv `env -0` and some bash features
  don't work.
- Without `env -0` the contents of some multi-line phases is taken as
  variable declarations, which wouldn't typically matter, but the PR
  wanted to refuse bash-invalid names which would be occasionally
  triggered. This commit dowgrades that to a warning with explanation.
Diffstat (limited to 'pkgs/stdenv/generic/setup.sh')
-rw-r--r--pkgs/stdenv/generic/setup.sh17
1 files changed, 7 insertions, 10 deletions
diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh
index 10fc4873afa3..ce5feac3c66d 100644
--- a/pkgs/stdenv/generic/setup.sh
+++ b/pkgs/stdenv/generic/setup.sh
@@ -408,14 +408,16 @@ substitute() {
 
         if [ "$p" = --subst-var ]; then
             varName="${params[$((n + 1))]}"
+            n=$((n + 1))
             # check if the used nix attribute name is a valid bash name
             if ! [[ "$varName" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]; then
-                echo "substitution variables must be valid bash names, \"$varName\" isn't."
-                exit 1;
+                echo "WARNING: substitution variables should be valid bash names,"
+                echo "  \"$varName\" isn't and therefore was skipped; it might be caused"
+                echo "  by multi-line phases in variables - see #14907 for details."
+                continue
             fi
             pattern="@$varName@"
             replacement="${!varName}"
-            n=$((n + 1))
         fi
 
         if [ "$p" = --subst-var-by ]; then
@@ -447,19 +449,14 @@ substituteAll() {
     local output="$2"
     local -a args=()
 
-    # We need to be careful due to vars with multi-line contents or weird names.
-    local IFS==
-    local varNames="$(env -0 | cut -z -d= -f1 | grep -z -v '^[_A-Z]' | tr '\000' '=')"
-    local varName
-    for varName in $varNames; do
+    # Select all environment variables that start with a lowercase character.
+    for varName in $(env | sed -e $'s/^\([a-z][^= \t]*\)=.*/\\1/; t \n d'); do
         if [ "$NIX_DEBUG" = "1" ]; then
             echo "@${varName}@ -> '${!varName}'"
         fi
         args+=("--subst-var" "$varName")
     done
 
-    # restore default $IFS for the child
-    IFS=$' \t\n'
     substitute "$input" "$output" "${args[@]}"
 }