Skip to content

Fix line-directive tool to work around Windows command line max limit #6464

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
Jan 26, 2017
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
29 changes: 19 additions & 10 deletions cmake/modules/SwiftSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,21 @@ 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.
string(RANDOM file_name)
set(file_path "${CMAKE_CURRENT_BINARY_DIR}/${file_name}.txt")
file(WRITE "${file_path}" "${source_files}")

add_custom_command_target(
dependency_target
COMMAND
"${PYTHON_EXECUTABLE}" "${line_directive_tool}" "${source_files}" --
"${PYTHON_EXECUTABLE}" "${line_directive_tool}" "@${file_path}" --
"${swift_compiler_tool}" "${main_command}" ${swift_flags}
${output_option} ${embed_bitcode_option} "${source_files}"
${output_option} ${embed_bitcode_option} "@${file_path}"
${command_touch_standard_outputs}
OUTPUT ${standard_outputs}
DEPENDS
Expand Down Expand Up @@ -485,9 +494,9 @@ function(_compile_swift_files
add_custom_command_target(
module_dependency_target
COMMAND
"${PYTHON_EXECUTABLE}" "${line_directive_tool}" "${source_files}" --
"${PYTHON_EXECUTABLE}" "${line_directive_tool}" "@${file_path}" --
"${swift_compiler_tool}" "-emit-module" "-o" "${module_file}" ${swift_flags}
"${source_files}"
"@${file_path}"
${command_touch_module_outputs}
OUTPUT ${module_outputs}
DEPENDS
Expand All @@ -502,9 +511,9 @@ function(_compile_swift_files
add_custom_command_target(
sib_dependency_target
COMMAND
"${PYTHON_EXECUTABLE}" "${line_directive_tool}" "${source_files}" --
"${PYTHON_EXECUTABLE}" "${line_directive_tool}" "@${file_path}" --
"${swift_compiler_tool}" "-emit-sib" "-o" "${sib_file}" ${swift_flags} -Onone
"${source_files}"
"@${file_path}"
${command_touch_sib_outputs}
OUTPUT ${sib_outputs}
DEPENDS
Expand All @@ -518,9 +527,9 @@ function(_compile_swift_files
add_custom_command_target(
sibopt_dependency_target
COMMAND
"${PYTHON_EXECUTABLE}" "${line_directive_tool}" "${source_files}" --
"${PYTHON_EXECUTABLE}" "${line_directive_tool}" "@${file_path}" --
"${swift_compiler_tool}" "-emit-sib" "-o" "${sibopt_file}" ${swift_flags} -O
"${source_files}"
"@${file_path}"
${command_touch_sibopt_outputs}
OUTPUT ${sibopt_outputs}
DEPENDS
Expand All @@ -535,9 +544,9 @@ function(_compile_swift_files
add_custom_command_target(
sibgen_dependency_target
COMMAND
"${PYTHON_EXECUTABLE}" "${line_directive_tool}" "${source_files}" --
"${PYTHON_EXECUTABLE}" "${line_directive_tool}" "@${file_path}" --
"${swift_compiler_tool}" "-emit-sibgen" "-o" "${sibgen_file}" ${swift_flags}
"${source_files}"
"@${file_path}"
${command_touch_sibgen_outputs}
OUTPUT ${sibgen_outputs}
DEPENDS
Expand Down
19 changes: 17 additions & 2 deletions utils/line-directive
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ def map_line_from_source_file(source_filename, source_line_num, target_filename)
return result + 1
raise RuntimeError("line not found")

def read_response_file(file_path):
with open(file_path, 'r') as files:
return filter(None, files.read().split(';'))
Copy link
Member

Choose a reason for hiding this comment

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

And here.


def expand_response_files(files):
expanded_files = []
for file_path in files:
# Read a list of files from a response file.
if file_path[0] == '@':
expanded_files.extend(read_response_file(file_path[1:]))
else:
expanded_files.append(file_path)

return expanded_files

def run():
"""Simulate a couple of gyb-generated files

Expand Down Expand Up @@ -243,7 +258,7 @@ def run():
print(map_line_from_source_file(source_file, source_line, target_file))
else:
dashes = sys.argv.index('--')
sources = sys.argv[1:dashes]
sources = expand_response_files(sys.argv[1:dashes])

# The first argument of command_args is the process to open.
# subprocess.Popen doesn't normalize arguments. This means that trying
Expand All @@ -252,7 +267,7 @@ def run():
# to the Win32 CreateProcess API. Unix systems handle non-normalized
# paths, so don't have this problem.
# Arguments passed to the process are normalized by the process.
command_args = sys.argv[dashes + 1:]
command_args = expand_response_files(sys.argv[dashes + 1:])
command_args[0] = os.path.normpath(command_args[0])

command = subprocess.Popen(
Expand Down