summary refs log tree commit diff
path: root/pkgs/build-support/cc-wrapper
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2018-05-07 13:15:34 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2018-05-07 15:10:45 -0400
commit8b0fce8cb1013837cd2108193653a1763cd68266 (patch)
tree9a66438ae3790f203561d354f0c1457da86f39b0 /pkgs/build-support/cc-wrapper
parent2110c0bd3009279ceec291f07bfbf063cb5ba6a0 (diff)
downloadnixlib-8b0fce8cb1013837cd2108193653a1763cd68266.tar
nixlib-8b0fce8cb1013837cd2108193653a1763cd68266.tar.gz
nixlib-8b0fce8cb1013837cd2108193653a1763cd68266.tar.bz2
nixlib-8b0fce8cb1013837cd2108193653a1763cd68266.tar.lz
nixlib-8b0fce8cb1013837cd2108193653a1763cd68266.tar.xz
nixlib-8b0fce8cb1013837cd2108193653a1763cd68266.tar.zst
nixlib-8b0fce8cb1013837cd2108193653a1763cd68266.zip
{bintools,cc}-wrapper: Factor out role accumulation logic
Diffstat (limited to 'pkgs/build-support/cc-wrapper')
-rw-r--r--pkgs/build-support/cc-wrapper/add-flags.sh13
-rw-r--r--pkgs/build-support/cc-wrapper/cc-wrapper.sh2
-rw-r--r--pkgs/build-support/cc-wrapper/default.nix4
-rw-r--r--pkgs/build-support/cc-wrapper/utils.sh80
4 files changed, 4 insertions, 95 deletions
diff --git a/pkgs/build-support/cc-wrapper/add-flags.sh b/pkgs/build-support/cc-wrapper/add-flags.sh
index 604aaf6b6cf0..ee4cc1ec06d4 100644
--- a/pkgs/build-support/cc-wrapper/add-flags.sh
+++ b/pkgs/build-support/cc-wrapper/add-flags.sh
@@ -14,18 +14,7 @@ var_templates_bool=(
     NIX+ENFORCE_NO_NATIVE
 )
 
-# Accumulate infixes for taking in the right input parameters. See setup-hook
-# for details.
-declare -a role_infixes=()
-if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_BUILD:-}" ]; then
-    role_infixes+=(_BUILD_)
-fi
-if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_HOST:-}" ]; then
-    role_infixes+=(_)
-fi
-if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_TARGET:-}" ]; then
-    role_infixes+=(_TARGET_)
-fi
+accumulateRoles
 
 # We need to mangle names for hygiene, but also take parameters/overrides
 # from the environment.
diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh
index c2e6c1406358..b2bacec5e9b5 100644
--- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh
+++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh
@@ -15,7 +15,7 @@ if [[ -n "@coreutils_bin@" && -n "@gnugrep_bin@" ]]; then
     PATH="@coreutils_bin@/bin:@gnugrep_bin@/bin"
 fi
 
-source @out@/nix-support/utils.sh
+source @out@/nix-support/utils.bash
 
 # Flirting with a layer violation here.
 if [ -z "${NIX_BINTOOLS_WRAPPER_@infixSalt@_FLAGS_SET:-}" ]; then
diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix
index 0ea9dd0cb9f4..1b1c82b9294f 100644
--- a/pkgs/build-support/cc-wrapper/default.nix
+++ b/pkgs/build-support/cc-wrapper/default.nix
@@ -282,7 +282,7 @@ stdenv.mkDerivation {
     + ''
       substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
       substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh
-      substituteAll ${./utils.sh} $out/nix-support/utils.sh
+      substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash
 
       ##
       ## Extra custom steps
@@ -293,7 +293,7 @@ stdenv.mkDerivation {
 
   inherit expand-response-params;
 
-  # for substitution in utils.sh
+  # for substitution in utils.bash
   expandResponseParams = "${expand-response-params}/bin/expand-response-params";
 
   meta =
diff --git a/pkgs/build-support/cc-wrapper/utils.sh b/pkgs/build-support/cc-wrapper/utils.sh
deleted file mode 100644
index 9215fe2dc397..000000000000
--- a/pkgs/build-support/cc-wrapper/utils.sh
+++ /dev/null
@@ -1,80 +0,0 @@
-mangleVarList() {
-    local var="$1"
-    shift
-    local -a role_infixes=("$@")
-
-    local outputVar="${var/+/_@infixSalt@_}"
-    declare -gx ${outputVar}+=''
-    # For each role we serve, we accumulate the input parameters into our own
-    # cc-wrapper-derivation-specific environment variables.
-    for infix in "${role_infixes[@]}"; do
-        local inputVar="${var/+/${infix}}"
-        if [ -v "$inputVar" ]; then
-            export ${outputVar}+="${!outputVar:+ }${!inputVar}"
-        fi
-    done
-}
-
-mangleVarBool() {
-    local var="$1"
-    shift
-    local -a role_infixes=("$@")
-
-    local outputVar="${var/+/_@infixSalt@_}"
-    declare -gxi ${outputVar}+=0
-    for infix in "${role_infixes[@]}"; do
-        local inputVar="${var/+/${infix}}"
-        if [ -v "$inputVar" ]; then
-            # "1" in the end makes `let` return success error code when
-            # expression itself evaluates to zero.
-            # We don't use `|| true` because that would silence actual
-            # syntax errors from bad variable values.
-            let "${outputVar} |= ${!inputVar:-0}" "1"
-        fi
-    done
-}
-
-skip () {
-    if (( "${NIX_DEBUG:-0}" >= 1 )); then
-        echo "skipping impure path $1" >&2
-    fi
-}
-
-
-# Checks whether a path is impure.  E.g., `/lib/foo.so' is impure, but
-# `/nix/store/.../lib/foo.so' isn't.
-badPath() {
-    local p=$1
-
-    # Relative paths are okay (since they're presumably relative to
-    # the temporary build directory).
-    if [ "${p:0:1}" != / ]; then return 1; fi
-
-    # Otherwise, the path should refer to the store or some temporary
-    # directory (including the build directory).
-    test \
-        "$p" != "/dev/null" -a \
-        "${p:0:${#NIX_STORE}}" != "$NIX_STORE" -a \
-        "${p:0:4}" != "/tmp" -a \
-        "${p:0:${#NIX_BUILD_TOP}}" != "$NIX_BUILD_TOP"
-}
-
-expandResponseParams() {
-    declare -ga params=("$@")
-    local arg
-    for arg in "$@"; do
-        if [[ "$arg" == @* ]]; then
-            # phase separation makes this look useless
-            # shellcheck disable=SC2157
-            if [ -x "@expandResponseParams@" ]; then
-                # params is used by caller
-                #shellcheck disable=SC2034
-                readarray -d '' params < <("@expandResponseParams@" "$@")
-                return 0
-            else
-                echo "Response files aren't supported during bootstrapping" >&2
-                return 1
-            fi
-        fi
-    done
-}