Skip to content

Commit 8bf3af0

Browse files
authored
Merge pull request #82166 from Steelskin/fabrice/6.2-line-directive
🍒 [6.2] line-directive: Stop expanding response files
2 parents a7e44d4 + a89f9de commit 8bf3af0

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
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: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,8 @@ def map_line_from_source_file(source_filename, source_line_num,
208208

209209
def read_response_file(file_path):
210210
with open(file_path, 'r') as files:
211-
# "Make an iterator out of shlex.shlex.get_token, then consume items
212-
# until it returns None." (Then eagerly convert the result to a list so
213-
# that we can close the file.)
214-
return list(iter(shlex.shlex(files, file_path, posix=True).get_token,
215-
None))
211+
# Read a response file and return a list of files (one per line).
212+
return [line.strip() for line in files if line.strip()]
216213

217214

218215
def expand_response_files(files):
@@ -683,16 +680,21 @@ def run():
683680
# delegates to the Win32 CreateProcess API. Unix systems handle
684681
# non-normalized paths, so don't have this problem.
685682
# Arguments passed to the process are normalized by the process.
686-
command_args = expand_response_files(sys.argv[dashes + 1:])
683+
command_args = sys.argv[dashes + 1:]
687684
command_args[0] = os.path.normpath(command_args[0])
688685

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

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

@@ -731,7 +733,12 @@ def run():
731733
m.group('tail'))
732734
sys.stdout.write(output)
733735

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

736743

737744
if __name__ == '__main__':

0 commit comments

Comments
 (0)