Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cc-wrapper: Run mktemp before PATH is restored #316700

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 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,12 @@ if (( "${NIX_DEBUG:-0}" >= 1 )); then
printf " %q\n" ${extraAfter+"${extraAfter[@]}"} >&2
fi

# Uses mktemp so should be done before PATH is restored
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
Copy link

@IlyaNiklyaev IlyaNiklyaev Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I can see trap will run rm from restored PATH. So this approach helps with mktemp, but not with rm.

fi

PATH="$path_backup"
# Old bash workaround, see above.

Expand All @@ -246,8 +252,6 @@ 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
printf "%q\n" \
${extraBefore+"${extraBefore[@]}"} \
${params+"${params[@]}"} \
Expand Down
3 changes: 3 additions & 0 deletions pkgs/test/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ in stdenv.mkDerivation {
NIX_DEBUG=1 $CC -v
NIX_DEBUG=1 $CXX -v

echo "checking if cc-wrapper works with an empty \$PATH... " >&2
env - $NIX_CC/bin/$CC --version

echo "checking whether compiler builds valid C binaries... " >&2
$CC -o cc-check ${./cc-main.c}
${emulator} ./cc-check
Expand Down