Skip to content
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

cc_wrapper: Spill arguments back to a response file #430

Open
wants to merge 1 commit 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
9 changes: 7 additions & 2 deletions toolchain/cc_wrapper.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,19 @@ function sanitize_option() {

cmd=()
for ((i = 0; i <= $#; i++)); do
if [[ ${!i} == @* ]]; then
if [[ ${!i} == @* && -r "${i:1}" ]]; then
# Create a temporary file that we'll spill sanitized options to since they
# were originally read from a response file.
temp_file=$(mktemp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this only if the arguments have a length that gets somewhat close to the limit? Otherwise we are just doing needless file I/O.


while IFS= read -r opt; do
opt="$(
set -e
sanitize_option "${opt}"
)"
cmd+=("${opt}")
echo "${opt}" >> "${temp_file}"
done <"${!i:1}"
mv "${temp_file}" "${!i:1}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replaces an input file, which is something actions should avoid. Could we rewrite the argument to point to the temporary file instead?

else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The temporary file should be deleted after the compiler returns.

opt="$(
set -e
Expand Down
7 changes: 6 additions & 1 deletion toolchain/osx_cc_wrapper.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ function sanitize_option() {
cmd=()
for ((i = 0; i <= $#; i++)); do
if [[ ${!i} == @* && -r "${i:1}" ]]; then
# Create a temporary file that we'll spill sanitized options to since they
# were originally read from a response file.
temp_file=$(mktemp)

while IFS= read -r opt; do
if [[ ${opt} == "-fuse-ld=ld64.lld" ]]; then
cmd+=("-fuse-ld=lld")
Expand All @@ -96,8 +100,9 @@ for ((i = 0; i <= $#; i++)); do
sanitize_option "${opt}"
)"
parse_option "${opt}"
cmd+=("${opt}")
echo "${opt}" >> "${temp_file}"
done <"${!i:1}"
mv "${temp_file}" "${!i:1}"
else
opt="$(
set -e
Expand Down