Skip to content

Commit

Permalink
stdenv-setup: Remove useless quotes
Browse files Browse the repository at this point in the history
foo=$1 surprisingly doesn't need quotes in Bash. Word splits are only
syntactic in string variable (not array var!) assignments.
  • Loading branch information
Ericson2314 committed Jul 13, 2017
1 parent 273a4c1 commit 2743078
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions pkgs/stdenv/generic/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ set -o pipefail
# code). The hooks for <hookName> are the shell function or variable
# <hookName>, and the values of the shell array ‘<hookName>Hooks’.
runHook() {
local hookName="$1"
local hookName=$1
shift
local var="$hookName"
if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
if [[ $hookName =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
local -n var
local hook
for hook in "_callImplicitHook 0 $hookName" "${var[@]}"; do
Expand All @@ -29,10 +29,10 @@ runHook() {
# Run all hooks with the specified name, until one succeeds (returns a
# zero exit code). If none succeed, return a non-zero exit code.
runOneHook() {
local hookName="$1"
local hookName=$1
shift
local var="$hookName"
if [[ "$hookName" =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
if [[ $hookName =~ Hook$ ]]; then var+=s; else var+=Hooks; fi
local -n var
local hook
for hook in "_callImplicitHook 1 $hookName" "${var[@]}"; do
Expand All @@ -50,8 +50,8 @@ runOneHook() {
# environment variables) and from shell scripts (as functions). If you
# want to allow multiple hooks, use runHook instead.
_callImplicitHook() {
local def="$1"
local hookName="$2"
local def=$1
local hookName=$2
case "$(type -t "$hookName")" in
(function|alias|builtin) "$hookName";;
(file) source "$hookName";;
Expand All @@ -64,7 +64,7 @@ _callImplicitHook() {
# A function wrapper around ‘eval’ that ensures that ‘return’ inside
# hooks exits the hook, not the caller.
_eval() {
local code="$1"
local code=$1
shift
if [ "$(type -t "$code")" = function ]; then
eval "$code \"\$@\""
Expand Down Expand Up @@ -195,26 +195,26 @@ _addRpathPrefix() {

# Return success if the specified file is an ELF object.
isELF() {
local fn="$1"
local fn=$1
local fd
local magic
exec {fd}< "$fn"
read -r -n 4 -u $fd magic
exec {fd}<&-
if [[ "$magic" =~ ELF ]]; then return 0; else return 1; fi
if [[ $magic =~ ELF ]]; then return 0; else return 1; fi
}

# Return success if the specified file is a script (i.e. starts with
# "#!").
isScript() {
local fn="$1"
local fn=$1
local fd
local magic
if ! [ -x /bin/sh ]; then return 0; fi
exec {fd}< "$fn"
read -r -n 2 -u $fd magic
exec {fd}<&-
if [[ "$magic" =~ \#! ]]; then return 0; else return 1; fi
if [[ $magic =~ \#! ]]; then return 0; else return 1; fi
}

# printf unfortunately will print a trailing newline regardless
Expand Down Expand Up @@ -255,8 +255,8 @@ fi

# Check that the pre-hook initialised SHELL.
if [ -z "$SHELL" ]; then echo "SHELL not set"; exit 1; fi
BASH="$SHELL"
export CONFIG_SHELL="$SHELL"
BASH=$SHELL
export CONFIG_SHELL=$SHELL


# Dummy implementation of the paxmark function. On Linux, this is
Expand All @@ -283,7 +283,7 @@ findInputs() {
local propagatedBuildInputsFile=$3

# Stop if we've already added this one
[[ -z "${varDeref["$pkg"]}" ]] || return 0
[[ -z ${varDeref[$pkg]} ]] || return 0
varDeref["$pkg"]=1

if ! [ -e "$pkg" ]; then
Expand Down Expand Up @@ -373,7 +373,7 @@ export TZ=UTC
# for instance if we just want to perform a test build/install to a
# temporary location and write a build report to $out.
if [ -z "$prefix" ]; then
prefix="$out";
prefix=$out;
fi

if [ "$useTempPrefix" = 1 ]; then
Expand Down Expand Up @@ -449,7 +449,7 @@ substitute() {
local varName=$2
shift 2
# check if the used nix attribute name is a valid bash name
if ! [[ "$varName" =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]; then
if ! [[ $varName =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]]; then
echo "${FUNCNAME[0]}(): WARNING: substitution variables should be valid bash names," >&2
echo " \"$varName\" isn't and therefore was skipped; it might be caused" >&2
echo " by multi-line phases in variables - see #14907 for details." >&2
Expand Down Expand Up @@ -480,7 +480,7 @@ substitute() {


substituteInPlace() {
local fileName="$1"
local fileName=$1
shift
substitute "$fileName" "$fileName" "$@"
}
Expand All @@ -490,8 +490,8 @@ substituteInPlace() {
# character or underscore. Note: other names that aren't bash-valid
# will cause an error during `substitute --subst-var`.
substituteAll() {
local input="$1"
local output="$2"
local input=$1
local output=$2
local -a args=()

# Select all environment variables that start with a lowercase character.
Expand All @@ -507,7 +507,7 @@ substituteAll() {


substituteAllInPlace() {
local fileName="$1"
local fileName=$1
shift
substituteAll "$fileName" "$fileName" "$@"
}
Expand All @@ -534,7 +534,7 @@ dumpVars() {
stripHash() {
local strippedName
# On separate line for `set -e`
strippedName="$(basename "$1")"
strippedName=$(basename "$1")
if echo "$strippedName" | grep -q '^[a-z0-9]\{32\}-'; then
echo "$strippedName" | cut -c34-
else
Expand All @@ -545,7 +545,7 @@ stripHash() {

unpackCmdHooks+=(_defaultUnpack)
_defaultUnpack() {
local fn="$1"
local fn=$1

if [ -d "$fn" ]; then

Expand Down Expand Up @@ -576,7 +576,7 @@ _defaultUnpack() {


unpackFile() {
curSrc="$1"
curSrc=$1
header "unpacking source archive $curSrc" 3
if ! runOneHook unpackCmd "$curSrc"; then
echo "do not know how to unpack source archive $curSrc"
Expand All @@ -595,7 +595,7 @@ unpackPhase() {
echo 'variable $src or $srcs should point to the source'
exit 1
fi
srcs="$src"
srcs=$src
fi

# To determine the source directory created by unpacking the
Expand Down Expand Up @@ -629,7 +629,7 @@ unpackPhase() {
echo "unpacker produced multiple directories"
exit 1
fi
sourceRoot="$i"
sourceRoot=$i
;;
esac
fi
Expand Down Expand Up @@ -692,7 +692,7 @@ fixLibtool() {
configurePhase() {
runHook preConfigure

if [[ -z "$configureScript" && -x ./configure ]]; then
if [[ -z $configureScript && -x ./configure ]]; then
configureScript=./configure
fi

Expand All @@ -704,7 +704,7 @@ configurePhase() {
done
fi

if [[ -z "$dontAddPrefix" && -n "$prefix" ]]; then
if [[ -z $dontAddPrefix && -n $prefix ]]; then
configureFlags="${prefixKey:---prefix=}$prefix $configureFlags"
fi

Expand Down Expand Up @@ -912,7 +912,7 @@ distPhase() {


showPhaseHeader() {
local phase="$1"
local phase=$1
case $phase in
unpackPhase) header "unpacking sources";;
patchPhase) header "patching sources";;
Expand Down Expand Up @@ -945,14 +945,14 @@ genericBuild() {
fi

for curPhase in $phases; do
if [[ "$curPhase" = buildPhase && -n "$dontBuild" ]]; then continue; fi
if [[ "$curPhase" = checkPhase && -z "$doCheck" ]]; then continue; fi
if [[ "$curPhase" = installPhase && -n "$dontInstall" ]]; then continue; fi
if [[ "$curPhase" = fixupPhase && -n "$dontFixup" ]]; then continue; fi
if [[ "$curPhase" = installCheckPhase && -z "$doInstallCheck" ]]; then continue; fi
if [[ "$curPhase" = distPhase && -z "$doDist" ]]; then continue; fi

if [[ -n "$tracePhases" ]]; then
if [[ $curPhase = buildPhase && -n $dontBuild ]]; then continue; fi
if [[ $curPhase = checkPhase && -z $doCheck ]]; then continue; fi
if [[ $curPhase = installPhase && -n $dontInstall ]]; then continue; fi
if [[ $curPhase = fixupPhase && -n $dontFixup ]]; then continue; fi
if [[ $curPhase = installCheckPhase && -z $doInstallCheck ]]; then continue; fi
if [[ $curPhase = distPhase && -z $doDist ]]; then continue; fi

if [[ -n $tracePhases ]]; then
echo
echo "@ phase-started $out $curPhase"
fi
Expand Down

0 comments on commit 2743078

Please sign in to comment.