Skip to content

Commit 810588b

Browse files
committed
line-directive: Stop expanding response files
`line-directive` was expanding response files for the swiftc invocation, which was causing issues on CI when the file list got too long. This changes the script to stop expanding response files and pass them as-is to the swiftc invocation instead. The format for the response files was also incorrect, with each individual file being quoted, so this fixes the CMake script generating those. Finally, this changes `line-directive` to dump the command line on failure.
1 parent dd57d4d commit 810588b

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,13 +1015,13 @@ function(_compile_swift_files
10151015
# need to work around this by avoiding long command line arguments. This can
10161016
# be achieved by writing the list of file paths to a file, then reading that
10171017
# list in the Python script.
1018-
string(REPLACE ";" "'\n'" source_files_quoted "${source_files}")
1019-
string(SHA1 file_name "'${source_files_quoted}'")
1018+
string(REPLACE ";" "\n" source_files_quoted "${source_files}")
1019+
string(SHA1 file_name "${source_files_quoted}")
10201020
set(file_path_target "filelist-${file_name}")
10211021
set(file_path "${CMAKE_CURRENT_BINARY_DIR}/${file_name}.txt")
10221022

10231023
if (NOT TARGET ${file_path_target})
1024-
file(WRITE "${file_path}.tmp" "'${source_files_quoted}'")
1024+
file(WRITE "${file_path}.tmp" "${source_files_quoted}")
10251025
add_custom_command_target(unused_var
10261026
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${file_path}.tmp" "${file_path}"
10271027
CUSTOM_TARGET_NAME ${file_path_target}

utils/line-directive

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ def read_response_file(file_path):
211211
# "Make an iterator out of shlex.shlex.get_token, then consume items
212212
# until it returns None." (Then eagerly convert the result to a list so
213213
# that we can close the file.)
214-
return list(iter(shlex.shlex(files, file_path, posix=True).get_token,
215-
None))
214+
return [line.strip() for line in files if line.strip()]
216215

217216

218217
def expand_response_files(files):
@@ -686,13 +685,18 @@ def run():
686685
command_args = expand_response_files(sys.argv[dashes + 1:])
687686
command_args[0] = os.path.normpath(command_args[0])
688687

689-
command = subprocess.Popen(
690-
command_args,
691-
stderr=subprocess.STDOUT,
692-
stdout=subprocess.PIPE,
693-
universal_newlines=True,
694-
encoding='UTF-8'
695-
)
688+
try:
689+
command = subprocess.Popen(
690+
command_args,
691+
stderr=subprocess.STDOUT,
692+
stdout=subprocess.PIPE,
693+
universal_newlines=True,
694+
encoding='UTF-8'
695+
)
696+
except Exception as e:
697+
sys.stderr.write(f"Error executing command: {e}\n")
698+
sys.stderr.write(f"Command: {' '.join(shlex.quote(arg) for arg in command_args)}\n")
699+
sys.exit(1)
696700

697701
sources = '(?P<file>' + '|'.join(re.escape(s) for s in sources) + ')'
698702

@@ -731,7 +735,12 @@ def run():
731735
m.group('tail'))
732736
sys.stdout.write(output)
733737

734-
sys.exit(command.wait())
738+
exit_code = command.wait()
739+
if exit_code != 0:
740+
sys.stderr.write(f"Command failed with exit code {exit_code}\n")
741+
sys.stderr.write(f"Command: {' '.join(shlex.quote(arg) for arg in command_args)}\n")
742+
743+
sys.exit(exit_code)
735744

736745

737746
if __name__ == '__main__':

0 commit comments

Comments
 (0)