cc-wrapper, bintools-wrapper: Improve hooks that run before invocation (#366960)

Changed files
+12 -6
doc
pkgs
build-support
bintools-wrapper
cc-wrapper
+1
doc/stdenv/stdenv.chapter.md
···
### Compiler and Linker wrapper hooks {#compiler-linker-wrapper-hooks}
If the file `${cc}/nix-support/cc-wrapper-hook` exists, it will be run at the end of the [compiler wrapper](#cc-wrapper).
+
If the file `${binutils}/nix-support/ld-wrapper-hook` exists, it will be run at the end of the linker wrapper, before the linker runs.
If the file `${binutils}/nix-support/post-link-hook` exists, it will be run at the end of the linker wrapper.
These hooks allow a user to inject code into the wrappers.
As an example, these hooks can be used to extract `extraBefore`, `params` and `extraAfter` which store all the command line arguments passed to the compiler and linker respectively.
+5
pkgs/build-support/bintools-wrapper/ld-wrapper.sh
···
extraAfter+=(--build-id="${NIX_BUILD_ID_STYLE:-sha1}")
fi
+
# if a ld-wrapper-hook exists, run it.
+
if [[ -e @out@/nix-support/ld-wrapper-hook ]]; then
+
linker=@prog@
+
source @out@/nix-support/ld-wrapper-hook
+
fi
# Optionally print debug info.
if (( "${NIX_DEBUG:-0}" >= 1 )); then
+6 -6
pkgs/build-support/cc-wrapper/cc-wrapper.sh
···
extraAfter+=(-- "${positionalArgs[@]}")
fi
+
# if a cc-wrapper-hook exists, run it.
+
if [[ -e @out@/nix-support/cc-wrapper-hook ]]; then
+
compiler=@prog@
+
source @out@/nix-support/cc-wrapper-hook
+
fi
+
# Optionally print debug info.
if (( "${NIX_DEBUG:-0}" >= 1 )); then
# Old bash workaround, see ld-wrapper for explanation.
···
PATH="$path_backup"
# Old bash workaround, see above.
-
-
# if a cc-wrapper-hook exists, run it.
-
if [[ -e @out@/nix-support/cc-wrapper-hook ]]; then
-
compiler=@prog@
-
source @out@/nix-support/cc-wrapper-hook
-
fi
if (( "${NIX_CC_USE_RESPONSE_FILE:-@use_response_file_by_default@}" >= 1 )); then
responseFile=$(@mktemp@ "${TMPDIR:-/tmp}/cc-params.XXXXXX")