From 4bd38c330fc6dace1f45a29bbc7f5c64b22fffdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Sat, 17 Jul 2021 20:27:52 +0200 Subject: [PATCH] Revert #127736: stdenv changes towards an alternative shell At least for now. Such changes are risky (we have very many packages), and apparently it needs more testing/review without blocking other changes. This reverts the whole range 4d0e3984918^..8752c327377, except for one commit that got reverted in 6f239d73096 already. (that MR didn't even get its merge commit) --- .../bintools-wrapper/setup-hook.sh | 9 +- .../setup-hooks/auto-patchelf.sh | 1 - pkgs/build-support/setup-hooks/autoreconf.sh | 3 +- .../setup-hooks/make-symlinks-relative.sh | 1 - pkgs/build-support/setup-hooks/move-docs.sh | 7 +- .../setup-hooks/multiple-outputs.sh | 16 +- .../setup-hooks/reproducible-builds.sh | 8 +- pkgs/stdenv/generic/builder.sh | 18 +- pkgs/stdenv/generic/setup.sh | 244 ++++++++---------- 9 files changed, 128 insertions(+), 179 deletions(-) diff --git a/pkgs/build-support/bintools-wrapper/setup-hook.sh b/pkgs/build-support/bintools-wrapper/setup-hook.sh index ba09d19b1f26..7e9547b96c25 100644 --- a/pkgs/build-support/bintools-wrapper/setup-hook.sh +++ b/pkgs/build-support/bintools-wrapper/setup-hook.sh @@ -1,4 +1,3 @@ -# shellcheck shell=bash # Binutils Wrapper hygiene # # See comments in cc-wrapper's setup hook. This works exactly the same way. @@ -15,9 +14,7 @@ bintoolsWrapper_addLDVars () { getHostRoleEnvHook if [[ -d "$1/lib64" && ! -L "$1/lib64" ]]; then - varName=NIX_LDFLAGS${role_post} - eval "$varName=\"${!varName:-} -L$1/lib64\"" - export "${varName?}" + export NIX_LDFLAGS${role_post}+=" -L$1/lib64" fi if [[ -d "$1/lib" ]]; then @@ -27,9 +24,7 @@ bintoolsWrapper_addLDVars () { # directories and bloats the size of the environment variable space. local -a glob=( $1/lib/lib* ) if [ "${#glob[*]}" -gt 0 ]; then - varName=NIX_LDFLAGS${role_post} - eval "$varName=\"${!varName:-} -L$1/lib\"" - export "${varName?}" + export NIX_LDFLAGS${role_post}+=" -L$1/lib" fi fi } diff --git a/pkgs/build-support/setup-hooks/auto-patchelf.sh b/pkgs/build-support/setup-hooks/auto-patchelf.sh index 70b1fc802b56..511371931de8 100644 --- a/pkgs/build-support/setup-hooks/auto-patchelf.sh +++ b/pkgs/build-support/setup-hooks/auto-patchelf.sh @@ -29,7 +29,6 @@ isExecutable() { isExeResult="$(LANG=C $READELF -h -l "$1" 2> /dev/null \ | grep '^ *Type: *EXEC\>\|^ *INTERP\>')" # not using grep -q, because it can cause Broken pipe - # https://unix.stackexchange.com/questions/305547/broken-pipe-when-grepping-output-but-only-with-i-flag [ -n "$isExeResult" ] } diff --git a/pkgs/build-support/setup-hooks/autoreconf.sh b/pkgs/build-support/setup-hooks/autoreconf.sh index 4ba4025a02e6..c08cab158688 100644 --- a/pkgs/build-support/setup-hooks/autoreconf.sh +++ b/pkgs/build-support/setup-hooks/autoreconf.sh @@ -1,5 +1,4 @@ -# shellcheck shell=bash -preConfigurePhases="${preConfigurePhases:-} autoreconfPhase" +preConfigurePhases+=" autoreconfPhase" autoreconfPhase() { runHook preAutoreconf diff --git a/pkgs/build-support/setup-hooks/make-symlinks-relative.sh b/pkgs/build-support/setup-hooks/make-symlinks-relative.sh index fd65f2e8e13b..0608d3ca81c4 100644 --- a/pkgs/build-support/setup-hooks/make-symlinks-relative.sh +++ b/pkgs/build-support/setup-hooks/make-symlinks-relative.sh @@ -1,4 +1,3 @@ -# shellcheck shell=bash fixupOutputHooks+=(_makeSymlinksRelative) # For every symlink in $output that refers to another file in $output diff --git a/pkgs/build-support/setup-hooks/move-docs.sh b/pkgs/build-support/setup-hooks/move-docs.sh index 965c16be2f62..ef31dcdce274 100644 --- a/pkgs/build-support/setup-hooks/move-docs.sh +++ b/pkgs/build-support/setup-hooks/move-docs.sh @@ -6,7 +6,7 @@ preFixupHooks+=(_moveToShare) _moveToShare() { forceShare=${forceShare:=man doc info} - if [[ -z $forceShare || -z $out ]]; then return; fi + if [ -z "$forceShare" -o -z "$out" ]; then return; fi for d in $forceShare; do if [ -d "$out/$d" ]; then @@ -14,9 +14,10 @@ _moveToShare() { echo "both $d/ and share/$d/ exist!" else echo "moving $out/$d to $out/share/$d" - mkdir -p "$out/share" - mv "$out/$d" "$out/share/" + mkdir -p $out/share + mv $out/$d $out/share/ fi fi done } + diff --git a/pkgs/build-support/setup-hooks/multiple-outputs.sh b/pkgs/build-support/setup-hooks/multiple-outputs.sh index 91f056cc89bd..bfa47e3b20e1 100644 --- a/pkgs/build-support/setup-hooks/multiple-outputs.sh +++ b/pkgs/build-support/setup-hooks/multiple-outputs.sh @@ -1,4 +1,3 @@ -# shellcheck shell=bash # The base package for automatic multiple-output splitting. Used in stdenv as well. preConfigureHooks+=(_multioutConfig) preFixupHooks+=(_multioutDocs) @@ -48,25 +47,22 @@ _overrideFirst outputInfo "info" "$outputBin" # Add standard flags to put files into the desired outputs. _multioutConfig() { - if [[ "$outputs" = "out" || -z "${setOutputFlags-1}" ]]; then - return - fi + if [ "$outputs" = "out" ] || [ -z "${setOutputFlags-1}" ]; then return; fi; # try to detect share/doc/${shareDocName} # Note: sadly, $configureScript detection comes later in configurePhase, # and reordering would cause more trouble than worth. if [ -z "$shareDocName" ]; then local confScript="$configureScript" - if [[ -z "$confScript" && -x ./configure ]]; then + if [ -z "$confScript" ] && [ -x ./configure ]; then confScript=./configure fi if [ -f "$confScript" ]; then local shareDocName="$(sed -n "s/^PACKAGE_TARNAME='\(.*\)'$/\1/p" < "$confScript")" - # PACKAGE_TARNAME sometimes contains garbage. - # verify that shareDocName contains only valid characters - if ! [[ $shareDocName =~ ^[a-zA-Z0f9_-]+$ ]]; then - shareDocName="$(echo "$name" | sed 's/-[^a-zA-Z].*//')" - fi + fi + # PACKAGE_TARNAME sometimes contains garbage. + if [ -z "$shareDocName" ] || echo "$shareDocName" | grep -q '[^a-zA-Z0-9_-]'; then + shareDocName="$(echo "$name" | sed 's/-[^a-zA-Z].*//')" fi fi diff --git a/pkgs/build-support/setup-hooks/reproducible-builds.sh b/pkgs/build-support/setup-hooks/reproducible-builds.sh index 29efd22d9051..5b01c213fe4a 100644 --- a/pkgs/build-support/setup-hooks/reproducible-builds.sh +++ b/pkgs/build-support/setup-hooks/reproducible-builds.sh @@ -1,13 +1,9 @@ -# shellcheck disable=SC2148 # Use the last part of the out path as hash input for the build. # This should ensure that it is deterministic across rebuilds of the same # derivation and not easily collide with other builds. # We also truncate the hash so that it cannot cause reference cycles. -# NIX_CFLAGS_COMPILE might not have been defined before -NIX_CFLAGS_COMPILE="${NIX_CFLAGS_COMPILE:-} -frandom-seed=$( - # shellcheck disable=SC2154 +export NIX_CFLAGS_COMPILE+=" -frandom-seed=$( outbase="${out##*/}" randomseed="${outbase:0:10}" - echo "$randomseed" + echo $randomseed )" -export NIX_CFLAGS_COMPILE diff --git a/pkgs/stdenv/generic/builder.sh b/pkgs/stdenv/generic/builder.sh index 986d94943c59..79bf21ab4730 100644 --- a/pkgs/stdenv/generic/builder.sh +++ b/pkgs/stdenv/generic/builder.sh @@ -4,20 +4,18 @@ for i in $initialPath; do PATH=$PATH${PATH:+:}$i/bin done -mkdir "$out" +mkdir $out -{ - echo "export SHELL=$shell" - echo "initialPath=\"$initialPath\"" - echo "defaultNativeBuildInputs=\"$defaultNativeBuildInputs\"" - echo "defaultBuildInputs=\"$defaultBuildInputs\"" - echo "$preHook" - cat "$setup" -} > "$out/setup" +echo "export SHELL=$shell" > $out/setup +echo "initialPath=\"$initialPath\"" >> $out/setup +echo "defaultNativeBuildInputs=\"$defaultNativeBuildInputs\"" >> $out/setup +echo "defaultBuildInputs=\"$defaultBuildInputs\"" >> $out/setup +echo "$preHook" >> $out/setup +cat "$setup" >> $out/setup # Allow the user to install stdenv using nix-env and get the packages # in stdenv. mkdir $out/nix-support -if [ -n "${propagatedUserEnvPkgs:-}" ]; then +if [ "$propagatedUserEnvPkgs" ]; then printf '%s ' $propagatedUserEnvPkgs > $out/nix-support/propagated-user-env-packages fi diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 4ae561fbca07..066ef6ed9eb3 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -1,4 +1,3 @@ -# shellcheck shell=bash set -eu set -o pipefail @@ -12,7 +11,7 @@ if (( "${NIX_DEBUG:-0}" >= 6 )); then set -x fi -: "${outputs:=out}" +: ${outputs:=out} ###################################################################### @@ -69,8 +68,7 @@ _callImplicitHook() { local hookName="$2" if declare -F "$hookName" > /dev/null; then "$hookName" - elif test -e "$hookName" ; then - # shellcheck disable=SC1090 + elif type -p "$hookName" > /dev/null; then source "$hookName" elif [ -n "${!hookName:-}" ]; then eval "${!hookName}" @@ -124,14 +122,13 @@ exitHandler() { if [ -n "${showBuildStats:-}" ]; then times > "$NIX_BUILD_TOP/.times" - local -a buildTimesArray - IFS=" " read -r -a buildTimesArray < "$NIX_BUILD_TOP/.times" + local -a times=($(cat "$NIX_BUILD_TOP/.times")) # Print the following statistics: # - user time for the shell # - system time for the shell # - user time for all child processes # - system time for all child processes - echo "build time elapsed: " "${buildTimesArray[@]}" + echo "build time elapsed: " "${times[@]}" fi if (( "$exitCode" != 0 )); then @@ -143,7 +140,6 @@ exitHandler() { # normally. Otherwise, return the original exit code. if [ -n "${succeedOnFailure:-}" ]; then echo "build failed with exit code $exitCode (ignored)" - # shellcheck disable=SC2154 mkdir -p "$out/nix-support" printf "%s" "$exitCode" > "$out/nix-support/failed" exit 0 @@ -236,7 +232,7 @@ printWords() { # implementation uses zip archive and zip does not support dates going back to # 1970. export SOURCE_DATE_EPOCH -: "${SOURCE_DATE_EPOCH:=315532800}" +: ${SOURCE_DATE_EPOCH:=315532800} # Wildcard expansions that don't match should expand to an empty list. @@ -246,10 +242,8 @@ shopt -s nullglob # Set up the initial path. -# shellcheck disable=SC2123 PATH= HOST_PATH= -# shellcheck disable=SC2154 for i in $initialPath; do if [ "$i" = / ]; then i=; fi addToSearchPath PATH "$i/bin" @@ -312,10 +306,6 @@ declare -a pkgTargetHookVars=(envTargetTargetHook) declare -a pkgHookVarVars=(pkgBuildHookVars pkgHostHookVars pkgTargetHookVars) -# those variables are declared here, since where and if they are used varies -# shellcheck disable=SC2034 -declare -a preFixupHooks fixupOutputHooks preConfigureHooks postFixupHooks postUnpackHooks unpackCmdHooks - # Add env hooks for all sorts of deps with the specified host offset. addEnvHooks() { local depHostOffset="$1" @@ -357,14 +347,14 @@ declare -a allPlatOffsets=(-1 0 1) # implements. findInputs() { local -r pkg="$1" - local -r hostOffset="$2" - local -r targetOffset="$3" + local -ri hostOffset="$2" + local -ri targetOffset="$3" # Sanity check - (( "$hostOffset" <= "$targetOffset" )) || exit 1 + (( "$hostOffset" <= "$targetOffset" )) || exit -1 - local varVar="${pkgAccumVarVars[$(( hostOffset + 1 ))]}" - local varRef="${varVar}[$(( targetOffset - hostOffset ))]" + local varVar="${pkgAccumVarVars[$hostOffset + 1]}" + local varRef="$varVar[\$targetOffset - \$hostOffset]" local var="${!varRef}" unset -v varVar varRef @@ -372,7 +362,7 @@ findInputs() { # nix-shell doesn't use impure bash. This should replace the O(n) # case with an O(1) hash map lookup, assuming bash is implemented # well :D. - local varSlice="${var}[*]" + local varSlice="$var[*]" # ${..-} to hack around old bash empty array problem case "${!varSlice-}" in *" $pkg "*) return 0 ;; @@ -389,28 +379,28 @@ findInputs() { # The current package's host and target offset together # provide a <=-preserving homomorphism from the relative # offsets to current offset - local mapOffsetResult + local -i mapOffsetResult function mapOffset() { - local -r inputOffset="$1" + local -ri inputOffset="$1" if (( "$inputOffset" <= 0 )); then - local -r outputOffset=$(( inputOffset + hostOffset )) + local -ri outputOffset="$inputOffset + $hostOffset" else - local -r outputOffset=$(( inputOffset - 1 + targetOffset )) + local -ri outputOffset="$inputOffset - 1 + $targetOffset" fi mapOffsetResult="$outputOffset" } # Host offset relative to that of the package whose immediate # dependencies we are currently exploring. - local relHostOffset + local -i relHostOffset for relHostOffset in "${allPlatOffsets[@]}"; do # `+ 1` so we start at 0 for valid index - local files="${propagatedDepFilesVars[$(( relHostOffset + 1 ))]}" + local files="${propagatedDepFilesVars[$relHostOffset + 1]}" # Host offset relative to the package currently being # built---as absolute an offset as will be used. - mapOffset "$relHostOffset" - local hostOffsetNext="$mapOffsetResult" + mapOffset relHostOffset + local -i hostOffsetNext="$mapOffsetResult" # Ensure we're in bounds relative to the package currently # being built. @@ -418,18 +408,18 @@ findInputs() { # Target offset relative to the *host* offset of the package # whose immediate dependencies we are currently exploring. - local relTargetOffset + local -i relTargetOffset for relTargetOffset in "${allPlatOffsets[@]}"; do (( "$relHostOffset" <= "$relTargetOffset" )) || continue - local fileRef="${files}[$(( relTargetOffset - relHostOffset ))]" + local fileRef="${files}[$relTargetOffset - $relHostOffset]" local file="${!fileRef}" unset -v fileRef # Target offset relative to the package currently being # built. - mapOffset "$relTargetOffset" - local targetOffsetNext="$mapOffsetResult" + mapOffset relTargetOffset + local -i targetOffsetNext="$mapOffsetResult" # Once again, ensure we're in bounds relative to the # package currently being built. @@ -447,12 +437,12 @@ findInputs() { } # Make sure all are at least defined as empty -: "${depsBuildBuild=}" "${depsBuildBuildPropagated=}" -: "${nativeBuildInputs=}" "${propagatedNativeBuildInputs=}" "${defaultNativeBuildInputs=}" -: "${depsBuildTarget=}" "${depsBuildTargetPropagated=}" -: "${depsHostHost=}" "${depsHostHostPropagated=}" -: "${buildInputs=}" "${propagatedBuildInputs=}" "${defaultBuildInputs=}" -: "${depsTargetTarget=}" "${depsTargetTargetPropagated=}" +: ${depsBuildBuild=} ${depsBuildBuildPropagated=} +: ${nativeBuildInputs=} ${propagatedNativeBuildInputs=} ${defaultNativeBuildInputs=} +: ${depsBuildTarget=} ${depsBuildTargetPropagated=} +: ${depsHostHost=} ${depsHostHostPropagated=} +: ${buildInputs=} ${propagatedBuildInputs=} ${defaultBuildInputs=} +: ${depsTargetTarget=} ${depsTargetTargetPropagated=} for pkg in $depsBuildBuild $depsBuildBuildPropagated; do findInputs "$pkg" -1 -1 @@ -483,14 +473,13 @@ done # Add package to the future PATH and run setup hooks activatePackage() { local pkg="$1" - local -r hostOffset="$2" - local -r targetOffset="$3" + local -ri hostOffset="$2" + local -ri targetOffset="$3" # Sanity check - (( "$hostOffset" <= "$targetOffset" )) || exit 1 + (( "$hostOffset" <= "$targetOffset" )) || exit -1 if [ -f "$pkg" ]; then - # shellcheck disable=SC1090 source "$pkg" fi @@ -498,7 +487,7 @@ activatePackage() { # build platform are included here. That would be `depsBuild*`, # and legacy `nativeBuildInputs`, in general. If we aren't cross # compiling, however, everything can be put on the PATH. To ease - # the transition, we do include everything in that case. + # the transition, we do include everything in thatcase. # # TODO(@Ericson2314): Don't special-case native compilation if [[ -z "${strictDeps-}" || "$hostOffset" -le -1 ]]; then @@ -514,19 +503,19 @@ activatePackage() { fi if [[ -f "$pkg/nix-support/setup-hook" ]]; then - # shellcheck disable=SC1091 source "$pkg/nix-support/setup-hook" fi } _activatePkgs() { - local hostOffset targetOffset pkg + local -i hostOffset targetOffset + local pkg for hostOffset in "${allPlatOffsets[@]}"; do - local pkgsVar="${pkgAccumVarVars[$(( hostOffset + 1 ))]}" + local pkgsVar="${pkgAccumVarVars[$hostOffset + 1]}" for targetOffset in "${allPlatOffsets[@]}"; do (( "$hostOffset" <= "$targetOffset" )) || continue - local pkgsRef="${pkgsVar}[$(( targetOffset - hostOffset ))]" + local pkgsRef="${pkgsVar}[$targetOffset - $hostOffset]" local pkgsSlice="${!pkgsRef}[@]" for pkg in ${!pkgsSlice+"${!pkgsSlice}"}; do activatePackage "$pkg" "$hostOffset" "$targetOffset" @@ -547,14 +536,15 @@ _activatePkgs # with this information to the relevant env hook array, but bash # doesn't have closures, so it's easier to just pass this in. _addToEnv() { - local depHostOffset depTargetOffset pkg + local -i depHostOffset depTargetOffset + local pkg for depHostOffset in "${allPlatOffsets[@]}"; do - local hookVar="${pkgHookVarVars[$(( depHostOffset + 1 ))]}" - local pkgsVar="${pkgAccumVarVars[$(( depHostOffset + 1 ))]}" + local hookVar="${pkgHookVarVars[$depHostOffset + 1]}" + local pkgsVar="${pkgAccumVarVars[$depHostOffset + 1]}" for depTargetOffset in "${allPlatOffsets[@]}"; do (( "$depHostOffset" <= "$depTargetOffset" )) || continue - local hookRef="${hookVar}[$(( depTargetOffset - depHostOffset ))]" + local hookRef="${hookVar}[$depTargetOffset - $depHostOffset]" if [[ -z "${strictDeps-}" ]]; then # Keep track of which packages we have visited before. @@ -565,12 +555,12 @@ _addToEnv() { # # TODO(@Ericson2314): Don't special-case native compilation for pkg in \ - "${pkgsBuildBuild[@]}" \ - "${pkgsBuildHost[@]}" \ - "${pkgsBuildTarget[@]}" \ - "${pkgsHostHost[@]}" \ - "${pkgsHostTarget[@]}" \ - "${pkgsTargetTarget[@]}" + ${pkgsBuildBuild+"${pkgsBuildBuild[@]}"} \ + ${pkgsBuildHost+"${pkgsBuildHost[@]}"} \ + ${pkgsBuildTarget+"${pkgsBuildTarget[@]}"} \ + ${pkgsHostHost+"${pkgsHostHost[@]}"} \ + ${pkgsHostTarget+"${pkgsHostTarget[@]}"} \ + ${pkgsTargetTarget+"${pkgsTargetTarget[@]}"} do if [[ "$visitedPkgs" = *"$pkg"* ]]; then continue @@ -579,7 +569,7 @@ _addToEnv() { visitedPkgs+=" $pkg" done else - local pkgsRef="${pkgsVar}[$(( depTargetOffset - depHostOffset ))]" + local pkgsRef="${pkgsVar}[$depTargetOffset - $depHostOffset]" local pkgsSlice="${!pkgsRef}[@]" for pkg in ${!pkgsSlice+"${!pkgsSlice}"}; do runHook "${!hookRef}" "$pkg" @@ -645,7 +635,7 @@ export NIX_INDENT_MAKE=1 if [ -z "${NIX_BUILD_CORES:-}" ]; then NIX_BUILD_CORES="1" -elif (( "$NIX_BUILD_CORES" <= 0 )); then +elif [ "$NIX_BUILD_CORES" -le 0 ]; then NIX_BUILD_CORES=$(nproc 2>/dev/null || true) if expr >/dev/null 2>&1 "$NIX_BUILD_CORES" : "^[0-9][0-9]*$"; then : @@ -658,11 +648,11 @@ export NIX_BUILD_CORES # Prevent SSL libraries from using certificates in /etc/ssl, unless set explicitly. # Leave it in impure shells for convenience. -if [[ -z "${NIX_SSL_CERT_FILE:-}" && "${IN_NIX_SHELL:-}" != "impure" ]]; then +if [ -z "${NIX_SSL_CERT_FILE:-}" ] && [ "${IN_NIX_SHELL:-}" != "impure" ]; then export NIX_SSL_CERT_FILE=/no-cert-file.crt fi # Another variant left for compatibility. -if [[ -z "${SSL_CERT_FILE:-}" && "${IN_NIX_SHELL:-}" != "impure" ]]; then +if [ -z "${SSL_CERT_FILE:-}" ] && [ "${IN_NIX_SHELL:-}" != "impure" ]; then export SSL_CERT_FILE=/no-cert-file.crt fi @@ -728,7 +718,6 @@ substituteStream() { consumeEntire() { # read returns non-0 on EOF, so we want read to fail - # shellcheck disable=SC2086 if IFS='' read -r -N 0 $1; then echo "consumeEntire(): ERROR: Input null bytes, won't process" >&2 return 1 @@ -900,7 +889,7 @@ unpackPhase() { # Find the source directory. # set to empty if unset - : "${sourceRoot=}" + : ${sourceRoot=} if [ -n "${setSourceRoot:-}" ]; then runOneHook setSourceRoot @@ -978,8 +967,8 @@ configurePhase() { runHook preConfigure # set to empty if unset - : "${configureScript=}" - : "${configureFlags=}" + : ${configureScript=} + : ${configureFlags=} if [[ -z "$configureScript" && -x ./configure ]]; then configureScript=./configure @@ -997,27 +986,25 @@ configurePhase() { configureFlags="${prefixKey:---prefix=}$prefix $configureFlags" fi - if [ -f "$configureScript" ]; then - # Add --disable-dependency-tracking to speed up some builds. - if [[ -z ${dontAddDisableDepTrack:-} ]]; then - if grep -q dependency-tracking "$configureScript"; then - configureFlags="--disable-dependency-tracking $configureFlags" - fi + # Add --disable-dependency-tracking to speed up some builds. + if [ -z "${dontAddDisableDepTrack:-}" ]; then + if [ -f "$configureScript" ] && grep -q dependency-tracking "$configureScript"; then + configureFlags="--disable-dependency-tracking $configureFlags" fi + fi - # By default, disable static builds. - if [[ -z ${dontDisableStatic:-} ]]; then - if grep -q enable-static "$configureScript"; then - configureFlags="--disable-static $configureFlags" - fi + # By default, disable static builds. + if [ -z "${dontDisableStatic:-}" ]; then + if [ -f "$configureScript" ] && grep -q enable-static "$configureScript"; then + configureFlags="--disable-static $configureFlags" fi fi if [ -n "$configureScript" ]; then - IFS=" " read -r -a configureFlagsTemp <<< "$configureFlags" - local -a flagsArray=( - "${configureFlagsTemp[@]}" - "${configureFlagsArray[@]}" + # Old bash empty array hack + # shellcheck disable=SC2086 + local flagsArray=( + $configureFlags ${configureFlagsArray+"${configureFlagsArray[@]}"} ) echoCmd 'configure flags' "${flagsArray[@]}" # shellcheck disable=SC2086 @@ -1035,22 +1022,20 @@ buildPhase() { runHook preBuild # set to empty if unset - : "${makeFlags=}" + : ${makeFlags=} if [[ -z "$makeFlags" && -z "${makefile:-}" && ! ( -e Makefile || -e makefile || -e GNUmakefile ) ]]; then echo "no Makefile, doing nothing" else foundMakefile=1 - IFS=" " read -r -a makeFlagsTemp <<< "$makeFlags" - # shellcheck disable=SC2154 - IFS=" " read -r -a buildFlagsTemp <<< "$buildFlags" - local -a flagsArray=( + + # Old bash empty array hack + # shellcheck disable=SC2086 + local flagsArray=( ${enableParallelBuilding:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} - SHELL="$SHELL" - "${makeFlagsTemp[@]}" - "${makeFlagsArray[@]}" - "${buildFlagsTemp[@]}" - "${buildFlagsArray[@]}" + SHELL=$SHELL + $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"} + $buildFlags ${buildFlagsArray+"${buildFlagsArray[@]}"} ) echoCmd 'build flags' "${flagsArray[@]}" @@ -1074,26 +1059,23 @@ checkPhase() { if [[ -z "${checkTarget:-}" ]]; then #TODO(@oxij): should flagsArray influence make -n? if make -n ${makefile:+-f $makefile} check >/dev/null 2>&1; then - checkTarget="check" + checkTarget=check elif make -n ${makefile:+-f $makefile} test >/dev/null 2>&1; then - checkTarget="test" + checkTarget=test fi fi if [[ -z "${checkTarget:-}" ]]; then echo "no check/test target in ${makefile:-Makefile}, doing nothing" else - IFS=" " read -r -a makeFlagsTemp <<< "$makeFlags" - IFS=" " read -r -a checkFlagsTemp <<< "${checkFlags:-VERBOSE=y}" - IFS=" " read -r -a checkTargetTemp <<< "${checkTarget}" - local -a flagsArray=( + # Old bash empty array hack + # shellcheck disable=SC2086 + local flagsArray=( ${enableParallelChecking:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} - SHELL="$SHELL" - "${makeFlagsTemp[@]}" - "${makeFlagsArray[@]}" - "${checkFlagsTemp[@]}" - "${checkFlagsArray[@]}" - "${checkTargetTemp[@]}" + SHELL=$SHELL + $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"} + ${checkFlags:-VERBOSE=y} ${checkFlagsArray+"${checkFlagsArray[@]}"} + ${checkTarget} ) echoCmd 'check flags' "${flagsArray[@]}" @@ -1112,18 +1094,14 @@ installPhase() { if [ -n "$prefix" ]; then mkdir -p "$prefix" fi - IFS=" " read -r -a makeFlagsTemp <<< "$makeFlags" - # shellcheck disable=SC2154 - IFS=" " read -r -a installFlagsTemp <<< "$installFlags" - # shellcheck disable=SC2154 - IFS=" " read -r -a installTargetsTemp <<< "${installTargets:-install}" - local -a flagsArray=( - SHELL="$SHELL" - "${makeFlagsTemp[@]}" - "${makeFlagsArray[@]}" - "${installFlagsTemp[@]}" - "${installFlagsArray[@]}" - "${installTargetsTemp[@]}" + + # Old bash empty array hack + # shellcheck disable=SC2086 + local flagsArray=( + SHELL=$SHELL + $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"} + $installFlags ${installFlagsArray+"${installFlagsArray[@]}"} + ${installTargets:-install} ) echoCmd 'install flags' "${flagsArray[@]}" @@ -1178,7 +1156,6 @@ fixupPhase() { [[ "${!propagatedInputsSlice}" ]] || continue - # shellcheck disable=SC2154 mkdir -p "${!outputDev}/nix-support" # shellcheck disable=SC2086 printWords ${!propagatedInputsSlice} > "${!outputDev}/nix-support/$propagatedInputsFile" @@ -1195,8 +1172,6 @@ fixupPhase() { mkdir -p "${!outputDev}/nix-support" local hook for hook in $setupHooks; do - # content is being assigned to in the following lines - # shellcheck disable=SC2034 local content consumeEntire content < "$hook" substituteAllStream content "file '$hook'" >> "${!outputDev}/nix-support/setup-hook" @@ -1208,7 +1183,6 @@ fixupPhase() { # Propagate user-env packages into the output with binaries, TODO? if [ -n "${propagatedUserEnvPkgs:-}" ]; then - # shellcheck disable=SC2154 mkdir -p "${!outputBin}/nix-support" # shellcheck disable=SC2086 printWords $propagatedUserEnvPkgs > "${!outputBin}/nix-support/propagated-user-env-packages" @@ -1225,21 +1199,17 @@ installCheckPhase() { echo "no Makefile or custom installCheckPhase, doing nothing" #TODO(@oxij): should flagsArray influence make -n? elif [[ -z "${installCheckTarget:-}" ]] \ - && ! make -n ${makefile:+-f $makefile} "${installCheckTarget:-installcheck}" >/dev/null 2>&1; then + && ! make -n ${makefile:+-f $makefile} ${installCheckTarget:-installcheck} >/dev/null 2>&1; then echo "no installcheck target in ${makefile:-Makefile}, doing nothing" else - IFS=" " read -r -a makeFlagsTemp <<< "$makeFlags" - # shellcheck disable=SC2154 - IFS=" " read -r -a installCheckFlagsTemp <<< "$installCheckFlags" - IFS=" " read -r -a installCheckTargetTemp <<< "${installCheckTarget:-installcheck}" - local -a flagsArray=( + # Old bash empty array hack + # shellcheck disable=SC2086 + local flagsArray=( ${enableParallelChecking:+-j${NIX_BUILD_CORES} -l${NIX_BUILD_CORES}} - SHELL="$SHELL" - "${makeFlagsTemp[@]}" - "${makeFlagsArray[@]}" - "${installCheckFlagsTemp[@]}" - "${installCheckFlagsArray[@]}" - "${installCheckTargetTemp[@]}" + SHELL=$SHELL + $makeFlags ${makeFlagsArray+"${makeFlagsArray[@]}"} + $installCheckFlags ${installCheckFlagsArray+"${installCheckFlagsArray[@]}"} + ${installCheckTarget:-installcheck} ) echoCmd 'installcheck flags' "${flagsArray[@]}" @@ -1254,13 +1224,10 @@ installCheckPhase() { distPhase() { runHook preDist - # shellcheck disable=SC2154 - IFS=" " read -r -a distFlagsTemp <<< "$distFlags" - + # Old bash empty array hack + # shellcheck disable=SC2086 local flagsArray=( - "${distFlagsTemp[@]}" - ${distFlagsArray+"${distFlagsArray[@]}"} - "${distTarget:-dist}" + $distFlags ${distFlagsArray+"${distFlagsArray[@]}"} ${distTarget:-dist} ) echo 'dist flags: %q' "${flagsArray[@]}" @@ -1297,7 +1264,6 @@ showPhaseHeader() { genericBuild() { if [ -f "${buildCommandPath:-}" ]; then - # shellcheck disable=SC1090 source "$buildCommandPath" return fi @@ -1325,7 +1291,7 @@ genericBuild() { if [[ "$curPhase" = distPhase && -z "${doDist:-}" ]]; then continue; fi if [[ -n $NIX_LOG_FD ]]; then - echo "@nix { \"action\": \"setPhase\", \"phase\": \"$curPhase\" }" >&"$NIX_LOG_FD" + echo "@nix { \"action\": \"setPhase\", \"phase\": \"$curPhase\" }" >&$NIX_LOG_FD fi showPhaseHeader "$curPhase"