Skip to content

Commit 6cd7803

Browse files
authored
[CMake] Make GNU-style response files for long argument lists (#18958)
...i.e. an actual shell-like argument list, rather than a semicolon-separated list (CMake's internal stringification mechanism for lists). Apart from being a little easier to read, this also works directly with the response file support in swiftc itself now (not depending on utils/line-directive). (It's still not /quite/ enough to expand on a command-line, though, since that will escape the quotes. The 'sed' command can get around that: $(sed "s/'//g" foo.txt).)
1 parent f85d8ae commit 6cd7803

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

cmake/modules/SwiftSource.cmake

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -454,13 +454,14 @@ function(_compile_swift_files
454454
# Then we can compile both the object files and the swiftmodule files
455455
# in parallel in this target for the object file, and ...
456456

457-
# Windows doesn't support long command line paths, of 8191 chars or over.
458-
# We need to work around this by avoiding long command line arguments. This can be
459-
# achieved by writing the list of file paths to a file, then reading that list
460-
# in the Python script.
457+
# Windows doesn't support long command line paths, of 8191 chars or over. We
458+
# need to work around this by avoiding long command line arguments. This can
459+
# be achieved by writing the list of file paths to a file, then reading that
460+
# list in the Python script.
461461
string(RANDOM file_name)
462462
set(file_path "${CMAKE_CURRENT_BINARY_DIR}/${file_name}.txt")
463-
file(WRITE "${file_path}" "${source_files}")
463+
string(REPLACE ";" "'\n'" source_files_quoted "${source_files}")
464+
file(WRITE "${file_path}" "'${source_files_quoted}'")
464465

465466
add_custom_command_target(
466467
dependency_target

utils/line-directive

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ from __future__ import print_function
2121
import bisect
2222
import os
2323
import re
24+
import shlex
2425
import subprocess
2526
import sys
2627

@@ -178,7 +179,11 @@ def map_line_from_source_file(source_filename, source_line_num,
178179

179180
def read_response_file(file_path):
180181
with open(file_path, 'r') as files:
181-
return filter(None, files.read().split(';'))
182+
# "Make an iterator out of shlex.shlex.get_token, then consume items
183+
# until it returns None." (Then eagerly convert the result to a list so
184+
# that we can close the file.)
185+
return list(iter(shlex.shlex(files, file_path, posix=True).get_token,
186+
None))
182187

183188

184189
def expand_response_files(files):

0 commit comments

Comments
 (0)