Skip to content

Create sanitized response file instead of expanding arguments #480

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

Merged
merged 3 commits into from
Apr 10, 2025
Merged
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: 17 additions & 3 deletions toolchain/cc_wrapper.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -78,4 +92,4 @@ for ((i = 0; i <= $#; i++)); do
done

# Call the C++ compiler.
exec "${cmd[@]}"
"${cmd[@]}"
17 changes: 14 additions & 3 deletions toolchain/osx_cc_wrapper.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down