From b8b5bbe07d73449fd97a2bd4c689bb0e69e2bd9e Mon Sep 17 00:00:00 2001 From: Alex Faxa Date: Wed, 9 Apr 2025 18:14:20 +0000 Subject: [PATCH 1/2] Support response files with quoted args --- toolchain/cc_wrapper.sh.tpl | 18 ++++++++++++------ toolchain/osx_cc_wrapper.sh.tpl | 26 ++++++++++++++++---------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/toolchain/cc_wrapper.sh.tpl b/toolchain/cc_wrapper.sh.tpl index e972d57e6..2ce2a91aa 100644 --- a/toolchain/cc_wrapper.sh.tpl +++ b/toolchain/cc_wrapper.sh.tpl @@ -60,13 +60,19 @@ 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. + declare -a 'opts=('"$line"')' + 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..40a9ef0ef 100755 --- a/toolchain/osx_cc_wrapper.sh.tpl +++ b/toolchain/osx_cc_wrapper.sh.tpl @@ -86,17 +86,23 @@ 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. + declare -a 'opts=('"$line"')' + 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="$( From 933bf69a8765a75f9db982c132880a3154fa0930 Mon Sep 17 00:00:00 2001 From: Alex Faxa Date: Wed, 9 Apr 2025 20:50:49 +0000 Subject: [PATCH 2/2] Support args starting with $ --- toolchain/cc_wrapper.sh.tpl | 4 +++- toolchain/osx_cc_wrapper.sh.tpl | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/toolchain/cc_wrapper.sh.tpl b/toolchain/cc_wrapper.sh.tpl index 2ce2a91aa..2aa530d8d 100644 --- a/toolchain/cc_wrapper.sh.tpl +++ b/toolchain/cc_wrapper.sh.tpl @@ -65,7 +65,9 @@ for ((i = 0; i <= $#; i++)); do while IFS= read -r line; do # Process every arg on the line individually. # Note that a single line can contain multiple args. - declare -a 'opts=('"$line"')' + # 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 diff --git a/toolchain/osx_cc_wrapper.sh.tpl b/toolchain/osx_cc_wrapper.sh.tpl index 40a9ef0ef..d71bdb2a2 100755 --- a/toolchain/osx_cc_wrapper.sh.tpl +++ b/toolchain/osx_cc_wrapper.sh.tpl @@ -91,7 +91,9 @@ for ((i = 0; i <= $#; i++)); do while IFS= read -r line; do # Process every arg on the line individually. # Note that a single line can contain multiple args. - declare -a 'opts=('"$line"')' + # 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")