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