diff --git a/cmake/modules/SwiftSource.cmake b/cmake/modules/SwiftSource.cmake index 5b3154e911c78..bd581b17dc677 100644 --- a/cmake/modules/SwiftSource.cmake +++ b/cmake/modules/SwiftSource.cmake @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/utils/line-directive b/utils/line-directive index 49166e29dbdee..07e6c5d2965df 100755 --- a/utils/line-directive +++ b/utils/line-directive @@ -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(';')) + +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 @@ -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 @@ -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(