From e22e28e6a046b39c9b18d8912550bf24baa66e69 Mon Sep 17 00:00:00 2001 From: Hugh Bellamy Date: Sat, 14 Jan 2017 21:45:00 +0000 Subject: [PATCH] Fix line-directive-tool not being able to invoke swiftc.exe on Windows --- utils/line-directive | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/utils/line-directive b/utils/line-directive index a3ba3a03f08b7..c915b13c12daf 100755 --- a/utils/line-directive +++ b/utils/line-directive @@ -20,6 +20,7 @@ import bisect import re import subprocess import sys +import os line_pattern = re.compile( r'^// ###sourceLocation\(file:\s*"([^"]+)",\s*line:\s*([0-9]+)\s*\)') @@ -244,8 +245,18 @@ def run(): dashes = sys.argv.index('--') sources = sys.argv[1:dashes] + # The first argument of command_args is the process to open. + # subprocess.Popen doesn't normalise arguments. This means that trying + # to open a non-normalised file (e.g. C:/swift/./bin/swiftc.exe) on + # Windows results in file/directory not found errors, as Popen delegates + # to the Win32 CreateProcess API. Unix systems handle non-normalised + # paths, so don't have this problem. + # Arguments passed to the process are normalised by the process. + command_args = sys.argv[dashes + 1:] + command_args[0] = os.path.normpath(command_args[0]) + command = subprocess.Popen( - sys.argv[dashes + 1:], + command_args, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, universal_newlines=True