cc-wrapper: Fix standalone gcc
This ensures that all salted variables are defined even if the wrapped program is invoked outside nix-build environment.
This commit is contained in:
parent
c8f7f18e69
commit
c8e9dcc8a4
@ -4,108 +4,85 @@
|
|||||||
# that case, it is cheaper/better to not repeat this step and let the forked
|
# 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.
|
# wrapped binary just inherit the work of the forker's wrapper script.
|
||||||
|
|
||||||
# Accumulate prefixes for taking in the right input parameters. See setup-hook
|
var_templates=(
|
||||||
|
NIX_CC_WRAPPER+START_HOOK
|
||||||
|
NIX_CC_WRAPPER+EXEC_HOOK
|
||||||
|
NIX_LD_WRAPPER+START_HOOK
|
||||||
|
NIX_LD_WRAPPER+EXEC_HOOK
|
||||||
|
|
||||||
|
NIX+CFLAGS_COMPILE
|
||||||
|
NIX+CFLAGS_LINK
|
||||||
|
NIX+CXXSTDLIB_COMPILE
|
||||||
|
NIX+CXXSTDLIB_LINK
|
||||||
|
NIX+GNATFLAGS_COMPILE
|
||||||
|
NIX+IGNORE_LD_THROUGH_GCC
|
||||||
|
NIX+LDFLAGS
|
||||||
|
NIX+LDFLAGS_BEFORE
|
||||||
|
NIX+LDFLAGS_AFTER
|
||||||
|
NIX+LDFLAGS_HARDEN
|
||||||
|
|
||||||
|
NIX+SET_BUILD_ID
|
||||||
|
NIX+DONT_SET_RPATH
|
||||||
|
NIX+ENFORCE_NO_NATIVE
|
||||||
|
)
|
||||||
|
|
||||||
|
# Accumulate infixes for taking in the right input parameters. See setup-hook
|
||||||
# for details.
|
# for details.
|
||||||
declare -a role_prefixes=()
|
declare -a role_infixes=()
|
||||||
if [[ -n "${NIX_CC_WRAPPER_@infixSalt@_TARGET_BUILD:-}" ]]; then
|
if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_BUILD:-}" ]; then
|
||||||
role_prefixes+=(_BUILD)
|
role_infixes+=(_BUILD_)
|
||||||
fi
|
fi
|
||||||
if [[ -n "${NIX_CC_WRAPPER_@infixSalt@_TARGET_HOST:-}" ]]; then
|
if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_HOST:-}" ]; then
|
||||||
role_prefixes+=('')
|
role_infixes+=(_)
|
||||||
fi
|
fi
|
||||||
if [[ -n "${NIX_CC_WRAPPER_@infixSalt@_TARGET_TARGET:-}" ]]; then
|
if [ "${NIX_CC_WRAPPER_@infixSalt@_TARGET_TARGET:-}" ]; then
|
||||||
role_prefixes+=(_TARGET)
|
role_infixes+=(_TARGET_)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# For each role we serve, we accumulate the input parameters into our own
|
# We need to mangle names for hygiene, but also take parameters/overrides
|
||||||
# cc-wrapper-derivation-specific environment variables.
|
# from the environment.
|
||||||
for pre in "${role_prefixes[@]}"; do
|
for var in "${var_templates[@]}"; do
|
||||||
# We need to mangle names for hygiene, but also take parameters/overrides
|
outputVar="${var/+/_@infixSalt@_}"
|
||||||
# from the environment.
|
export ${outputVar}+=''
|
||||||
slurpUnsalted () {
|
# For each role we serve, we accumulate the input parameters into our own
|
||||||
case "$1" in
|
# cc-wrapper-derivation-specific environment variables.
|
||||||
CC_WRAPPER_*)
|
for infix in "${role_infixes[@]}"; do
|
||||||
local firstPre=NIX_CC_WRAPPER_
|
inputVar="${var/+/${infix}}"
|
||||||
local varname="${1#CC_WRAPPER_}"
|
if [ -v "$inputVar" ]; then
|
||||||
;;
|
export ${outputVar}+="${!outputVar:+ }${!inputVar}"
|
||||||
LD_WRAPPER_*)
|
|
||||||
local firstPre=NIX_LD_WRAPPER_
|
|
||||||
local varname="${1#LD_WRAPPER_}"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
local firstPre=NIX_
|
|
||||||
local varname="$1"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
local inputVar="${firstPre}${pre}${varname}"
|
|
||||||
local outputVar="${firstPre}@infixSalt@_${varname}"
|
|
||||||
local delimiter=''
|
|
||||||
if [[ -n "${!outputVar:-}" && -n "${!inputVar:-}" ]]; then
|
|
||||||
delimiter=' '
|
|
||||||
fi
|
fi
|
||||||
# Easiest to just do this to deal with either the input or (old) output.
|
done
|
||||||
set +u
|
|
||||||
export ${outputVar}+="${delimiter}${!inputVar}"
|
|
||||||
set -u
|
|
||||||
}
|
|
||||||
|
|
||||||
slurpUnsalted CC_WRAPPER_START_HOOK
|
|
||||||
slurpUnsalted CC_WRAPPER_EXEC_HOOK
|
|
||||||
slurpUnsalted LD_WRAPPER_START_HOOK
|
|
||||||
slurpUnsalted LD_WRAPPER_EXEC_HOOK
|
|
||||||
|
|
||||||
slurpUnsalted CFLAGS_COMPILE
|
|
||||||
slurpUnsalted CFLAGS_LINK
|
|
||||||
slurpUnsalted CXXSTDLIB_COMPILE
|
|
||||||
slurpUnsalted CXXSTDLIB_LINK
|
|
||||||
slurpUnsalted GNATFLAGS_COMPILE
|
|
||||||
slurpUnsalted IGNORE_LD_THROUGH_GCC
|
|
||||||
slurpUnsalted LDFLAGS
|
|
||||||
slurpUnsalted LDFLAGS_BEFORE
|
|
||||||
slurpUnsalted LDFLAGS_AFTER
|
|
||||||
slurpUnsalted LDFLAGS_HARDEN
|
|
||||||
|
|
||||||
slurpUnsalted SET_BUILD_ID
|
|
||||||
slurpUnsalted DONT_SET_RPATH
|
|
||||||
slurpUnsalted ENFORCE_NO_NATIVE
|
|
||||||
done
|
done
|
||||||
unset -f slurpUnsalted
|
|
||||||
|
|
||||||
# `-B@out@/bin' forces cc to use ld-wrapper.sh when calling ld.
|
# `-B@out@/bin' forces cc to use ld-wrapper.sh when calling ld.
|
||||||
export NIX_@infixSalt@_CFLAGS_COMPILE="-B@out@/bin/ $NIX_@infixSalt@_CFLAGS_COMPILE"
|
NIX_@infixSalt@_CFLAGS_COMPILE="-B@out@/bin/ $NIX_@infixSalt@_CFLAGS_COMPILE"
|
||||||
|
|
||||||
# Export and assign separately in order that a failing $(..) will fail
|
# Export and assign separately in order that a failing $(..) will fail
|
||||||
# the script.
|
# the script.
|
||||||
|
|
||||||
if [ -e @out@/nix-support/libc-cflags ]; then
|
if [ -e @out@/nix-support/libc-cflags ]; then
|
||||||
export NIX_@infixSalt@_CFLAGS_COMPILE
|
|
||||||
NIX_@infixSalt@_CFLAGS_COMPILE="$(< @out@/nix-support/libc-cflags) $NIX_@infixSalt@_CFLAGS_COMPILE"
|
NIX_@infixSalt@_CFLAGS_COMPILE="$(< @out@/nix-support/libc-cflags) $NIX_@infixSalt@_CFLAGS_COMPILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -e @out@/nix-support/cc-cflags ]; then
|
if [ -e @out@/nix-support/cc-cflags ]; then
|
||||||
export NIX_@infixSalt@_CFLAGS_COMPILE
|
|
||||||
NIX_@infixSalt@_CFLAGS_COMPILE="$(< @out@/nix-support/cc-cflags) $NIX_@infixSalt@_CFLAGS_COMPILE"
|
NIX_@infixSalt@_CFLAGS_COMPILE="$(< @out@/nix-support/cc-cflags) $NIX_@infixSalt@_CFLAGS_COMPILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -e @out@/nix-support/gnat-cflags ]; then
|
if [ -e @out@/nix-support/gnat-cflags ]; then
|
||||||
export NIX_@infixSalt@_GNATFLAGS_COMPILE
|
|
||||||
NIX_@infixSalt@_GNATFLAGS_COMPILE="$(< @out@/nix-support/gnat-cflags) $NIX_@infixSalt@_GNATFLAGS_COMPILE"
|
NIX_@infixSalt@_GNATFLAGS_COMPILE="$(< @out@/nix-support/gnat-cflags) $NIX_@infixSalt@_GNATFLAGS_COMPILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -e @out@/nix-support/libc-ldflags ]; then
|
if [ -e @out@/nix-support/libc-ldflags ]; then
|
||||||
export NIX_@infixSalt@_LDFLAGS
|
|
||||||
NIX_@infixSalt@_LDFLAGS+=" $(< @out@/nix-support/libc-ldflags)"
|
NIX_@infixSalt@_LDFLAGS+=" $(< @out@/nix-support/libc-ldflags)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -e @out@/nix-support/cc-ldflags ]; then
|
if [ -e @out@/nix-support/cc-ldflags ]; then
|
||||||
export NIX_@infixSalt@_LDFLAGS
|
|
||||||
NIX_@infixSalt@_LDFLAGS+=" $(< @out@/nix-support/cc-ldflags)"
|
NIX_@infixSalt@_LDFLAGS+=" $(< @out@/nix-support/cc-ldflags)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -e @out@/nix-support/libc-ldflags-before ]; then
|
if [ -e @out@/nix-support/libc-ldflags-before ]; then
|
||||||
export NIX_@infixSalt@_LDFLAGS_BEFORE
|
|
||||||
NIX_@infixSalt@_LDFLAGS_BEFORE="$(< @out@/nix-support/libc-ldflags-before) $NIX_@infixSalt@_LDFLAGS_BEFORE"
|
NIX_@infixSalt@_LDFLAGS_BEFORE="$(< @out@/nix-support/libc-ldflags-before) $NIX_@infixSalt@_LDFLAGS_BEFORE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# That way forked processes don't againt extend these environment variables
|
# That way forked processes will not extend these environment variables again.
|
||||||
export NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET=1
|
export NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET=1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user