Skip to content

Commit

Permalink
fix(msvs): fix paths again in action command arguments (#121)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
targos authored Aug 22, 2021
1 parent e68cc05 commit 7159dfb
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions pylib/gyp/generator/msvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def _NormalizedSource(source):
return source


def _FixPath(path):
def _FixPath(path, separator="\\"):
"""Convert paths to a form that will make sense in a vcproj file.
Arguments:
Expand All @@ -168,9 +168,12 @@ def _FixPath(path):
and not _IsWindowsAbsPath(path)
):
path = os.path.join(fixpath_prefix, path)
path = path.replace("/", "\\")
if separator == "\\":
path = path.replace("/", "\\")
path = _NormalizedSource(path)
if path and path[-1] == "\\":
if separator == "/":
path = path.replace("\\", "/")
if path and path[-1] == separator:
path = path[:-1]
return path

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


def _FixPaths(paths):
def _FixPaths(paths, separator="\\"):
"""Fix each of the paths of the list."""
return [_FixPath(i) for i in paths]
return [_FixPath(i, separator) for i in paths]


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

0 comments on commit 7159dfb

Please sign in to comment.