Merge pull request #82166 from Steelskin/fabrice/6.2-line-directive

🍒 [6.2] line-directive: Stop expanding response files
This commit is contained in:
Saleem Abdulrasool
2025-07-15 11:40:13 -07:00
committed by GitHub
2 changed files with 24 additions and 17 deletions

View File

@@ -1015,13 +1015,13 @@ function(_compile_swift_files
# 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(REPLACE ";" "'\n'" source_files_quoted "${source_files}")
string(SHA1 file_name "'${source_files_quoted}'")
string(REPLACE ";" "\n" source_files_quoted "${source_files}")
string(SHA1 file_name "${source_files_quoted}")
set(file_path_target "filelist-${file_name}")
set(file_path "${CMAKE_CURRENT_BINARY_DIR}/${file_name}.txt")
if (NOT TARGET ${file_path_target})
file(WRITE "${file_path}.tmp" "'${source_files_quoted}'")
file(WRITE "${file_path}.tmp" "${source_files_quoted}")
add_custom_command_target(unused_var
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${file_path}.tmp" "${file_path}"
CUSTOM_TARGET_NAME ${file_path_target}

View File

@@ -208,11 +208,8 @@ def map_line_from_source_file(source_filename, source_line_num,
def read_response_file(file_path):
with open(file_path, 'r') as files:
# "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))
# Read a response file and return a list of files (one per line).
return [line.strip() for line in files if line.strip()]
def expand_response_files(files):
@@ -683,9 +680,10 @@ def run():
# delegates 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 = expand_response_files(sys.argv[dashes + 1:])
command_args = sys.argv[dashes + 1:]
command_args[0] = os.path.normpath(command_args[0])
try:
command = subprocess.Popen(
command_args,
stderr=subprocess.STDOUT,
@@ -693,6 +691,10 @@ def run():
universal_newlines=True,
encoding='UTF-8'
)
except Exception as e:
sys.stderr.write(f"Error executing command: {e}\n")
sys.stderr.write(f"Command: {' '.join(shlex.quote(arg) for arg in command_args)}\n")
sys.exit(1)
sources = '(?P<file>' + '|'.join(re.escape(s) for s in sources) + ')'
@@ -731,7 +733,12 @@ def run():
m.group('tail'))
sys.stdout.write(output)
sys.exit(command.wait())
exit_code = command.wait()
if exit_code != 0:
sys.stderr.write(f"Command failed with exit code {exit_code}\n")
sys.stderr.write(f"Command: {' '.join(shlex.quote(arg) for arg in command_args)}\n")
sys.exit(exit_code)
if __name__ == '__main__':