Skip to content

Commit bd03b27

Browse files
committed
[CMake] Make GNU-style response files for long argument lists
...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 249b55b commit bd03b27

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
@@ -455,13 +455,14 @@ function(_compile_swift_files
455455
# Then we can compile both the object files and the swiftmodule files
456456
# in parallel in this target for the object file, and ...
457457

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

466467
add_custom_command_target(
467468
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)