Skip to content

Commit 7159dfb

Browse files
authored
fix(msvs): fix paths again in action command arguments (#121)
* fix(msvs): fix paths again in action command arguments This is a revert of #84 with a change to the _FixPath function allowing to change the separator used. Fixes: #120 Fixes: nodejs/node-gyp#2485
1 parent e68cc05 commit 7159dfb

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

pylib/gyp/generator/msvs.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def _NormalizedSource(source):
152152
return source
153153

154154

155-
def _FixPath(path):
155+
def _FixPath(path, separator="\\"):
156156
"""Convert paths to a form that will make sense in a vcproj file.
157157
158158
Arguments:
@@ -168,9 +168,12 @@ def _FixPath(path):
168168
and not _IsWindowsAbsPath(path)
169169
):
170170
path = os.path.join(fixpath_prefix, path)
171-
path = path.replace("/", "\\")
171+
if separator == "\\":
172+
path = path.replace("/", "\\")
172173
path = _NormalizedSource(path)
173-
if path and path[-1] == "\\":
174+
if separator == "/":
175+
path = path.replace("\\", "/")
176+
if path and path[-1] == separator:
174177
path = path[:-1]
175178
return path
176179

@@ -185,9 +188,9 @@ def _IsWindowsAbsPath(path):
185188
return path.startswith("c:") or path.startswith("C:")
186189

187190

188-
def _FixPaths(paths):
191+
def _FixPaths(paths, separator="\\"):
189192
"""Fix each of the paths of the list."""
190-
return [_FixPath(i) for i in paths]
193+
return [_FixPath(i, separator) for i in paths]
191194

192195

193196
def _ConvertSourcesToFilterHierarchy(
@@ -418,7 +421,15 @@ def _BuildCommandLineForRuleRaw(
418421
# file out of the raw command string, and some commands (like python) are
419422
# actually batch files themselves.
420423
command.insert(0, "call")
421-
arguments = [i.replace("$(InputDir)", "%INPUTDIR%") for i in cmd[1:]]
424+
# Fix the paths
425+
# TODO(quote): This is a really ugly heuristic, and will miss path fixing
426+
# for arguments like "--arg=path" or "/opt:path".
427+
# If the argument starts with a slash or dash, it's probably a command line
428+
# switch
429+
# Return the path with forward slashes because the command using it might
430+
# not support backslashes.
431+
arguments = [i if (i[:1] in "/-") else _FixPath(i, "/") for i in cmd[1:]]
432+
arguments = [i.replace("$(InputDir)", "%INPUTDIR%") for i in arguments]
422433
arguments = [MSVSSettings.FixVCMacroSlashes(i) for i in arguments]
423434
if quote_cmd:
424435
# Support a mode for using cmd directly.

0 commit comments

Comments
 (0)