cc-wrapper: Use separate mangler for "bool" variables

This avoids any `NIX_FOOBAR=1 1` not triggering conditions.
This commit is contained in:
John Ericson 2017-08-31 15:29:03 -04:00
parent fc7ed86915
commit bdd6c037c0
2 changed files with 27 additions and 7 deletions

View File

@ -4,7 +4,7 @@
# that case, it is cheaper/better to not repeat this step and let the forked
# wrapped binary just inherit the work of the forker's wrapper script.
var_templates=(
var_templates_list=(
NIX+CFLAGS_COMPILE
NIX+CFLAGS_LINK
NIX+CXXSTDLIB_COMPILE
@ -14,7 +14,9 @@ var_templates=(
NIX+LDFLAGS
NIX+LDFLAGS_BEFORE
NIX+LDFLAGS_AFTER
)
var_templates_bool=(
NIX+SET_BUILD_ID
NIX+DONT_SET_RPATH
NIX+ENFORCE_NO_NATIVE
@ -35,9 +37,12 @@ fi
# We need to mangle names for hygiene, but also take parameters/overrides
# from the environment.
for var in "${var_templates[@]}"; do
for var in "${var_templates_list[@]}"; do
mangleVarList "$var" "${role_infixes[@]}"
done
for var in "${var_templates_bool[@]}"; do
mangleVarBool "$var" "${role_infixes[@]}"
done
# `-B@out@/bin' forces cc to use ld-wrapper.sh when calling ld.
NIX_@infixSalt@_CFLAGS_COMPILE="-B@out@/bin/ $NIX_@infixSalt@_CFLAGS_COMPILE"

View File

@ -1,20 +1,35 @@
mangleVarList() {
declare var="$1"
local var="$1"
shift
declare -a role_infixes=("$@")
local -a role_infixes=("$@")
outputVar="${var/+/_@infixSalt@_}"
export ${outputVar}+=''
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
inputVar="${var/+/${infix}}"
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
let "${outputVar} |= ${!inputVar}"
fi
done
}
skip () {
if (( "${NIX_DEBUG:-0}" >= 1 )); then
echo "skipping impure path $1" >&2