Fix build when /usr/local/bin/python is python 3
Eitan Adler
lists at eitanadler.com
Wed Jul 17 10:15:51 PDT 2013
Hi,
What follows is a patch which attempts to be compatible with both
python 2 and python 3. This also fixes a few wrong shebang lines.
diff --git a/utils/DSAclean.py b/utils/DSAclean.py
index 6c43357..8a6f82a 100755
--- a/utils/DSAclean.py
+++ b/utils/DSAclean.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python
+#! /usr/bin/env python
#changelog:
#10/13/2005b: replaced the # in tmp(.#*)* with alphanumeric and _,
this will then remove
@@ -11,7 +11,7 @@
import re
import sys
if( len(sys.argv) < 3 ):
- print 'usage is: ./DSAclean <dot_file_to_be_cleaned> <out_put_file>'
+ print ('usage is: ./DSAclean <dot_file_to_be_cleaned> <out_put_file>')
sys.exit(1)
#get a file object
input = open(sys.argv[1], 'r')
diff --git a/utils/DSAextract.py b/utils/DSAextract.py
index 89dece1..8174e67 100644
--- a/utils/DSAextract.py
+++ b/utils/DSAextract.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python
+#! /usr/bin/env python
#this is a script to extract given named nodes from a dot file, with
#the associated edges. An edge is kept iff for edge x -> y
@@ -31,8 +31,8 @@ import sys
if len(sys.argv) < 3:
- print 'usage is ./DSAextract <dot_file_to_modify> \
- <output_file> [list of nodes to extract]'
+ print ('usage is ./DSAextract <dot_file_to_modify> \
+ <output_file> [list of nodes to extract]')
#open the input file
input = open(sys.argv[1], 'r')
@@ -73,7 +73,7 @@ while buffer != '':
#test code
#print '\n'
-print node_name_set
+print(node_name_set)
#print node_set
diff --git a/utils/lint/common_lint.py b/utils/lint/common_lint.py
index e982680..23576c1 100644
--- a/utils/lint/common_lint.py
+++ b/utils/lint/common_lint.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# Common lint functions applicable to multiple types of files.
@@ -89,7 +89,7 @@ def RunLintOverAllFiles(linter, filenames):
for filename in filenames:
file = open(filename, 'r')
if not file:
- print 'Cound not open %s' % filename
+ print('Cound not open %s' % filename)
continue
lines = file.readlines()
lint.extend(linter.RunOnFile(filename, lines))
diff --git a/utils/lint/cpp_lint.py b/utils/lint/cpp_lint.py
index 07fad58..34d6478 100755
--- a/utils/lint/cpp_lint.py
+++ b/utils/lint/cpp_lint.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# Checks C++ files to make sure they conform to LLVM standards, as specified in
# http://llvm.org/docs/CodingStandards.html .
@@ -86,7 +86,7 @@ class CppLint(common_lint.BaseLint):
def CppLintMain(filenames):
all_lint = common_lint.RunLintOverAllFiles(CppLint(), filenames)
for lint in all_lint:
- print '%s:%d:%s' % (lint[0], lint[1], lint[2])
+ print('%s:%d:%s' % (lint[0], lint[1], lint[2]))
return 0
diff --git a/utils/lint/generic_lint.py b/utils/lint/generic_lint.py
index c8f4835..06218d7 100755
--- a/utils/lint/generic_lint.py
+++ b/utils/lint/generic_lint.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# Checks files to make sure they conform to LLVM standards which can be applied
# to any programming language: at present, line length and trailing whitespace.
diff --git a/utils/release/findRegressions-nightly.py
b/utils/release/findRegressions-nightly.py
index ddf8983..c0b4863 100755
--- a/utils/release/findRegressions-nightly.py
+++ b/utils/release/findRegressions-nightly.py
@@ -22,12 +22,12 @@ def parse(file):
fname = ''
for t in r:
if DEBUG:
- print t
+ print (t)
if t[0] == 'PASS' or t[0] == 'FAIL' :
tmp = t[2].split(testDirName)
if DEBUG:
- print tmp
+ print (tmp)
if len(tmp) == 2:
fname = tmp[1].strip('\r\n')
@@ -41,26 +41,26 @@ def parse(file):
test[fname][k] = 'NA'
test[fname][t[1]] = t[0]
if DEBUG:
- print test[fname][t[1]]
+ print (test[fname][t[1]])
else :
try:
n = t[0].split('RESULT-')[1]
if DEBUG:
- print n;
+ print (n);
if n == 'llc' or n == 'jit-comptime' or n == 'compile':
test[fname][tp + n] = float(t[2].split(' ')[2])
if DEBUG:
- print test[fname][tp + n]
+ print (test[fname][tp + n])
elif n.endswith('-time') :
test[fname][exp + n] = float(t[2].strip('\r\n'))
if DEBUG:
- print test[fname][exp + n]
+ print (test[fname][exp + n])
else :
- print "ERROR!"
+ print ("ERROR!")
sys.exit(1)
except:
@@ -73,7 +73,7 @@ def diffResults(d_old, d_new):
for t in sorted(d_old.keys()) :
if DEBUG:
- print t
+ print (t)
if d_new.has_key(t) :
@@ -83,42 +83,42 @@ def diffResults(d_old, d_new):
if d_new[t].has_key(x):
if d_old[t][x] == 'PASS':
if d_new[t][x] != 'PASS':
- print t + " *** REGRESSION (" + x + ")\n"
+ print (t + " *** REGRESSION (" + x + ")\n")
else:
if d_new[t][x] == 'PASS':
- print t + " * NEW PASS (" + x + ")\n"
+ print (t + " * NEW PASS (" + x + ")\n")
else :
- print t + "*** REGRESSION (" + x + ")\n"
+ print (t + "*** REGRESSION (" + x + ")\n")
# For execution time, if there is no result, its a fail.
for x in exectime:
if d_old[t].has_key(tp + x):
if not d_new[t].has_key(tp + x):
- print t + " *** REGRESSION (" + tp + x + ")\n"
+ print (t + " *** REGRESSION (" + tp + x + ")\n")
else :
if d_new[t].has_key(tp + x):
- print t + " * NEW PASS (" + tp + x + ")\n"
+ print (t + " * NEW PASS (" + tp + x + ")\n")
for x in comptime:
if d_old[t].has_key(exp + x):
if not d_new[t].has_key(exp + x):
- print t + " *** REGRESSION (" + exp + x + ")\n"
+ print (t + " *** REGRESSION (" + exp + x + ")\n")
else :
if d_new[t].has_key(exp + x):
- print t + " * NEW PASS (" + exp + x + ")\n"
+ print (t + " * NEW PASS (" + exp + x + ")\n")
else :
- print t + ": Removed from test-suite.\n"
+ print (t + ": Removed from test-suite.\n")
#Main
if len(sys.argv) < 3 :
- print 'Usage:', sys.argv[0], \
- '<old log> <new log>'
+ print ('Usage:', sys.argv[0], \
+ '<old log> <new log>')
sys.exit(-1)
d_old = parse(sys.argv[1])
diff --git a/utils/release/findRegressions-simple.py
b/utils/release/findRegressions-simple.py
index 8d3b4cf..01c5589 100755
--- a/utils/release/findRegressions-simple.py
+++ b/utils/release/findRegressions-simple.py
@@ -18,20 +18,20 @@ def parse(file):
fname = ''
for t in r:
if DEBUG:
- print t
+ print(t)
if t[0] == 'PASS' or t[0] == 'FAIL' :
tmp = t[2].split('llvm-test/')
if DEBUG:
- print tmp
+ print(tmp)
if len(tmp) == 2:
fname = tmp[1].strip('\r\n')
else:
fname = tmp[0].strip('\r\n')
- if not test.has_key(fname):
+ if fname not in test:
test[fname] = {}
test[fname][t[1] + ' state'] = t[0]
@@ -41,7 +41,7 @@ def parse(file):
n = t[0].split('RESULT-')[1]
if DEBUG:
- print "n == ", n;
+ print ("n == ", n);
if n == 'compile-success':
test[fname]['compile time'] =
float(t[2].split('program')[1].strip('\r\n'))
@@ -49,7 +49,7 @@ def parse(file):
elif n == 'exec-success':
test[fname]['exec time'] =
float(t[2].split('program')[1].strip('\r\n'))
if DEBUG:
- print test[fname][string.replace(n, '-success', '')]
+ print (test[fname][string.replace(n, '-success', '')])
else :
# print "ERROR!"
@@ -71,16 +71,16 @@ def diffResults(d_old, d_new):
passes[x] = ''
for t in sorted(d_old.keys()) :
- if d_new.has_key(t):
+ if t in d_new:
# Check if the test passed or failed.
for x in ['compile state', 'compile time', 'exec state', 'exec time']:
- if not d_old[t].has_key(x) and not d_new[t].has_key(x):
+ if x not in d_old[t] and x not in d_new[t]:
continue
- if d_old[t].has_key(x):
- if d_new[t].has_key(x):
+ if x in d_old[t]:
+ if x in d_new[t]:
if d_old[t][x] == 'PASS':
if d_new[t][x] != 'PASS':
@@ -96,11 +96,11 @@ def diffResults(d_old, d_new):
continue
# For execution time, if there is no result it's a fail.
- if not d_old[t].has_key(x) and not d_new[t].has_key(x):
+ if x not in d_old[t] and x not in d_new[t]:
continue
- elif not d_new[t].has_key(x):
+ elif x not in d_new[t]:
regressions[x] += t + "\n"
- elif not d_old[t].has_key(x):
+ elif x not in d_old[t]:
passes[x] += t + "\n"
if math.isnan(d_old[t][x]) and math.isnan(d_new[t][x]):
@@ -120,36 +120,36 @@ def diffResults(d_old, d_new):
removed += t + "\n"
if len(regressions['compile state']) != 0:
- print 'REGRESSION: Compilation Failed'
- print regressions['compile state']
+ print ('REGRESSION: Compilation Failed')
+ print (regressions['compile state'])
if len(regressions['exec state']) != 0:
- print 'REGRESSION: Execution Failed'
- print regressions['exec state']
+ print ('REGRESSION: Execution Failed')
+ print (regressions['exec state'])
if len(regressions['compile time']) != 0:
- print 'REGRESSION: Compilation Time'
- print regressions['compile time']
+ print ('REGRESSION: Compilation Time')
+ print (regressions['compile time'])
if len(regressions['exec time']) != 0:
- print 'REGRESSION: Execution Time'
- print regressions['exec time']
+ print ('REGRESSION: Execution Time')
+ print (regressions['exec time'])
if len(passes['compile state']) != 0:
- print 'NEW PASSES: Compilation'
- print passes['compile state']
+ print ('NEW PASSES: Compilation')
+ print (passes['compile state'])
if len(passes['exec state']) != 0:
- print 'NEW PASSES: Execution'
- print passes['exec state']
+ print ('NEW PASSES: Execution')
+ print (passes['exec state'])
if len(removed) != 0:
- print 'REMOVED TESTS'
- print removed
+ print ('REMOVED TESTS')
+ print (removed)
# Main
if len(sys.argv) < 3 :
- print 'Usage:', sys.argv[0], '<old log> <new log>'
+ print ('Usage:', sys.argv[0], '<old log> <new log>')
sys.exit(-1)
d_old = parse(sys.argv[1])
--
Eitan Adler
--
Eitan Adler
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-python-llvm.diff
Type: application/octet-stream
Size: 10699 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130717/af185c11/attachment.obj>
More information about the llvm-commits
mailing list