1# Accumulate infixes for taking in the right input parameters with the `mangle*` 2# functions below. See setup-hook for details. 3accumulateRoles() { 4 declare -ga role_infixes=() 5 if [ "${NIX_@wrapperName@_@infixSalt@_TARGET_BUILD:-}" ]; then 6 role_infixes+=(_BUILD_) 7 fi 8 if [ "${NIX_@wrapperName@_@infixSalt@_TARGET_HOST:-}" ]; then 9 role_infixes+=(_) 10 fi 11 if [ "${NIX_@wrapperName@_@infixSalt@_TARGET_TARGET:-}" ]; then 12 role_infixes+=(_TARGET_) 13 fi 14} 15 16mangleVarList() { 17 local var="$1" 18 shift 19 local -a role_infixes=("$@") 20 21 local outputVar="${var/+/_@infixSalt@_}" 22 declare -gx ${outputVar}+='' 23 # For each role we serve, we accumulate the input parameters into our own 24 # cc-wrapper-derivation-specific environment variables. 25 for infix in "${role_infixes[@]}"; do 26 local inputVar="${var/+/${infix}}" 27 if [ -v "$inputVar" ]; then 28 export ${outputVar}+="${!outputVar:+ }${!inputVar}" 29 fi 30 done 31} 32 33mangleVarBool() { 34 local var="$1" 35 shift 36 local -a role_infixes=("$@") 37 38 local outputVar="${var/+/_@infixSalt@_}" 39 declare -gxi ${outputVar}+=0 40 for infix in "${role_infixes[@]}"; do 41 local inputVar="${var/+/${infix}}" 42 if [ -v "$inputVar" ]; then 43 # "1" in the end makes `let` return success error code when 44 # expression itself evaluates to zero. 45 # We don't use `|| true` because that would silence actual 46 # syntax errors from bad variable values. 47 let "${outputVar} |= ${!inputVar:-0}" "1" 48 fi 49 done 50} 51 52skip () { 53 if (( "${NIX_DEBUG:-0}" >= 1 )); then 54 echo "skipping impure path $1" >&2 55 fi 56} 57 58 59# Checks whether a path is impure. E.g., `/lib/foo.so' is impure, but 60# `/nix/store/.../lib/foo.so' isn't. 61badPath() { 62 local p=$1 63 64 # Relative paths are okay (since they're presumably relative to 65 # the temporary build directory). 66 if [ "${p:0:1}" != / ]; then return 1; fi 67 68 # Otherwise, the path should refer to the store or some temporary 69 # directory (including the build directory). 70 test \ 71 "$p" != "/dev/null" -a \ 72 "${p:0:${#NIX_STORE}}" != "$NIX_STORE" -a \ 73 "${p:0:4}" != "/tmp" -a \ 74 "${p:0:${#NIX_BUILD_TOP}}" != "$NIX_BUILD_TOP" 75} 76 77expandResponseParams() { 78 declare -ga params=("$@") 79 local arg 80 for arg in "$@"; do 81 if [[ "$arg" == @* ]]; then 82 # phase separation makes this look useless 83 # shellcheck disable=SC2157 84 if [ -x "@expandResponseParams@" ]; then 85 # params is used by caller 86 #shellcheck disable=SC2034 87 readarray -d '' params < <("@expandResponseParams@" "$@") 88 return 0 89 else 90 echo "Response files aren't supported during bootstrapping" >&2 91 return 1 92 fi 93 fi 94 done 95}