Skip to content

Commit aaf7aa3

Browse files
[clang][utils] Make CmpDriver Python3 compatible (#163740)
The majority of this is running 2to3 on it: * print is a function in 3.x * next(it) instead of it.next() Then there was a use of "map(None, iterables..)" which in Python 2 was a way of saying "combine these iterables, and if one is shorter, pad with None". This no longer works in Python3, the equivalent is zip_longest: https://docs.python.org/3/library/itertools.html#itertools.zip_longest fillvalue defaults to None but I made it explicit since it may help someone debugging this script in future. (I doubt it has been used for a very long time)
1 parent 34decf3 commit aaf7aa3

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

clang/utils/CmpDriver

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ A simple utility that compares tool invocations and exit codes issued by
55
compiler drivers that support -### (e.g. gcc and clang).
66
"""
77

8+
from itertools import zip_longest
89
import subprocess
910

1011
def splitArgs(s):
@@ -22,7 +23,7 @@ def splitArgs(s):
2223
elif inQuote:
2324
if c == '\\':
2425
current += c
25-
current += it.next()
26+
current += next(it)
2627
else:
2728
current += c
2829
elif not c.isspace():
@@ -135,77 +136,77 @@ def main():
135136

136137
# Compare stdout.
137138
if infoA.stdout != infoB.stdout:
138-
print '-- STDOUT DIFFERS -'
139-
print 'A OUTPUT: ',infoA.stdout
140-
print 'B OUTPUT: ',infoB.stdout
141-
print
139+
print('-- STDOUT DIFFERS -')
140+
print('A OUTPUT: ',infoA.stdout)
141+
print('B OUTPUT: ',infoB.stdout)
142+
print()
142143

143144
diff = ZipperDiff(infoA.stdout.split('\n'),
144145
infoB.stdout.split('\n'))
145146
for i,(aElt,bElt) in enumerate(diff.getDiffs()):
146147
if aElt is None:
147-
print 'A missing: %s' % bElt
148+
print('A missing: %s' % bElt)
148149
elif bElt is None:
149-
print 'B missing: %s' % aElt
150+
print('B missing: %s' % aElt)
150151
else:
151-
print 'mismatch: A: %s' % aElt
152-
print ' B: %s' % bElt
152+
print('mismatch: A: %s' % aElt)
153+
print(' B: %s' % bElt)
153154

154155
differ = True
155156

156157
# Compare stderr.
157158
if infoA.stderr != infoB.stderr:
158-
print '-- STDERR DIFFERS -'
159-
print 'A STDERR: ',infoA.stderr
160-
print 'B STDERR: ',infoB.stderr
161-
print
159+
print('-- STDERR DIFFERS -')
160+
print('A STDERR: ',infoA.stderr)
161+
print('B STDERR: ',infoB.stderr)
162+
print()
162163

163164
diff = ZipperDiff(infoA.stderr.split('\n'),
164165
infoB.stderr.split('\n'))
165166
for i,(aElt,bElt) in enumerate(diff.getDiffs()):
166167
if aElt is None:
167-
print 'A missing: %s' % bElt
168+
print('A missing: %s' % bElt)
168169
elif bElt is None:
169-
print 'B missing: %s' % aElt
170+
print('B missing: %s' % aElt)
170171
else:
171-
print 'mismatch: A: %s' % aElt
172-
print ' B: %s' % bElt
172+
print('mismatch: A: %s' % aElt)
173+
print(' B: %s' % bElt)
173174

174175
differ = True
175176

176177
# Compare commands.
177-
for i,(a,b) in enumerate(map(None, infoA.commands, infoB.commands)):
178+
for i,(a,b) in enumerate(zip_longest(infoA.commands, infoB.commands, fillvalue=None)):
178179
if a is None:
179-
print 'A MISSING:',' '.join(b)
180+
print('A MISSING:',' '.join(b))
180181
differ = True
181182
continue
182183
elif b is None:
183-
print 'B MISSING:',' '.join(a)
184+
print('B MISSING:',' '.join(a))
184185
differ = True
185186
continue
186187

187188
diff = DriverZipperDiff(a,b)
188189
diffs = list(diff.getDiffs())
189190
if diffs:
190-
print '-- COMMAND %d DIFFERS -' % i
191-
print 'A COMMAND:',' '.join(a)
192-
print 'B COMMAND:',' '.join(b)
193-
print
191+
print('-- COMMAND %d DIFFERS -' % i)
192+
print('A COMMAND:',' '.join(a))
193+
print('B COMMAND:',' '.join(b))
194+
print()
194195
for i,(aElt,bElt) in enumerate(diffs):
195196
if aElt is None:
196-
print 'A missing: %s' % bElt
197+
print('A missing: %s' % bElt)
197198
elif bElt is None:
198-
print 'B missing: %s' % aElt
199+
print('B missing: %s' % aElt)
199200
else:
200-
print 'mismatch: A: %s' % aElt
201-
print ' B: %s' % bElt
201+
print('mismatch: A: %s' % aElt)
202+
print(' B: %s' % bElt)
202203
differ = True
203204

204205
# Compare result codes.
205206
if infoA.exitCode != infoB.exitCode:
206-
print '-- EXIT CODES DIFFER -'
207-
print 'A: ',infoA.exitCode
208-
print 'B: ',infoB.exitCode
207+
print('-- EXIT CODES DIFFER -')
208+
print('A: ',infoA.exitCode)
209+
print('B: ',infoB.exitCode)
209210
differ = True
210211

211212
if differ:

0 commit comments

Comments
 (0)