diff --git a/toolchain/cc_wrapper.sh.tpl b/toolchain/cc_wrapper.sh.tpl index e972d57e6..b3cb23386 100644 --- a/toolchain/cc_wrapper.sh.tpl +++ b/toolchain/cc_wrapper.sh.tpl @@ -29,6 +29,16 @@ set -euo pipefail +CLEANUP_FILES=() + +function cleanup() { + if [[ ${#CLEANUP_FILES[@]} -gt 0 ]]; then + rm -f "${CLEANUP_FILES[@]}" + fi +} + +trap cleanup EXIT + # See note in toolchain/internal/configure.bzl where we define # `wrapper_bin_prefix` for why this wrapper is needed. @@ -60,14 +70,18 @@ function sanitize_option() { cmd=() for ((i = 0; i <= $#; i++)); do - if [[ ${!i} == @* ]]; then + if [[ ${!i} == @* && -r "${i:1}" ]]; then + # Create a new, sanitized file. + tmpfile=$(mktemp) + CLEANUP_FILES+=("${tmpfile}") while IFS= read -r opt; do opt="$( set -e sanitize_option "${opt}" )" - cmd+=("${opt}") + echo "${opt}" >>"${tmpfile}" done <"${!i:1}" + cmd+=("@${tmpfile}") else opt="$( set -e @@ -78,4 +92,4 @@ for ((i = 0; i <= $#; i++)); do done # Call the C++ compiler. -exec "${cmd[@]}" +"${cmd[@]}" diff --git a/toolchain/osx_cc_wrapper.sh.tpl b/toolchain/osx_cc_wrapper.sh.tpl index 31122784b..a005caa30 100755 --- a/toolchain/osx_cc_wrapper.sh.tpl +++ b/toolchain/osx_cc_wrapper.sh.tpl @@ -35,6 +35,15 @@ LIBS= LIB_DIRS= RPATHS= OUTPUT= +CLEANUP_FILES=() + +function cleanup() { + if [[ ${#CLEANUP_FILES[@]} -gt 0 ]]; then + rm -f "${CLEANUP_FILES[@]}" + fi +} + +trap cleanup EXIT function parse_option() { local -r opt="$1" @@ -87,17 +96,19 @@ function sanitize_option() { cmd=() for ((i = 0; i <= $#; i++)); do if [[ ${!i} == @* && -r "${i:1}" ]]; then + tmpfile=$(mktemp) + CLEANUP_FILES+=("${tmpfile}") while IFS= read -r opt; do if [[ ${opt} == "-fuse-ld=ld64.lld" ]]; then - cmd+=("-fuse-ld=lld") + echo "-fuse-ld=lld" >>"${tmpfile}" fi opt="$( set -e sanitize_option "${opt}" )" - parse_option "${opt}" - cmd+=("${opt}") + parse_option "${opt}" >>"${tmpfile}" done <"${!i:1}" + cmd+=("@${tmpfile}") else opt="$( set -e