diff --git a/toolchain/cc_wrapper.sh.tpl b/toolchain/cc_wrapper.sh.tpl index e972d57e6..2aa530d8d 100644 --- a/toolchain/cc_wrapper.sh.tpl +++ b/toolchain/cc_wrapper.sh.tpl @@ -60,13 +60,21 @@ function sanitize_option() { cmd=() for ((i = 0; i <= $#; i++)); do + # If the arg starts with a `@` it is a path to a response file containing args. if [[ ${!i} == @* ]]; then - while IFS= read -r opt; do - opt="$( - set -e - sanitize_option "${opt}" - )" - cmd+=("${opt}") + while IFS= read -r line; do + # Process every arg on the line individually. + # Note that a single line can contain multiple args. + # We also need to ensure args starting with $ are not expanded but passed as-is. + declare -a opts + mapfile -t opts < <(printf '%s' "$line" | xargs -n1) + for opt in "${opts[@]}"; do + opt="$( + set -e + sanitize_option "${opt}" + )" + cmd+=("${opt}") + done done <"${!i:1}" else opt="$( diff --git a/toolchain/osx_cc_wrapper.sh.tpl b/toolchain/osx_cc_wrapper.sh.tpl index 31122784b..d71bdb2a2 100755 --- a/toolchain/osx_cc_wrapper.sh.tpl +++ b/toolchain/osx_cc_wrapper.sh.tpl @@ -86,17 +86,25 @@ function sanitize_option() { cmd=() for ((i = 0; i <= $#; i++)); do + # If the arg starts with a `@` it is a path to a response file containing args. if [[ ${!i} == @* && -r "${i:1}" ]]; then - while IFS= read -r opt; do - if [[ ${opt} == "-fuse-ld=ld64.lld" ]]; then - cmd+=("-fuse-ld=lld") - fi - opt="$( - set -e - sanitize_option "${opt}" - )" - parse_option "${opt}" - cmd+=("${opt}") + while IFS= read -r line; do + # Process every arg on the line individually. + # Note that a single line can contain multiple args. + # We also need to ensure args starting with $ are not expanded but passed as-is. + declare -a opts + mapfile -t opts < <(printf '%s' "$line" | xargs -n1) + for opt in "${opts[@]}"; do + if [[ ${opt} == "-fuse-ld=ld64.lld" ]]; then + cmd+=("-fuse-ld=lld") + fi + opt="$( + set -e + sanitize_option "${opt}" + )" + parse_option "${opt}" + cmd+=("${opt}") + done done <"${!i:1}" else opt="$(