Skip to content

Commit c453bb9

Browse files
authored
Merge pull request #21816 from LynnKirby/SR-9644
[gyb] Fix Windows path normalization
2 parents 374efd1 + 43f188a commit c453bb9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

utils/gyb.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ class ParseContext(object):
395395

396396
def __init__(self, filename, template=None):
397397
self.filename = os.path.abspath(filename)
398+
if sys.platform == 'win32':
399+
self.filename = self.filename.replace('\\', '/')
398400
if template is None:
399401
with open(filename) as f:
400402
self.template = f.read()
@@ -573,8 +575,6 @@ def append_text(self, text, file, line):
573575
# We can only insert the line directive at a line break
574576
if len(self.result_text) == 0 \
575577
or self.result_text[-1].endswith('\n'):
576-
if sys.platform == 'win32':
577-
file = file.replace('\\', '/')
578578
substitutions = {'file': file, 'line': line + 1}
579579
format_str = self.line_directive + '\n'
580580
self.result_text.append(format_str % substitutions)
@@ -779,7 +779,7 @@ def expand(filename, line_directive=_default_line_directive, **local_bindings):
779779
... 'line: %(line)d)',
780780
... x=2
781781
... ).replace(
782-
... '"%s"' % f.name, '"dummy.file"')
782+
... '"%s"' % f.name.replace('\\', '/'), '"dummy.file"')
783783
>>> print(result, end='')
784784
//#sourceLocation(file: "dummy.file", line: 1)
785785
---
@@ -1067,7 +1067,7 @@ def execute_template(
10671067
Keyword arguments become local variable bindings in the execution context
10681068
10691069
>>> root_directory = os.path.abspath('/')
1070-
>>> file_name = root_directory + 'dummy.file'
1070+
>>> file_name = (root_directory + 'dummy.file').replace('\\', '/')
10711071
>>> ast = parse_template(file_name, text=
10721072
... '''Nothing
10731073
... % if x:
@@ -1239,7 +1239,7 @@ def succ(a):
12391239
12401240
Example: `#sourceLocation(file: "%%(file)s", line: %%(line)d)`
12411241
1242-
The default works automatically with the `line-directive` tool,
1242+
The default works automatically with the `line-directive` tool,
12431243
which see for more information.
12441244
''')
12451245

0 commit comments

Comments
 (0)