-
Couldn't load subscription status.
- Fork 15k
[clang][utils] Make CmpDriver Python3 compatible #163740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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 debuging this script in future. (I doubt it has been used for a very long time)
|
@llvm/pr-subscribers-clang Author: David Spickett (DavidSpickett) ChangesThe majority of this is running 2to3 on it:
Then there was a use of "map(None, iterables..)" This no longer works in Python3, the equivalent fillvalue defaults to None but I made it explicit (I doubt it has been used for a very long time) Full diff: https://github.com/llvm/llvm-project/pull/163740.diff 1 Files Affected:
diff --git a/clang/utils/CmpDriver b/clang/utils/CmpDriver
index 12ce7a3250f66..0732baa76d01c 100755
--- a/clang/utils/CmpDriver
+++ b/clang/utils/CmpDriver
@@ -5,6 +5,7 @@ A simple utility that compares tool invocations and exit codes issued by
compiler drivers that support -### (e.g. gcc and clang).
"""
+from itertools import zip_longest
import subprocess
def splitArgs(s):
@@ -22,7 +23,7 @@ def splitArgs(s):
elif inQuote:
if c == '\\':
current += c
- current += it.next()
+ current += next(it)
else:
current += c
elif not c.isspace():
@@ -135,77 +136,77 @@ def main():
# Compare stdout.
if infoA.stdout != infoB.stdout:
- print '-- STDOUT DIFFERS -'
- print 'A OUTPUT: ',infoA.stdout
- print 'B OUTPUT: ',infoB.stdout
- print
+ print('-- STDOUT DIFFERS -')
+ print('A OUTPUT: ',infoA.stdout)
+ print('B OUTPUT: ',infoB.stdout)
+ print()
diff = ZipperDiff(infoA.stdout.split('\n'),
infoB.stdout.split('\n'))
for i,(aElt,bElt) in enumerate(diff.getDiffs()):
if aElt is None:
- print 'A missing: %s' % bElt
+ print('A missing: %s' % bElt)
elif bElt is None:
- print 'B missing: %s' % aElt
+ print('B missing: %s' % aElt)
else:
- print 'mismatch: A: %s' % aElt
- print ' B: %s' % bElt
+ print('mismatch: A: %s' % aElt)
+ print(' B: %s' % bElt)
differ = True
# Compare stderr.
if infoA.stderr != infoB.stderr:
- print '-- STDERR DIFFERS -'
- print 'A STDERR: ',infoA.stderr
- print 'B STDERR: ',infoB.stderr
- print
+ print('-- STDERR DIFFERS -')
+ print('A STDERR: ',infoA.stderr)
+ print('B STDERR: ',infoB.stderr)
+ print()
diff = ZipperDiff(infoA.stderr.split('\n'),
infoB.stderr.split('\n'))
for i,(aElt,bElt) in enumerate(diff.getDiffs()):
if aElt is None:
- print 'A missing: %s' % bElt
+ print('A missing: %s' % bElt)
elif bElt is None:
- print 'B missing: %s' % aElt
+ print('B missing: %s' % aElt)
else:
- print 'mismatch: A: %s' % aElt
- print ' B: %s' % bElt
+ print('mismatch: A: %s' % aElt)
+ print(' B: %s' % bElt)
differ = True
# Compare commands.
- for i,(a,b) in enumerate(map(None, infoA.commands, infoB.commands)):
+ for i,(a,b) in enumerate(zip_longest(infoA.commands, infoB.commands, fillvalue=None)):
if a is None:
- print 'A MISSING:',' '.join(b)
+ print('A MISSING:',' '.join(b))
differ = True
continue
elif b is None:
- print 'B MISSING:',' '.join(a)
+ print('B MISSING:',' '.join(a))
differ = True
continue
diff = DriverZipperDiff(a,b)
diffs = list(diff.getDiffs())
if diffs:
- print '-- COMMAND %d DIFFERS -' % i
- print 'A COMMAND:',' '.join(a)
- print 'B COMMAND:',' '.join(b)
- print
+ print('-- COMMAND %d DIFFERS -' % i)
+ print('A COMMAND:',' '.join(a))
+ print('B COMMAND:',' '.join(b))
+ print()
for i,(aElt,bElt) in enumerate(diffs):
if aElt is None:
- print 'A missing: %s' % bElt
+ print('A missing: %s' % bElt)
elif bElt is None:
- print 'B missing: %s' % aElt
+ print('B missing: %s' % aElt)
else:
- print 'mismatch: A: %s' % aElt
- print ' B: %s' % bElt
+ print('mismatch: A: %s' % aElt)
+ print(' B: %s' % bElt)
differ = True
# Compare result codes.
if infoA.exitCode != infoB.exitCode:
- print '-- EXIT CODES DIFFER -'
- print 'A: ',infoA.exitCode
- print 'B: ',infoB.exitCode
+ print('-- EXIT CODES DIFFER -')
+ print('A: ',infoA.exitCode)
+ print('B: ',infoB.exitCode)
differ = True
if differ:
|
|
There's an argument to leave these old scripts exactly as they are, but in this case the changes are straightforward enough that I'd like to do them anyway. This will make it easier to use Python compatibility checking tools on llvm-project, and save someone some work if the script is rediscovered. |
The majority of this is running 2to3 on it:
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)