Merge pull request #27879 from obsidiansystems/cc-wrapper-shellcheck

cc-wrapper: Pass shellcheck and other cleanups

authored by John Ericson and committed by GitHub fdd07f62 dd61dbf5

+195 -161
+15 -6
pkgs/build-support/cc-wrapper/add-flags.sh
··· 1 1 # `-B@out@/bin' forces cc to use ld-wrapper.sh when calling ld. 2 2 export NIX_CFLAGS_COMPILE="-B@out@/bin/ $NIX_CFLAGS_COMPILE" 3 3 4 + # Export and assign separately in order that a failing $(..) will fail 5 + # the script. 6 + 4 7 if [ -e @out@/nix-support/libc-cflags ]; then 5 - export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE" 8 + export NIX_CFLAGS_COMPILE 9 + NIX_CFLAGS_COMPILE="$(< @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE" 6 10 fi 7 11 8 12 if [ -e @out@/nix-support/cc-cflags ]; then 9 - export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/cc-cflags) $NIX_CFLAGS_COMPILE" 13 + export NIX_CFLAGS_COMPILE 14 + NIX_CFLAGS_COMPILE="$(< @out@/nix-support/cc-cflags) $NIX_CFLAGS_COMPILE" 10 15 fi 11 16 12 17 if [ -e @out@/nix-support/gnat-cflags ]; then 13 - export NIX_GNATFLAGS_COMPILE="$(cat @out@/nix-support/gnat-cflags) $NIX_GNATFLAGS_COMPILE" 18 + export NIX_GNATFLAGS_COMPILE 19 + NIX_GNATFLAGS_COMPILE="$(< @out@/nix-support/gnat-cflags) $NIX_GNATFLAGS_COMPILE" 14 20 fi 15 21 16 22 if [ -e @out@/nix-support/libc-ldflags ]; then 17 - export NIX_LDFLAGS+=" $(cat @out@/nix-support/libc-ldflags)" 23 + export NIX_LDFLAGS 24 + NIX_LDFLAGS+=" $(< @out@/nix-support/libc-ldflags)" 18 25 fi 19 26 20 27 if [ -e @out@/nix-support/cc-ldflags ]; then 21 - export NIX_LDFLAGS+=" $(cat @out@/nix-support/cc-ldflags)" 28 + export NIX_LDFLAGS 29 + NIX_LDFLAGS+=" $(< @out@/nix-support/cc-ldflags)" 22 30 fi 23 31 24 32 if [ -e @out@/nix-support/libc-ldflags-before ]; then 25 - export NIX_LDFLAGS_BEFORE="$(cat @out@/nix-support/libc-ldflags-before) $NIX_LDFLAGS_BEFORE" 33 + export NIX_LDFLAGS_BEFORE 34 + NIX_LDFLAGS_BEFORE="$(< @out@/nix-support/libc-ldflags-before) $NIX_LDFLAGS_BEFORE" 26 35 fi 27 36 28 37 export NIX_CC_WRAPPER_FLAGS_SET=1
+22 -8
pkgs/build-support/cc-wrapper/add-hardening.sh
··· 1 1 hardeningFlags=(fortify stackprotector pic strictoverflow format relro bindnow) 2 - hardeningFlags+=("${hardeningEnable[@]}") 2 + # Intentionally word-split in case 'hardeningEnable' is defined in Nix. 3 + hardeningFlags+=(${hardeningEnable[@]}) 3 4 hardeningCFlags=() 4 5 hardeningLDFlags=() 5 - hardeningDisable=${hardeningDisable:-""} 6 6 7 - hardeningDisable+=" @hardening_unsupported_flags@" 7 + declare -A hardeningDisableMap 8 8 9 - if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: Value of '$hardeningDisable': $hardeningDisable >&2; fi 9 + # Intentionally word-split in case 'hardeningDisable' is defined in Nix. The 10 + # array expansion also prevents undefined variables from causing trouble with 11 + # `set -u`. 12 + for flag in ${hardeningDisable[@]} @hardening_unsupported_flags@ 13 + do 14 + hardeningDisableMap[$flag]=1 15 + done 10 16 11 - if [[ ! $hardeningDisable =~ "all" ]]; then 12 - if [[ -n "$NIX_DEBUG" ]]; then echo 'HARDENING: Is active (not completely disabled with "all" flag)' >&2; fi 17 + if [[ -n "$NIX_DEBUG" ]]; then 18 + printf 'HARDENING: disabled flags:' >&2 19 + (( "${#hardeningDisableMap[@]}" )) && printf ' %q' "${!hardeningDisableMap[@]}" >&2 20 + echo >&2 21 + fi 22 + 23 + if [[ -z "${hardeningDisableMap[all]}" ]]; then 24 + if [[ -n "$NIX_DEBUG" ]]; then 25 + echo 'HARDENING: Is active (not completely disabled with "all" flag)' >&2; 26 + fi 13 27 for flag in "${hardeningFlags[@]}" 14 28 do 15 - if [[ ! "${hardeningDisable}" =~ "$flag" ]]; then 29 + if [[ -z "${hardeningDisableMap[$flag]}" ]]; then 16 30 case $flag in 17 31 fortify) 18 32 if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling fortify >&2; fi ··· 20 34 ;; 21 35 stackprotector) 22 36 if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling stackprotector >&2; fi 23 - hardeningCFlags+=('-fstack-protector-strong' '--param ssp-buffer-size=4') 37 + hardeningCFlags+=('-fstack-protector-strong' '--param' 'ssp-buffer-size=4') 24 38 ;; 25 39 pie) 26 40 if [[ -n "$NIX_DEBUG" ]]; then echo HARDENING: enabling CFlags -fPIE >&2; fi
+42 -40
pkgs/build-support/cc-wrapper/cc-wrapper.sh
··· 1 - #! @shell@ -e 1 + #! @shell@ 2 + set -e -o pipefail 3 + shopt -s nullglob 4 + 2 5 path_backup="$PATH" 3 - if [ -n "@coreutils_bin@" ]; then 4 - PATH="@coreutils_bin@/bin:@gnugrep_bin@/bin" 6 + 7 + # That @-vars are substituted separately from bash evaluation makes 8 + # shellcheck think this, and others like it, are useless conditionals. 9 + # shellcheck disable=SC2157 10 + if [[ -n "@coreutils_bin@" && -n "@gnugrep_bin@" ]]; then 11 + PATH="@coreutils_bin@/bin:@gnugrep_bin@/bin" 5 12 fi 6 13 7 14 if [ -n "$NIX_CC_WRAPPER_START_HOOK" ]; then ··· 19 26 # For instance, figure out if linker flags should be passed. 20 27 # GCC prints annoying warnings when they are not needed. 21 28 dontLink=0 22 - getVersion=0 23 29 nonFlagArgs=0 30 + # shellcheck disable=SC2193 24 31 [[ "@prog@" = *++ ]] && isCpp=1 || isCpp=0 25 32 cppInclude=1 26 33 27 34 expandResponseParams "$@" 28 - n=0 29 - while [ $n -lt ${#params[*]} ]; do 35 + declare -i n=0 36 + nParams=${#params[@]} 37 + while [ "$n" -lt "$nParams" ]; do 30 38 p=${params[n]} 31 - p2=${params[$((n+1))]} 39 + p2=${params[n+1]} 32 40 if [ "$p" = -c ]; then 33 41 dontLink=1 34 42 elif [ "$p" = -S ]; then ··· 55 63 nonFlagArgs=1 56 64 elif [ "$p" = -m32 ]; then 57 65 if [ -e @out@/nix-support/dynamic-linker-m32 ]; then 58 - NIX_LDFLAGS+=" -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)" 66 + NIX_LDFLAGS+=" -dynamic-linker $(< @out@/nix-support/dynamic-linker-m32)" 59 67 fi 60 68 fi 61 - n=$((n + 1)) 69 + n+=1 62 70 done 63 71 64 72 # If we pass a flag like -Wl, then gcc will call the linker unless it ··· 71 79 fi 72 80 73 81 # Optionally filter out paths not refering to the store. 74 - if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then 82 + if [[ "$NIX_ENFORCE_PURITY" = 1 && -n "$NIX_STORE" ]]; then 75 83 rest=() 76 - n=0 77 - while [ $n -lt ${#params[*]} ]; do 84 + nParams=${#params[@]} 85 + declare -i n=0 86 + while [ "$n" -lt "$nParams" ]; do 78 87 p=${params[n]} 79 - p2=${params[$((n+1))]} 88 + p2=${params[n+1]} 80 89 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then 81 - skip $p 90 + skip "${p:2}" 82 91 elif [ "$p" = -L ] && badPath "$p2"; then 83 - n=$((n + 1)); skip $p2 92 + n+=1; skip "$p2" 84 93 elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then 85 - skip $p 94 + skip "${p:2}" 86 95 elif [ "$p" = -I ] && badPath "$p2"; then 87 - n=$((n + 1)); skip $p2 96 + n+=1; skip "$p2" 88 97 elif [ "$p" = -isystem ] && badPath "$p2"; then 89 - n=$((n + 1)); skip $p2 98 + n+=1; skip "$p2" 90 99 else 91 100 rest+=("$p") 92 101 fi 93 - n=$((n + 1)) 102 + n+=1 94 103 done 95 104 params=("${rest[@]}") 96 105 fi ··· 99 108 # Clear march/mtune=native -- they bring impurity. 100 109 if [ "$NIX_ENFORCE_NO_NATIVE" = 1 ]; then 101 110 rest=() 102 - for i in "${params[@]}"; do 103 - if [[ "$i" = -m*=native ]]; then 104 - skip $i 111 + for p in "${params[@]}"; do 112 + if [[ "$p" = -m*=native ]]; then 113 + skip "$p" 105 114 else 106 - rest+=("$i") 115 + rest+=("$p") 107 116 fi 108 117 done 109 118 params=("${rest[@]}") ··· 116 125 NIX_CFLAGS_LINK+=" $NIX_CXXSTDLIB_LINK" 117 126 fi 118 127 119 - LD=@ldPath@/ld 120 128 source @out@/nix-support/add-hardening.sh 121 129 122 130 # Add the flags for the C compiler proper. 123 - extraAfter=($NIX_CFLAGS_COMPILE ${hardeningCFlags[@]}) 131 + extraAfter=($NIX_CFLAGS_COMPILE "${hardeningCFlags[@]}") 124 132 extraBefore=() 125 133 126 134 if [ "$dontLink" != 1 ]; then 127 135 128 136 # Add the flags that should only be passed to the compiler when 129 137 # linking. 130 - extraAfter+=($NIX_CFLAGS_LINK ${hardeningLDFlags[@]}) 138 + extraAfter+=($NIX_CFLAGS_LINK "${hardeningLDFlags[@]}") 131 139 132 140 # Add the flags that should be passed to the linker (and prevent 133 141 # `ld-wrapper' from adding NIX_LDFLAGS again). 134 142 for i in $NIX_LDFLAGS_BEFORE; do 135 - extraBefore=(${extraBefore[@]} "-Wl,$i") 143 + extraBefore+=("-Wl,$i") 136 144 done 137 145 for i in $NIX_LDFLAGS; do 138 146 if [ "${i:0:3}" = -L/ ]; then ··· 155 163 156 164 # Optionally print debug info. 157 165 if [ -n "$NIX_DEBUG" ]; then 158 - echo "original flags to @prog@:" >&2 159 - for i in "${params[@]}"; do 160 - echo " $i" >&2 161 - done 162 - echo "extraBefore flags to @prog@:" >&2 163 - for i in ${extraBefore[@]}; do 164 - echo " $i" >&2 165 - done 166 - echo "extraAfter flags to @prog@:" >&2 167 - for i in ${extraAfter[@]}; do 168 - echo " $i" >&2 169 - done 166 + echo "extra flags before to @prog@:" >&2 167 + printf " %q\n" "${extraBefore[@]}" >&2 168 + echo "original flags to @prog@:" >&2 169 + printf " %q\n" "${params[@]}" >&2 170 + echo "extra flags after to @prog@:" >&2 171 + printf " %q\n" "${extraAfter[@]}" >&2 170 172 fi 171 173 172 174 if [ -n "$NIX_CC_WRAPPER_EXEC_HOOK" ]; then ··· 174 176 fi 175 177 176 178 PATH="$path_backup" 177 - exec @prog@ ${extraBefore[@]} "${params[@]}" "${extraAfter[@]}" 179 + exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"
+43 -38
pkgs/build-support/cc-wrapper/gnat-wrapper.sh
··· 1 - #! @shell@ -e 1 + #! @shell@ 2 + set -e -o pipefail 3 + shopt -s nullglob 4 + 2 5 path_backup="$PATH" 6 + 7 + # phase separation makes this look useless 8 + # shellcheck disable=SC2157 3 9 if [ -n "@coreutils_bin@" ]; then 4 - PATH="@coreutils_bin@/bin" 10 + PATH="@coreutils_bin@/bin" 5 11 fi 6 12 7 13 if [ -n "$NIX_GNAT_WRAPPER_START_HOOK" ]; then ··· 18 24 # Figure out if linker flags should be passed. GCC prints annoying 19 25 # warnings when they are not needed. 20 26 dontLink=0 21 - getVersion=0 22 27 nonFlagArgs=0 23 28 24 29 for i in "$@"; do ··· 30 35 nonFlagArgs=1 31 36 elif [ "$i" = -m32 ]; then 32 37 if [ -e @out@/nix-support/dynamic-linker-m32 ]; then 33 - NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)" 38 + NIX_LDFLAGS+=" -dynamic-linker $(< @out@/nix-support/dynamic-linker-m32)" 34 39 fi 35 40 fi 36 41 done ··· 47 52 48 53 # Optionally filter out paths not refering to the store. 49 54 params=("$@") 50 - if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then 55 + if [[ "$NIX_ENFORCE_PURITY" = 1 && -n "$NIX_STORE" ]]; then 51 56 rest=() 52 - n=0 53 - while [ $n -lt ${#params[*]} ]; do 54 - p=${params[n]} 55 - p2=${params[$((n+1))]} 57 + for p in "${params[@]}"; do 56 58 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then 57 - skip $p 59 + skip "${p:2}" 58 60 elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then 59 - skip $p 61 + skip "${p:2}" 60 62 elif [ "${p:0:4}" = -aI/ ] && badPath "${p:3}"; then 61 - skip $p 63 + skip "${p:2}" 62 64 elif [ "${p:0:4}" = -aO/ ] && badPath "${p:3}"; then 63 - skip $p 65 + skip "${p:2}" 64 66 else 65 67 rest+=("$p") 66 68 fi 67 - n=$((n + 1)) 68 69 done 69 70 params=("${rest[@]}") 70 71 fi ··· 73 74 # Clear march/mtune=native -- they bring impurity. 74 75 if [ "$NIX_ENFORCE_NO_NATIVE" = 1 ]; then 75 76 rest=() 76 - for i in "${params[@]}"; do 77 - if [[ "$i" = -m*=native ]]; then 78 - skip $i 77 + for p in "${params[@]}"; do 78 + if [[ "$p" = -m*=native ]]; then 79 + skip "$p" 79 80 else 80 - rest+=("$i") 81 + rest+=("$p") 81 82 fi 82 83 done 83 84 params=("${rest[@]}") ··· 88 89 extraAfter=($NIX_GNATFLAGS_COMPILE) 89 90 extraBefore=() 90 91 91 - if [ "`basename $0`x" = "gnatmakex" ]; then 92 - extraBefore=("--GNATBIND=@out@/bin/gnatbind --GNATLINK=@out@/bin/gnatlink ") 92 + if [ "$(basename "$0")x" = "gnatmakex" ]; then 93 + extraBefore=("--GNATBIND=@out@/bin/gnatbind" "--GNATLINK=@out@/bin/gnatlink ") 93 94 fi 94 95 95 - # Add the flags that should be passed to the linker (and prevent 96 - # `ld-wrapper' from adding NIX_LDFLAGS again). 97 - #for i in $NIX_LDFLAGS_BEFORE; do 98 - # extraBefore=(${extraBefore[@]} "-largs $i") 99 - #done 96 + #if [ "$dontLink" != 1 ]; then 97 + # # Add the flags that should be passed to the linker (and prevent 98 + # # `ld-wrapper' from adding NIX_LDFLAGS again). 99 + # for i in $NIX_LDFLAGS_BEFORE; do 100 + # extraBefore+=("-largs" "$i") 101 + # done 102 + # for i in $NIX_LDFLAGS; do 103 + # if [ "${i:0:3}" = -L/ ]; then 104 + # extraAfter+=("$i") 105 + # else 106 + # extraAfter+=("-largs" "$i") 107 + # fi 108 + # done 109 + # export NIX_LDFLAGS_SET=1 110 + #fi 100 111 101 112 # Optionally print debug info. 102 113 if [ -n "$NIX_DEBUG" ]; then 103 - echo "original flags to @prog@:" >&2 104 - for i in "${params[@]}"; do 105 - echo " $i" >&2 106 - done 107 - echo "extraBefore flags to @prog@:" >&2 108 - for i in ${extraBefore[@]}; do 109 - echo " $i" >&2 110 - done 111 - echo "extraAfter flags to @prog@:" >&2 112 - for i in ${extraAfter[@]}; do 113 - echo " $i" >&2 114 - done 114 + echo "extra flags before to @prog@:" >&2 115 + printf " %q\n" "${extraBefore[@]}" >&2 116 + echo "original flags to @prog@:" >&2 117 + printf " %q\n" "${params[@]}" >&2 118 + echo "extra flags after to @prog@:" >&2 119 + printf " %q\n" "${extraAfter[@]}" >&2 115 120 fi 116 121 117 122 if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then ··· 119 124 fi 120 125 121 126 PATH="$path_backup" 122 - exec @prog@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]} 127 + exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"
+10 -25
pkgs/build-support/cc-wrapper/ld-solaris-wrapper.sh
··· 1 1 #!@shell@ 2 + set -eu -o pipefail 3 + shopt -s nullglob 2 4 3 - set -e 4 - set -u 5 - 5 + declare -a args=("$@") 6 6 # I've also tried adding -z direct and -z lazyload, but it gave too many problems with C++ exceptions :'( 7 7 # Also made sure libgcc would not be lazy-loaded, as suggested here: https://www.illumos.org/issues/2534#note-3 8 8 # but still no success. 9 - cmd="@ld@ -z ignore" 10 - 11 - args=("$@"); 9 + declare -a argsBefore=(-z ignore) argsAfter=() 12 10 13 11 # This loop makes sure all -L arguments are before -l arguments, or ld may complain it cannot find a library. 14 12 # GNU binutils does not have this problem: 15 13 # http://stackoverflow.com/questions/5817269/does-the-order-of-l-and-l-options-in-the-gnu-linker-matter 16 - i=0; 17 - while [[ $i -lt $# ]]; do 14 + while (( $# )); do 18 15 case "${args[$i]}" in 19 - -L) cmd="$cmd ${args[$i]} ${args[($i+1)]}"; i=($i+1); ;; 20 - -L*) cmd="$cmd ${args[$i]}" ;; 21 - *) ;; 16 + -L) argsBefore+=("$1" "$2"); shift ;; 17 + -L?*) argsBefore+=("$1") ;; 18 + *) argsAfter+=("$1") ;; 22 19 esac 23 - i=($i+1); 24 - done 25 - 26 - i=0; 27 - while [[ $i -lt $# ]]; do 28 - case "${args[$i]}" in 29 - -L) i=($i+1); ;; 30 - -L*) ;; 31 - *) cmd="$cmd ${args[$i]}" ;; 32 - esac 33 - i=($i+1); 20 + shift 34 21 done 35 22 36 23 # Trace: 37 24 set -x 38 - exec $cmd 39 - 40 - exit 0 25 + exec "@ld@" "${argsBefore[@]}" "${argsAfter[@]}"
+22 -16
pkgs/build-support/cc-wrapper/ld-wrapper.sh
··· 1 - #! @shell@ -e 1 + #! @shell@ 2 + set -e -o pipefail 2 3 shopt -s nullglob 4 + 3 5 path_backup="$PATH" 6 + 7 + # phase separation makes this look useless 8 + # shellcheck disable=SC2157 4 9 if [ -n "@coreutils_bin@" ]; then 5 - PATH="@coreutils_bin@/bin" 10 + PATH="@coreutils_bin@/bin" 6 11 fi 7 12 8 13 if [ -n "$NIX_LD_WRAPPER_START_HOOK" ]; then ··· 18 23 19 24 # Optionally filter out paths not refering to the store. 20 25 expandResponseParams "$@" 21 - if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" \ 22 - -a \( -z "$NIX_IGNORE_LD_THROUGH_GCC" -o -z "$NIX_LDFLAGS_SET" \) ]; then 26 + if [[ "$NIX_ENFORCE_PURITY" = 1 && -n "$NIX_STORE" 27 + && ( -z "$NIX_IGNORE_LD_THROUGH_GCC" || -z "$NIX_LDFLAGS_SET" ) ]]; then 23 28 rest=() 24 29 nParams=${#params[@]} 25 30 declare -i n=0 26 - while [ $n -lt $nParams ]; do 31 + while [ "$n" -lt "$nParams" ]; do 27 32 p=${params[n]} 28 - p2=${params[$((n+1))]} 33 + p2=${params[n+1]} 29 34 if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then 30 35 skip "${p:2}" 31 36 elif [ "$p" = -L ] && badPath "$p2"; then ··· 49 54 params=("${rest[@]}") 50 55 fi 51 56 52 - LD=@prog@ 53 57 source @out@/nix-support/add-hardening.sh 54 58 55 - extra=("${hardeningLDFlags[@]}") 59 + extraAfter=("${hardeningLDFlags[@]}") 56 60 extraBefore=() 57 61 58 62 if [ -z "$NIX_LDFLAGS_SET" ]; then 59 - extra+=($NIX_LDFLAGS) 63 + extraAfter+=($NIX_LDFLAGS) 60 64 extraBefore+=($NIX_LDFLAGS_BEFORE) 61 65 fi 62 66 63 - extra+=($NIX_LDFLAGS_AFTER $NIX_LDFLAGS_HARDEN) 67 + extraAfter+=($NIX_LDFLAGS_AFTER $NIX_LDFLAGS_HARDEN) 64 68 65 69 declare -a libDirs 66 70 declare -A libs ··· 69 73 # Find all -L... switches for rpath, and relocatable flags for build id. 70 74 if [ "$NIX_DONT_SET_RPATH" != 1 ] || [ "$NIX_SET_BUILD_ID" = 1 ]; then 71 75 prev= 72 - for p in "${params[@]}" "${extra[@]}"; do 76 + for p in "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"; do 73 77 case "$prev" in 74 78 -L) 75 79 libDirs+=("$p") ··· 127 131 libs["$file"]= 128 132 if [ ! "${rpaths[$dir]}" ]; then 129 133 rpaths["$dir"]=1 130 - extra+=(-rpath "$dir") 134 + extraAfter+=(-rpath "$dir") 131 135 fi 132 136 fi 133 137 done ··· 138 142 # Only add --build-id if this is a final link. FIXME: should build gcc 139 143 # with --enable-linker-build-id instead? 140 144 if [ "$NIX_SET_BUILD_ID" = 1 ] && [ ! "$relocatable" ]; then 141 - extra+=(--build-id) 145 + extraAfter+=(--build-id) 142 146 fi 143 147 144 148 145 149 # Optionally print debug info. 146 150 if [ -n "$NIX_DEBUG" ]; then 151 + echo "extra flags before to @prog@:" >&2 152 + printf " %q\n" "${extraBefore[@]}" >&2 147 153 echo "original flags to @prog@:" >&2 148 154 printf " %q\n" "${params[@]}" >&2 149 - echo "extra flags to @prog@:" >&2 150 - printf " %q\n" "${extraBefore[@]}" "${extra[@]}" >&2 155 + echo "extra flags after to @prog@:" >&2 156 + printf " %q\n" "${extraAfter[@]}" >&2 151 157 fi 152 158 153 159 if [ -n "$NIX_LD_WRAPPER_EXEC_HOOK" ]; then ··· 155 161 fi 156 162 157 163 PATH="$path_backup" 158 - exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extra[@]}" 164 + exec @prog@ "${extraBefore[@]}" "${params[@]}" "${extraAfter[@]}"
+14 -9
pkgs/build-support/cc-wrapper/setup-hook.sh
··· 1 1 addCVars () { 2 - if [ -d $1/include ]; then 2 + if [[ -d "$1/include" ]]; then 3 3 export NIX_CFLAGS_COMPILE+=" ${ccIncludeFlag:--isystem} $1/include" 4 4 fi 5 5 6 - if [ -d $1/lib64 -a ! -L $1/lib64 ]; then 6 + if [[ -d "$1/lib64" && ! -L "$1/lib64" ]]; then 7 7 export NIX_LDFLAGS+=" -L$1/lib64" 8 8 fi 9 9 10 - if [ -d $1/lib ]; then 10 + if [[ -d "$1/lib" ]]; then 11 11 export NIX_LDFLAGS+=" -L$1/lib" 12 12 fi 13 13 14 - if test -d $1/Library/Frameworks; then 15 - export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -F$1/Library/Frameworks" 14 + if [[ -d "$1/Library/Frameworks" ]]; then 15 + export NIX_CFLAGS_COMPILE+=" -F$1/Library/Frameworks" 16 16 fi 17 17 } 18 18 19 19 envHooks+=(addCVars) 20 20 21 - # Note: these come *after* $out in the PATH (see setup.sh). 21 + # Note 1: these come *after* $out in the PATH (see setup.sh). 22 + # Note 2: phase separation makes this look useless to shellcheck. 22 23 24 + # shellcheck disable=SC2157 23 25 if [ -n "@cc@" ]; then 24 26 addToSearchPath _PATH @cc@/bin 25 27 fi 26 28 29 + # shellcheck disable=SC2157 27 30 if [ -n "@binutils_bin@" ]; then 28 31 addToSearchPath _PATH @binutils_bin@/bin 29 32 fi 30 33 34 + # shellcheck disable=SC2157 31 35 if [ -n "@libc_bin@" ]; then 32 36 addToSearchPath _PATH @libc_bin@/bin 33 37 fi 34 38 39 + # shellcheck disable=SC2157 35 40 if [ -n "@coreutils_bin@" ]; then 36 41 addToSearchPath _PATH @coreutils_bin@/bin 37 42 fi 38 43 39 - if [ -z "$crossConfig" ]; then 40 - ENV_PREFIX="" 44 + if [ -z "${crossConfig:-}" ]; then 45 + ENV_PREFIX="" 41 46 else 42 - ENV_PREFIX="BUILD_" 47 + ENV_PREFIX="BUILD_" 43 48 fi 44 49 45 50 export NIX_${ENV_PREFIX}CC=@out@
+5 -1
pkgs/build-support/cc-wrapper/utils.sh
··· 24 24 } 25 25 26 26 expandResponseParams() { 27 - params=("$@") 27 + declare -g params=("$@") 28 28 local arg 29 29 for arg in "$@"; do 30 30 if [[ "$arg" == @* ]]; then 31 + # phase separation makes this look useless 32 + # shellcheck disable=SC2157 31 33 if [ -n "@expandResponseParams@" ]; then 34 + # params is used by caller 35 + #shellcheck disable=SC2034 32 36 readarray -d '' params < <("@expandResponseParams@" "$@") 33 37 return 0 34 38 else