Skip to content

Support response files with quoted args #479

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 14 additions & 6 deletions toolchain/cc_wrapper.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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="$(
Expand Down
28 changes: 18 additions & 10 deletions toolchain/osx_cc_wrapper.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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="$(
Expand Down
Loading