Skip to content

Commit

Permalink
cc-wrapper: Resolve mktemp and rm path before resetting $PATH
Browse files Browse the repository at this point in the history
Without this, mktemp (and rm) from the host environment is picked up.
This may result in mktemp behaving differently (on darwin) or mktemp / rm not being found at all.
  • Loading branch information
malt3 committed Nov 30, 2023
1 parent c6f3c04 commit 77c5993
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkgs/build-support/cc-wrapper/cc-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ if (( "${NIX_DEBUG:-0}" >= 1 )); then
printf " %q\n" ${extraAfter+"${extraAfter[@]}"} >&2
fi

# Resolve mktemp and rm before resetting the PATH.
# If coreutils was added to the PATH above,
# we want to use the configured coreutils versions
# (@coreutils_bin@) of these commands.
# Since rm is used in the trap below, we have no
# choice but to resolve it here.
MKTEMP=$(command -v mktemp)
RM=$(command -v rm)
PATH="$path_backup"
# Old bash workaround, see above.

Expand All @@ -246,8 +254,8 @@ if [[ -e @out@/nix-support/cc-wrapper-hook ]]; then
fi

if (( "${NIX_CC_USE_RESPONSE_FILE:-@use_response_file_by_default@}" >= 1 )); then
responseFile=$(mktemp "${TMPDIR:-/tmp}/cc-params.XXXXXX")
trap 'rm -f -- "$responseFile"' EXIT
responseFile=$("${MKTEMP}" "${TMPDIR:-/tmp}/cc-params.XXXXXX")
trap '"${RM}" -f -- "$responseFile"' EXIT
printf "%q\n" \
${extraBefore+"${extraBefore[@]}"} \
${params+"${params[@]}"} \
Expand Down

0 comments on commit 77c5993

Please sign in to comment.