Skip to content

Commit 85599f7

Browse files
committed
Keep gyb from messing up line endings on Windows
GYB opens its inputs and outputs in text mode. This is a problem because the recommendation in Windows is to check everything out in LF mode to avoid breaking tests, so gybbing a file ends up converting LFs to CRLFs. That broke test/SILGen/magic_identifier_file_conflicting.swift.gyb. Modify GYB to open its files in binary mode instead of text mode. This is a no-op everywhere but Windows. Note that this change is incomplete: it’s somewhat difficult to switch stdin and stdout to binary mode in Python 2. I’ve added FIXME comments about this.
1 parent d590823 commit 85599f7

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

test/SILGen/magic_identifier_file_conflicting.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %gyb -D TEMPDIR=%t %s > %t/magic_identifier_file_conflicting.swift
2+
// RUN: %gyb -D TEMPDIR=%t %s -o %t/magic_identifier_file_conflicting.swift
33

44
// We want to check both the diagnostics and the SIL output.
55
// RUN: %target-swift-emit-silgen -verify -emit-sorted-sil -enable-experimental-concise-pound-file -module-name Foo %t/magic_identifier_file_conflicting.swift %S/Inputs/magic_identifier_file_conflicting_other.swift | %FileCheck %s

utils/gyb.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,12 +1208,13 @@ def succ(a):
12081208
help='''Bindings to be set in the template's execution context''')
12091209

12101210
parser.add_argument(
1211-
'file', type=argparse.FileType(),
1211+
'file', type=argparse.FileType('rb'),
12121212
help='Path to GYB template file (defaults to stdin)', nargs='?',
1213-
default=sys.stdin)
1213+
default=sys.stdin) # FIXME: stdin not binary mode on Windows
12141214
parser.add_argument(
1215-
'-o', dest='target', type=argparse.FileType('w'),
1216-
help='Output file (defaults to stdout)', default=sys.stdout)
1215+
'-o', dest='target', type=argparse.FileType('wb'),
1216+
help='Output file (defaults to stdout)',
1217+
default=sys.stdout) # FIXME: stdout not binary mode on Windows
12171218
parser.add_argument(
12181219
'--test', action='store_true',
12191220
default=False, help='Run a self-test')

0 commit comments

Comments
 (0)