Merge pull request #28057 from obsidiansystems/stdenv-set-u

stdenv-setup: use `set -u`

authored by

John Ericson and committed by
GitHub
2e7a3902 4f7f48fb

+177 -103
+177 -103
pkgs/stdenv/generic/setup.sh
··· 1 - set -e 1 + set -eu 2 2 set -o pipefail 3 3 4 4 : ${outputs:=out} ··· 13 13 # code). The hooks for <hookName> are the shell function or variable 14 14 # <hookName>, and the values of the shell array ‘<hookName>Hooks’. 15 15 runHook() { 16 + local oldOpts="$(shopt -po nounset)" 17 + set -u # May be called from elsewhere, so do `set -u`. 18 + 16 19 local hookName="$1" 17 20 shift 18 - local var="$hookName" 19 - if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi 21 + local hooksSlice="${hookName%Hook}Hooks[@]" 20 22 21 - local varRef="$var[@]" 22 23 local hook 23 - for hook in "_callImplicitHook 0 $hookName" "${!varRef}"; do 24 + # Hack around old bash being bad and thinking empty arrays are 25 + # undefined. 26 + for hook in "_callImplicitHook 0 $hookName" ${!hooksSlice+"${!hooksSlice}"}; do 24 27 _eval "$hook" "$@" 28 + set -u # To balance `_eval` 25 29 done 30 + 31 + eval "${oldOpts}" 26 32 return 0 27 33 } 28 34 ··· 30 36 # Run all hooks with the specified name, until one succeeds (returns a 31 37 # zero exit code). If none succeed, return a non-zero exit code. 32 38 runOneHook() { 39 + local oldOpts="$(shopt -po nounset)" 40 + set -u # May be called from elsewhere, so do `set -u`. 41 + 33 42 local hookName="$1" 34 43 shift 35 - local var="$hookName" 36 - if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi 44 + local hooksSlice="${hookName%Hook}Hooks[@]" 37 45 38 - local varRef="$var[@]" 39 - local hook 40 - for hook in "_callImplicitHook 1 $hookName" "${!varRef}"; do 46 + local hook ret=1 47 + # Hack around old bash like above 48 + for hook in "_callImplicitHook 1 $hookName" ${!hooksSlice+"${!hooksSlice}"}; do 41 49 if _eval "$hook" "$@"; then 42 - return 0 50 + ret=0 51 + break 43 52 fi 53 + set -u # To balance `_eval` 44 54 done 45 - return 1 55 + 56 + eval "${oldOpts}" 57 + return "$ret" 46 58 } 47 59 48 60 ··· 52 64 # environment variables) and from shell scripts (as functions). If you 53 65 # want to allow multiple hooks, use runHook instead. 54 66 _callImplicitHook() { 67 + set -u 55 68 local def="$1" 56 69 local hookName="$2" 57 70 case "$(type -t "$hookName")" in 58 - (function|alias|builtin) "$hookName";; 59 - (file) source "$hookName";; 71 + (function|alias|builtin) 72 + set +u 73 + "$hookName";; 74 + (file) 75 + set +u 76 + source "$hookName";; 60 77 (keyword) :;; 61 - (*) if [ -z "${!hookName}" ]; then return "$def"; else eval "${!hookName}"; fi;; 78 + (*) if [ -z "${!hookName:-}" ]; then 79 + return "$def"; 80 + else 81 + set +u 82 + eval "${!hookName}" 83 + fi;; 62 84 esac 85 + # `_eval` expects hook to need nounset disable and leave it 86 + # disabled anyways, so Ok to to delegate. The alternative of a 87 + # return trap is no good because it would affect nested returns. 63 88 } 64 89 65 90 66 91 # A function wrapper around ‘eval’ that ensures that ‘return’ inside 67 - # hooks exits the hook, not the caller. 92 + # hooks exits the hook, not the caller. Also will only pass args if 93 + # command can take them 68 94 _eval() { 69 - local code="$1" 70 - shift 71 - if [ "$(type -t "$code")" = function ]; then 72 - eval "$code \"\$@\"" 95 + if [ "$(type -t "$1")" = function ]; then 96 + set +u 97 + "$@" # including args 73 98 else 74 - eval "$code" 99 + set +u 100 + eval "$1" 75 101 fi 102 + # `run*Hook` reenables `set -u` 76 103 } 77 104 78 105 ··· 103 130 exitCode="$?" 104 131 set +e 105 132 106 - if [ -n "$showBuildStats" ]; then 133 + if [ -n "${showBuildStats:-}" ]; then 107 134 times > "$NIX_BUILD_TOP/.times" 108 135 local -a times=($(cat "$NIX_BUILD_TOP/.times")) 109 136 # Print the following statistics: ··· 114 141 echo "build time elapsed: " "${times[@]}" 115 142 fi 116 143 117 - if [ "$exitCode" != 0 ]; then 144 + if (( "$exitCode" != 0 )); then 118 145 runHook failureHook 119 146 120 147 # If the builder had a non-zero exit code and 121 148 # $succeedOnFailure is set, create the file 122 149 # ‘$out/nix-support/failed’ to signal failure, and exit 123 150 # normally. Otherwise, return the original exit code. 124 - if [ -n "$succeedOnFailure" ]; then 151 + if [ -n "${succeedOnFailure:-}" ]; then 125 152 echo "build failed with exit code $exitCode (ignored)" 126 153 mkdir -p "$out/nix-support" 127 154 printf "%s" "$exitCode" > "$out/nix-support/failed" ··· 147 174 local varName="$2" 148 175 local dir="$3" 149 176 if [ -d "$dir" ]; then 150 - export "${varName}=${!varName}${!varName:+$delimiter}${dir}" 177 + export "${varName}=${!varName:+${!varName}${delimiter}}${dir}" 151 178 fi 152 179 } 153 180 ··· 171 198 # The function is used in multiple-outputs.sh hook, 172 199 # so it is defined here but tried after the hook. 173 200 _addRpathPrefix() { 174 - if [ "$NIX_NO_SELF_RPATH" != 1 ]; then 201 + if [ "${NIX_NO_SELF_RPATH:-0}" != 1 ]; then 175 202 export NIX_LDFLAGS="-rpath $1/lib $NIX_LDFLAGS" 176 - if [ -n "$NIX_LIB64_IN_SELF_RPATH" ]; then 203 + if [ -n "${NIX_LIB64_IN_SELF_RPATH:-}" ]; then 177 204 export NIX_LDFLAGS="-rpath $1/lib64 $NIX_LDFLAGS" 178 205 fi 179 - if [ -n "$NIX_LIB32_IN_SELF_RPATH" ]; then 206 + if [ -n "${NIX_LIB32_IN_SELF_RPATH:-}" ]; then 180 207 export NIX_LDFLAGS="-rpath $1/lib32 $NIX_LDFLAGS" 181 208 fi 182 209 fi ··· 242 269 addToSearchPath PATH "$i/bin" 243 270 done 244 271 245 - if [ "$NIX_DEBUG" = 1 ]; then 272 + if [ "${NIX_DEBUG:-}" = 1 ]; then 246 273 echo "initial path: $PATH" 247 274 fi 248 275 249 276 250 277 # Check that the pre-hook initialised SHELL. 251 - if [ -z "$SHELL" ]; then echo "SHELL not set"; exit 1; fi 278 + if [ -z "${SHELL:-}" ]; then echo "SHELL not set"; exit 1; fi 252 279 BASH="$SHELL" 253 280 export CONFIG_SHELL="$SHELL" 254 281 ··· 259 286 260 287 261 288 # Execute the pre-hook. 262 - if [ -z "$shell" ]; then export shell="$SHELL"; fi 289 + if [ -z "${shell:-}" ]; then export shell="$SHELL"; fi 263 290 runHook preHook 264 291 265 292 ··· 279 306 # nix-shell doesn't use impure bash. This should replace the O(n) 280 307 # case with an O(1) hash map lookup, assuming bash is implemented 281 308 # well :D. 282 - local varRef="$var[*]" 283 - 284 - case "${!varRef}" in 309 + local varSlice="$var[*]" 310 + # ${..-} to hack around old bash empty array problem 311 + case "${!varSlice-}" in 285 312 *" $pkg "*) return 0 ;; 286 313 esac 314 + unset -v varSlice 287 315 288 316 eval "$var"'+=("$pkg")' 289 317 ··· 293 321 fi 294 322 295 323 if [ -f "$pkg" ]; then 324 + local oldOpts="$(shopt -po nounset)" 325 + set +u 296 326 source "$pkg" 327 + eval "$oldOpts" 297 328 fi 298 329 299 330 if [ -d "$pkg/bin" ]; then ··· 301 332 fi 302 333 303 334 if [ -f "$pkg/nix-support/setup-hook" ]; then 335 + local oldOpts="$(shopt -po nounset)" 336 + set +u 304 337 source "$pkg/nix-support/setup-hook" 338 + eval "$oldOpts" 305 339 fi 306 340 307 341 if [ -f "$pkg/nix-support/$propagatedBuildInputsFile" ]; then ··· 312 346 fi 313 347 } 314 348 315 - if [ -z "$crossConfig" ]; then 349 + declare -a nativePkgs crossPkgs 350 + if [ -z "${crossConfig:-}" ]; then 316 351 # Not cross-compiling - both buildInputs (and variants like propagatedBuildInputs) 317 352 # are handled identically to nativeBuildInputs 318 - declare -a nativePkgs 319 - for i in $nativeBuildInputs $buildInputs \ 320 - $defaultNativeBuildInputs $defaultBuildInputs \ 321 - $propagatedNativeBuildInputs $propagatedBuildInputs; do 353 + for i in ${nativeBuildInputs:-} ${buildInputs:-} \ 354 + ${defaultNativeBuildInputs:-} ${defaultBuildInputs:-} \ 355 + ${propagatedNativeBuildInputs:-} ${propagatedBuildInputs:-}; do 322 356 findInputs "$i" nativePkgs propagated-native-build-inputs 323 357 done 324 358 else 325 - declare -a crossPkgs 326 - for i in $buildInputs $defaultBuildInputs $propagatedBuildInputs; do 359 + for i in ${buildInputs:-} ${defaultBuildInputs:-} ${propagatedBuildInputs:-}; do 327 360 findInputs "$i" crossPkgs propagated-build-inputs 328 361 done 329 362 330 363 declare -a nativePkgs 331 - for i in $nativeBuildInputs $defaultNativeBuildInputs $propagatedNativeBuildInputs; do 364 + for i in ${nativeBuildInputs:-} ${defaultNativeBuildInputs:-} ${propagatedNativeBuildInputs:-}; do 332 365 findInputs "$i" nativePkgs propagated-native-build-inputs 333 366 done 334 367 fi ··· 355 388 runHook envHook "$pkg" 356 389 } 357 390 358 - for i in "${nativePkgs[@]}"; do 391 + # Old bash empty array hack 392 + for i in ${nativePkgs+"${nativePkgs[@]}"}; do 359 393 _addToNativeEnv "$i" 360 394 done 361 395 ··· 367 401 runHook crossEnvHook "$pkg" 368 402 } 369 403 370 - for i in "${crossPkgs[@]}"; do 404 + # Old bash empty array hack 405 + for i in ${crossPkgs+"${crossPkgs[@]}"}; do 371 406 _addToCrossEnv "$i" 372 407 done 373 408 ··· 384 419 # Set the prefix. This is generally $out, but it can be overriden, 385 420 # for instance if we just want to perform a test build/install to a 386 421 # temporary location and write a build report to $out. 387 - if [ -z "$prefix" ]; then 422 + if [ -z "${prefix:-}" ]; then 388 423 prefix="$out"; 389 424 fi 390 425 391 - if [ "$useTempPrefix" = 1 ]; then 426 + if [ "${useTempPrefix:-}" = 1 ]; then 392 427 prefix="$NIX_BUILD_TOP/tmp_prefix"; 393 428 fi 394 429 395 430 396 - PATH=$_PATH${_PATH:+:}$PATH 397 - if [ "$NIX_DEBUG" = 1 ]; then 431 + PATH="${_PATH-}${_PATH:+${PATH:+:}}$PATH" 432 + if [ "${NIX_DEBUG:-}" = 1 ]; then 398 433 echo "final path: $PATH" 399 434 fi 400 435 ··· 423 458 # Prevent OpenSSL-based applications from using certificates in 424 459 # /etc/ssl. 425 460 # Leave it in shells for convenience. 426 - if [ -z "$SSL_CERT_FILE" ] && [ -z "$IN_NIX_SHELL" ]; then 461 + if [ -z "${SSL_CERT_FILE:-}" ] && [ -z "${IN_NIX_SHELL:-}" ]; then 427 462 export SSL_CERT_FILE=/no-cert-file.crt 428 463 fi 429 464 ··· 508 543 509 544 # Select all environment variables that start with a lowercase character. 510 545 for varName in $(env | sed -e $'s/^\([a-z][^= \t]*\)=.*/\\1/; t \n d'); do 511 - if [ "$NIX_DEBUG" = "1" ]; then 546 + if [ "${NIX_DEBUG:-}" = "1" ]; then 512 547 echo "@${varName}@ -> '${!varName}'" 513 548 fi 514 549 args+=("--subst-var" "$varName") ··· 535 570 # then go to the build directory and source in `env-vars' to reproduce 536 571 # the environment used for building. 537 572 dumpVars() { 538 - if [ "$noDumpEnvVars" != 1 ]; then 573 + if [ "${noDumpEnvVars:-0}" != 1 ]; then 539 574 export > "$NIX_BUILD_TOP/env-vars" || true 540 575 fi 541 576 } ··· 600 635 unpackPhase() { 601 636 runHook preUnpack 602 637 603 - if [ -z "$srcs" ]; then 604 - if [ -z "$src" ]; then 638 + if [ -z "${srcs:-}" ]; then 639 + if [ -z "${src:-}" ]; then 605 640 # shellcheck disable=SC2016 606 641 echo 'variable $src or $srcs should point to the source' 607 642 exit 1 ··· 626 661 done 627 662 628 663 # Find the source directory. 629 - if [ -n "$setSourceRoot" ]; then 664 + 665 + # set to empty if unset 666 + : ${sourceRoot=} 667 + 668 + if [ -n "${setSourceRoot:-}" ]; then 630 669 runOneHook setSourceRoot 631 670 elif [ -z "$sourceRoot" ]; then 632 - sourceRoot= 633 671 for i in *; do 634 672 if [ -d "$i" ]; then 635 673 case $dirsBefore in ··· 657 695 # By default, add write permission to the sources. This is often 658 696 # necessary when sources have been copied from other store 659 697 # locations. 660 - if [ "$dontMakeSourcesWritable" != 1 ]; then 698 + if [ "${dontMakeSourcesWritable:-0}" != 1 ]; then 661 699 chmod -R u+w "$sourceRoot" 662 700 fi 663 701 ··· 668 706 patchPhase() { 669 707 runHook prePatch 670 708 671 - for i in $patches; do 709 + for i in ${patches:-}; do 672 710 header "applying patch $i" 3 673 711 local uncompress=cat 674 712 case "$i" in ··· 702 740 configurePhase() { 703 741 runHook preConfigure 704 742 743 + # set to empty if unset 744 + : ${configureScript=} 745 + : ${configureFlags=} 746 + 705 747 if [[ -z "$configureScript" && -x ./configure ]]; then 706 748 configureScript=./configure 707 749 fi 708 750 709 - if [ -z "$dontFixLibtool" ]; then 751 + if [ -z "${dontFixLibtool:-}" ]; then 710 752 local i 711 753 find . -iname "ltmain.sh" -print0 | while IFS='' read -r -d '' i; do 712 754 echo "fixing libtool script $i" ··· 714 756 done 715 757 fi 716 758 717 - if [[ -z "$dontAddPrefix" && -n "$prefix" ]]; then 759 + if [[ -z "${dontAddPrefix:-}" && -n "$prefix" ]]; then 718 760 configureFlags="${prefixKey:---prefix=}$prefix $configureFlags" 719 761 fi 720 762 721 763 # Add --disable-dependency-tracking to speed up some builds. 722 - if [ -z "$dontAddDisableDepTrack" ]; then 764 + if [ -z "${dontAddDisableDepTrack:-}" ]; then 723 765 if [ -f "$configureScript" ] && grep -q dependency-tracking "$configureScript"; then 724 766 configureFlags="--disable-dependency-tracking $configureFlags" 725 767 fi 726 768 fi 727 769 728 770 # By default, disable static builds. 729 - if [ -z "$dontDisableStatic" ]; then 771 + if [ -z "${dontDisableStatic:-}" ]; then 730 772 if [ -f "$configureScript" ] && grep -q enable-static "$configureScript"; then 731 773 configureFlags="--disable-static $configureFlags" 732 774 fi 733 775 fi 734 776 735 777 if [ -n "$configureScript" ]; then 778 + # Old bash empty array hack 736 779 # shellcheck disable=SC2086 737 - local flagsArray=($configureFlags "${configureFlagsArray[@]}") 780 + local flagsArray=( 781 + $configureFlags ${configureFlagsArray+"${configureFlagsArray[@]}"} 782 + ) 738 783 echoCmd 'configure flags' "${flagsArray[@]}" 739 784 # shellcheck disable=SC2086 740 785 $configureScript "${flagsArray[@]}" ··· 750 795 buildPhase() { 751 796 runHook preBuild 752 797 753 - if [[ -z "$makeFlags" && ! ( -n "$makefile" || -e Makefile || -e makefile || -e GNUmakefile ) ]]; then 798 + # set to empty if unset 799 + : ${makeFlags=} 800 + 801 + if [[ -z "$makeFlags" && ! ( -n "${makefile:-}" || -e Makefile || -e makefile || -e GNUmakefile ) ]]; then 754 802 echo "no Makefile, doing nothing" 755 803 else 756 804 # See https://github.com/NixOS/nixpkgs/pull/1354#issuecomment-31260409 757 805 makeFlags="SHELL=$SHELL $makeFlags" 758 806 807 + # Old bash empty array hack 759 808 # shellcheck disable=SC2086 760 - local flagsArray=( \ 761 - ${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} \ 762 - $makeFlags "${makeFlagsArray[@]}" \ 763 - $buildFlags "${buildFlagsArray[@]}") 809 + local flagsArray=( 810 + ${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} 811 + $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"} 812 + $buildFlags ${buildFlagsArray+"${buildFlagsArray[@]}"} 813 + ) 764 814 765 815 echoCmd 'build flags' "${flagsArray[@]}" 766 816 make ${makefile:+-f $makefile} "${flagsArray[@]}" ··· 774 824 checkPhase() { 775 825 runHook preCheck 776 826 827 + # Old bash empty array hack 777 828 # shellcheck disable=SC2086 778 - local flagsArray=( \ 779 - ${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} \ 780 - $makeFlags "${makeFlagsArray[@]}" \ 781 - ${checkFlags:-VERBOSE=y} "${checkFlagsArray[@]}" ${checkTarget:-check}) 829 + local flagsArray=( 830 + ${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} 831 + $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"} 832 + ${checkFlags:-VERBOSE=y} ${checkFlagsArray+"${checkFlagsArray[@]}"} 833 + ${checkTarget:-check} 834 + ) 782 835 783 836 echoCmd 'check flags' "${flagsArray[@]}" 784 837 make ${makefile:+-f $makefile} "${flagsArray[@]}" ··· 797 850 798 851 installTargets="${installTargets:-install}" 799 852 853 + # Old bash empty array hack 800 854 # shellcheck disable=SC2086 801 - local flagsArray=( $installTargets \ 802 - $makeFlags "${makeFlagsArray[@]}" \ 803 - $installFlags "${installFlagsArray[@]}") 855 + local flagsArray=( 856 + $installTargets 857 + $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"} 858 + $installFlags ${installFlagsArray+"${installFlagsArray[@]}"} 859 + ) 804 860 805 861 echoCmd 'install flags' "${flagsArray[@]}" 806 862 make ${makefile:+-f $makefile} "${flagsArray[@]}" ··· 830 886 831 887 # Propagate build inputs and setup hook into the development output. 832 888 833 - if [ -z "$crossConfig" ]; then 889 + if [ -z "${crossConfig:-}" ]; then 834 890 # Not cross-compiling - propagatedBuildInputs are handled identically to propagatedNativeBuildInputs 835 891 local propagated="$propagatedNativeBuildInputs" 836 - if [ -n "$propagatedBuildInputs" ]; then 892 + if [ -n "${propagatedBuildInputs:-}" ]; then 837 893 propagated+="${propagated:+ }$propagatedBuildInputs" 838 894 fi 839 - if [ -n "$propagated" ]; then 895 + if [ -n "${propagated:-}" ]; then 840 896 mkdir -p "${!outputDev}/nix-support" 841 897 # shellcheck disable=SC2086 842 898 printWords $propagated > "${!outputDev}/nix-support/propagated-native-build-inputs" 843 899 fi 844 900 else 845 - if [ -n "$propagatedBuildInputs" ]; then 901 + if [ -n "${propagatedBuildInputs:-}" ]; then 846 902 mkdir -p "${!outputDev}/nix-support" 847 903 # shellcheck disable=SC2086 848 904 printWords $propagatedBuildInputs > "${!outputDev}/nix-support/propagated-build-inputs" 849 905 fi 850 906 851 - if [ -n "$propagatedNativeBuildInputs" ]; then 907 + if [ -n "${propagatedNativeBuildInputs:-}" ]; then 852 908 mkdir -p "${!outputDev}/nix-support" 853 909 # shellcheck disable=SC2086 854 910 printWords $propagatedNativeBuildInputs > "${!outputDev}/nix-support/propagated-native-build-inputs" 855 911 fi 856 912 fi 857 913 858 - if [ -n "$setupHook" ]; then 914 + if [ -n "${setupHook:-}" ]; then 859 915 mkdir -p "${!outputDev}/nix-support" 860 916 substituteAll "$setupHook" "${!outputDev}/nix-support/setup-hook" 861 917 fi 862 918 863 919 # Propagate user-env packages into the output with binaries, TODO? 864 920 865 - if [ -n "$propagatedUserEnvPkgs" ]; then 921 + if [ -n "${propagatedUserEnvPkgs:-}" ]; then 866 922 mkdir -p "${!outputBin}/nix-support" 867 923 # shellcheck disable=SC2086 868 924 printWords $propagatedUserEnvPkgs > "${!outputBin}/nix-support/propagated-user-env-packages" ··· 875 931 installCheckPhase() { 876 932 runHook preInstallCheck 877 933 934 + # Old bash empty array hack 878 935 # shellcheck disable=SC2086 879 - local flagsArray=( \ 880 - ${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} \ 881 - $makeFlags "${makeFlagsArray[@]}" \ 882 - $installCheckFlags "${installCheckFlagsArray[@]}" ${installCheckTarget:-installcheck}) 936 + local flagsArray=( 937 + ${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} 938 + $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"} 939 + $installCheckFlags ${installCheckFlagsArray+"${installCheckFlagsArray[@]}"} 940 + ${installCheckTarget:-installcheck} 941 + ) 883 942 884 943 echoCmd 'installcheck flags' "${flagsArray[@]}" 885 944 make ${makefile:+-f $makefile} "${flagsArray[@]}" ··· 892 951 distPhase() { 893 952 runHook preDist 894 953 954 + # Old bash empty array hack 895 955 # shellcheck disable=SC2086 896 - local flagsArray=($distFlags "${distFlagsArray[@]}" ${distTarget:-dist}) 956 + local flagsArray=( 957 + $distFlags ${distFlagsArray+"${distFlagsArray[@]}"} ${distTarget:-dist} 958 + ) 897 959 898 960 echo 'dist flags: %q' "${flagsArray[@]}" 899 961 make ${makefile:+-f $makefile} "${flagsArray[@]}" 900 962 901 - if [ "$dontCopyDist" != 1 ]; then 963 + if [ "${dontCopyDist:-0}" != 1 ]; then 902 964 mkdir -p "$out/tarballs" 903 965 904 966 # Note: don't quote $tarballs, since we explicitly permit ··· 928 990 929 991 930 992 genericBuild() { 931 - if [ -f "$buildCommandPath" ]; then 932 - . "$buildCommandPath" 993 + if [ -f "${buildCommandPath:-}" ]; then 994 + local oldOpts="$(shopt -po nounset)" 995 + set +u 996 + source "$buildCommandPath" 997 + eval "$oldOpts" 933 998 return 934 999 fi 935 - if [ -n "$buildCommand" ]; then 1000 + if [ -n "${buildCommand:-}" ]; then 1001 + local oldOpts="$(shopt -po nounset)" 1002 + set +u 936 1003 eval "$buildCommand" 1004 + eval "$oldOpts" 937 1005 return 938 1006 fi 939 1007 940 - if [ -z "$phases" ]; then 941 - phases="$prePhases unpackPhase patchPhase $preConfigurePhases \ 942 - configurePhase $preBuildPhases buildPhase checkPhase \ 943 - $preInstallPhases installPhase $preFixupPhases fixupPhase installCheckPhase \ 944 - $preDistPhases distPhase $postPhases"; 1008 + if [ -z "${phases:-}" ]; then 1009 + phases="${prePhases:-} unpackPhase patchPhase ${preConfigurePhases:-} \ 1010 + configurePhase ${preBuildPhases:-} buildPhase checkPhase \ 1011 + ${preInstallPhases:-} installPhase ${preFixupPhases:-} fixupPhase installCheckPhase \ 1012 + ${preDistPhases:-} distPhase ${postPhases:-}"; 945 1013 fi 946 1014 947 1015 for curPhase in $phases; do 948 - if [[ "$curPhase" = buildPhase && -n "$dontBuild" ]]; then continue; fi 949 - if [[ "$curPhase" = checkPhase && -z "$doCheck" ]]; then continue; fi 950 - if [[ "$curPhase" = installPhase && -n "$dontInstall" ]]; then continue; fi 951 - if [[ "$curPhase" = fixupPhase && -n "$dontFixup" ]]; then continue; fi 952 - if [[ "$curPhase" = installCheckPhase && -z "$doInstallCheck" ]]; then continue; fi 953 - if [[ "$curPhase" = distPhase && -z "$doDist" ]]; then continue; fi 1016 + if [[ "$curPhase" = buildPhase && -n "${dontBuild:-}" ]]; then continue; fi 1017 + if [[ "$curPhase" = checkPhase && -z "${doCheck:-}" ]]; then continue; fi 1018 + if [[ "$curPhase" = installPhase && -n "${dontInstall:-}" ]]; then continue; fi 1019 + if [[ "$curPhase" = fixupPhase && -n "${dontFixup:-}" ]]; then continue; fi 1020 + if [[ "$curPhase" = installCheckPhase && -z "${doInstallCheck:-}" ]]; then continue; fi 1021 + if [[ "$curPhase" = distPhase && -z "${doDist:-}" ]]; then continue; fi 954 1022 955 - if [[ -n "$tracePhases" ]]; then 1023 + if [[ -n "${tracePhases:-}" ]]; then 956 1024 echo 957 1025 echo "@ phase-started $out $curPhase" 958 1026 fi ··· 962 1030 963 1031 # Evaluate the variable named $curPhase if it exists, otherwise the 964 1032 # function named $curPhase. 1033 + local oldOpts="$(shopt -po nounset)" 1034 + set +u 965 1035 eval "${!curPhase:-$curPhase}" 1036 + eval "$oldOpts" 966 1037 967 1038 if [ "$curPhase" = unpackPhase ]; then 968 1039 cd "${sourceRoot:-.}" 969 1040 fi 970 1041 971 - if [ -n "$tracePhases" ]; then 1042 + if [ -n "${tracePhases:-}" ]; then 972 1043 echo 973 1044 echo "@ phase-succeeded $out $curPhase" 974 1045 fi ··· 987 1058 988 1059 989 1060 dumpVars 1061 + 1062 + # Disable nounset for nix-shell. 1063 + set +u