Skip to content

[CMake] Make GNU-style response files for long argument lists #18958

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 1 commit into from
Oct 24, 2018
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
11 changes: 6 additions & 5 deletions cmake/modules/SwiftSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,14 @@ function(_compile_swift_files
# Then we can compile both the object files and the swiftmodule files
# in parallel in this target for the object file, and ...

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

Choose a reason for hiding this comment

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

Im worried about how this expansion works on Windows. The shell escaping there is weird and the quoting here I believe will go wrong. Note that shlex behaves differently on Windows and unices, so the behaviour of the quoting is relevant to that too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of shlex's arguments is whether it behaves POSIXly, which I passed True to. Still, I'd love to test this on a Windows machine; I just don't have one available today.


add_custom_command_target(
dependency_target
Expand Down
7 changes: 6 additions & 1 deletion utils/line-directive
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ from __future__ import print_function
import bisect
import os
import re
import shlex
import subprocess
import sys

Expand Down Expand Up @@ -178,7 +179,11 @@ def map_line_from_source_file(source_filename, source_line_num,

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


def expand_response_files(files):
Expand Down