[PATCH] D42674: Make utils/UpdateTestChecks/common.py Python 2/3 compatible and fix print statements.

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 2 08:43:10 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL324104: Make utils/UpdateTestChecks/common.py Python 2/3 compatible and fix print… (authored by MaskRay, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D42674

Files:
  llvm/trunk/utils/UpdateTestChecks/common.py


Index: llvm/trunk/utils/UpdateTestChecks/common.py
===================================================================
--- llvm/trunk/utils/UpdateTestChecks/common.py
+++ llvm/trunk/utils/UpdateTestChecks/common.py
@@ -1,5 +1,7 @@
+from __future__ import print_function
 import re
 import subprocess
+import sys
 
 RUN_LINE_RE = re.compile('^\s*;\s*RUN:\s*(.*)$')
 CHECK_PREFIX_RE = re.compile('--?check-prefix(?:es)?=(\S+)')
@@ -35,9 +37,10 @@
   with open(ir) as ir_file:
     stdout = subprocess.check_output(exe + ' ' + cmd_args,
                                      shell=True, stdin=ir_file)
+    if sys.version_info[0] > 2:
+      stdout = stdout.decode()
   # Fix line endings to unix CR style.
-  stdout = stdout.replace('\r\n', '\n')
-  return stdout
+  return stdout.replace('\r\n', '\n')
 
 # Build up a dictionary of all the function bodies.
 def build_function_body_dictionary(function_re, scrubber, scrubber_args, raw_tool_output, prefixes, func_dict, verbose):
@@ -50,14 +53,14 @@
       # We only use the last line of the function body for stress tests.
       scrubbed_body = '\n'.join(scrubbed_body.splitlines()[-1:])
     if verbose:
-      print >>sys.stderr, 'Processing function: ' + func
+      print('Processing function: ' + func, file=sys.stderr)
       for l in scrubbed_body.splitlines():
-        print >>sys.stderr, '  ' + l
+        print('  ' + l, file=sys.stderr)
     for prefix in prefixes:
       if func in func_dict[prefix] and func_dict[prefix][func] != scrubbed_body:
         if prefix == prefixes[-1]:
-          print >>sys.stderr, ('WARNING: Found conflicting asm under the '
-                               'same prefix: %r!' % (prefix,))
+          print('WARNING: Found conflicting asm under the '
+                               'same prefix: %r!' % (prefix,), file=sys.stderr)
         else:
           func_dict[prefix][func] = None
           continue


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42674.132606.patch
Type: text/x-patch
Size: 1905 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180202/71ae6030/attachment.bin>


More information about the llvm-commits mailing list