Skip to content

Commit 6a06436

Browse files
authored
Merge pull request #6824 from hughbe/line-directive-invoke
Fix line-directive-tool not being able to invoke swiftc.exe on Windows
2 parents 592a298 + e22e28e commit 6a06436

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

utils/line-directive

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import bisect
2020
import re
2121
import subprocess
2222
import sys
23+
import os
2324

2425
line_pattern = re.compile(
2526
r'^// ###sourceLocation\(file:\s*"([^"]+)",\s*line:\s*([0-9]+)\s*\)')
@@ -244,8 +245,18 @@ def run():
244245
dashes = sys.argv.index('--')
245246
sources = sys.argv[1:dashes]
246247

248+
# The first argument of command_args is the process to open.
249+
# subprocess.Popen doesn't normalise arguments. This means that trying
250+
# to open a non-normalised file (e.g. C:/swift/./bin/swiftc.exe) on
251+
# Windows results in file/directory not found errors, as Popen delegates
252+
# to the Win32 CreateProcess API. Unix systems handle non-normalised
253+
# paths, so don't have this problem.
254+
# Arguments passed to the process are normalised by the process.
255+
command_args = sys.argv[dashes + 1:]
256+
command_args[0] = os.path.normpath(command_args[0])
257+
247258
command = subprocess.Popen(
248-
sys.argv[dashes + 1:],
259+
command_args,
249260
stderr=subprocess.STDOUT,
250261
stdout=subprocess.PIPE,
251262
universal_newlines=True

0 commit comments

Comments
 (0)