Skip to content

Commit d098595

Browse files
authored
Merge pull request #32589 from compnerd/cartography
test: make `gen-output-file-map` Python 3 friendly
2 parents 30ccb52 + 112af9e commit d098595

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

test/Incremental/Verifier/gen-output-file-map.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import print_function
44

55
import argparse
6+
import io
67
import json
78
import os
89
import sys
@@ -61,13 +62,22 @@ def main(arguments):
6162
'swift-dependencies': './main-buildrecord.swiftdeps'
6263
}
6364

64-
with open(output_path, 'wb') as f:
65-
json.dump(all_records, f)
65+
# TODO: this is for python 2 and python 3 compatibility. Once Python 2 is
66+
# removed, this function can be removed.
67+
def to_unicode(r):
68+
import sys
69+
if sys.version_info[0] < 3:
70+
return unicode(r)
71+
return str(r)
72+
73+
with io.open(output_path, 'w', encoding='utf-8', newline='\n') as f:
74+
f.write(to_unicode(json.dumps(all_records, ensure_ascii=False)))
6675

6776
if args.response_output_file is not None:
68-
with open(args.response_output_file, 'wb') as f:
77+
with io.open(args.response_output_file, 'w',
78+
encoding='utf-8', newline='\n') as f:
6979
for line in response_file_contents:
70-
f.write(line + " ")
80+
f.write(to_unicode(line + " "))
7181

7282

7383
if __name__ == '__main__':

0 commit comments

Comments
 (0)